Announcement

Collapse
No announcement yet.

Backtesting entry price == indicator value?

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

  • Backtesting entry price == indicator value?

    I would like to create a backtest that has me entering when the price == MA value (or any other indicator). I don't know how to acquire past bar values to do this. One thought would be to test & see if the MA value was between the price high & low, but the only means I know to do this involves using getValue(). How to then align the values, especially if in an array. Use bar index? The numbers for a 2 minute chart going back 30 days alone would be huge. Just as much so, if data is loading for a certain amount of historical data, how to get the starting date? Most importantly, this is bumping into, & probably beyond, my limited programming skills.

    Any help is greatly appreciated.
    Thanks,
    Greg

  • #2
    Greg
    You can find a very basic example of a strategy that uses a moving average as the entry price in this thread.
    The script was written using only the Formula Wizard
    Alex

    Comment


    • #3
      Hi Jason,

      Thanks for the response. It gets me there in format, but how do I use none builtin studies? As an example, T3Ave.efs?

      Thanks,
      Greg

      Comment


      • #4
        Oops! Mea culpa! I meant Alexis! I know how to read. Really, I do! ;-)

        Comment


        • #5
          Hi Alexis,

          From the thread you qouted:
          http://forum.esignalcentral.com/show...6161#post26161

          In strategy-limit.efs:

          1. Why is there a return statement? What functional purpose does it serve?

          2. What _functional_ purpose does vLastAlert serve? Logically, I could see how it might be used, but in this code, it appears to be unused. Am I incorrect?

          Thanks, as always!
          Greg

          Comment


          • #6
            Greg
            With non builtin studies you would use something similar to the example shown below (which is based on the T3 study you referenced).

            PHP Code:
            //other variables here
            var T3Average null;
            var 
            T3Average_1 null;//this is the value of the T3 at the prior bar

            function main()

                if(
            getBarState()==BARSTATE_NEWBAR){
                    
            //other code here
                    
            T3Average_1 T3Average;
                }

                
            //other code here

                
            T3Average c1 e6 c2 etc;

                if(!
            Strategy.isLong()){
                    if(
            close(-1)<T3Average_1 && close(0)>T3Average){
                        if(
            low(0)<T3Average){//this is to make sure prices traded across the T3 on the entry bar
                            
            Strategy.doLong("Long"Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, T3Average);
                        }else{
                            
            Strategy.doLong("Long"Strategy.CLOSEStrategy.THISBARStrategy.DEFAULT);
                        }
                    }
                }
                
                return 
            T3Average;

            As you can see if you exclude the code required to calculate the indicator the syntax and construct for the strategy are not much different than the ones shown in the example I indicated in my prior reply even though this script is not using a builtin study. Here I also added a further condition to ensure that prices actually traded at the T3 average to avoid unrealistic fills. The strategy in fact will go long at the T3 only if the low of the bar that generates the trade signal went below it else it will enter at the close of the bar.
            Note that the above is just an example intended to illustrate the basic concept.
            Alex

            Comment


            • #7
              Greg
              1. To return the value of the moving average to the chart
              2. vLastAlert is inserted automatically by the Formula Wizard and would be used to trigger alerts/events only the first time a condition returns true.
              At this point I would strongly suggest that you take some time to go through the Help Guides in the EFS knowledgeBase and in particular the Formula Wizard Guide, the Guide to Developing EFS Indicators and the Guide to Developing EFS Strategies.
              Alex

              Comment


              • #8
                Hi Alex,
                Actually, I was going into a compiler question which is inappropriate here. Thank you for getting me past my difficulties once again.
                - Greg

                Comment

                Working...
                X