Announcement

Collapse
No announcement yet.

code for managing in-trade signals

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • code for managing in-trade signals

    hi all,

    i'm new to using efs so bear with me on this one...

    i downloaded the into guide to developing efs stategies from this forum and it contained code on how to close out a current trade
    when your signal fires again, but how do u tell the program to just chill and do nothing when you are in a trade and your trigger fires again?

    my program just keeps buying and buying if the signal is on...

    thanks for any help

  • #2
    riskaverse305
    You enclose the section that triggers buys/sells in a condition that either checks that you are not already in a trade ie if(!Strategy.isInTrade()) or more specifically that you are not already long ie if)!Strategy.isLong()) or short ie if(!Strategy.isShort()) The exclamation mark that precedes the condition negates it. If you prefer you can also write it as if(Strategy.isLong()==false)
    Hope this helps
    Alex

    Comment


    • #3
      thnx, i was just confused because i was typing in strategy.islong
      instead of Strategy.isLong... didn't realize everything was case sensitive

      now another question: how do u specify the dates u want back-tested? i'm using 5 minute data and its only back-testing 3 days.

      thanks again

      Comment


      • #4
        riskaverse305
        You define how many days you want to back test through the Time Template. However in the Back Tester you cannot define a start/end period during which you want the test to run. You need to do that in the efs itself. You can find an example of how to do this in this post.
        Alex

        Comment


        • #5
          awesome, thanks for the quick response

          Comment


          • #6
            riskaverse305
            You are most welcome
            Alex

            Comment


            • #7
              alright, sorry guys, one more question:

              what code would u use to say, enter a trade after the signal is generated for a certain amount of time? say you only buy after the MACD goes positive for more than 5 minutes on a 1 minute interval.

              thanks again

              Comment


              • #8
                riskaverse305
                Enclosed below is a sample of a strategy that will go Long at the close of the 5th bar after a buy signal was triggered. Comments are in the script. Insert it into a plain efs and add the following two global variables
                var myBuyTrigger = false;
                var vCounter = 0;

                If you also want to see the average plotted add setPriceStudy(true) in preMain and for the return use sma(10,0)
                Alex

                PHP Code:
                var myLongCondition close(0)>sma(10,0);//condition for Long

                    
                if(!Strategy.isLong()){//if Strategy is NOT long
                        
                if(!myLongCondition){//il condition for Buy is NOT true
                            
                myBuyTrigger=false;//set the Buy Trigger to false
                        
                }
                        if(
                myLongCondition && !myBuyTrigger){//if Long condition is true AND Buy Trigger is false
                            
                vCounter getCurrentBarCount();//assign the current bar count to the variable vCounter
                            
                setBarBgColor(Color.yellow);//color the background in yellow
                            
                myBuyTrigger=true;//set the Buy Trigger to true
                        
                }
                        if(
                myBuyTrigger && (vCounter+4)==getCurrentBarCount()){//if Buy Trigger is true AND 5 bars have passed
                            
                Strategy.doLong("Long",Strategy.CLOSE,Strategy.THISBAR);//go Long
                            
                myBuyTrigger=false;//set the Buy Trigger to false
                        
                }
                    }
                    if(
                Strategy.isLong()){//if Strategy is Long
                        
                setBarBgColor(Color.lime);//color the background in lime
                        
                if(!myLongCondition){//if Long condition is NOT true 
                            
                Strategy.doSell("Sell",Strategy.CLOSE,Strategy.THISBAR);//close the trade
                        
                }
                    } 

                Comment

                Working...
                X