Announcement

Collapse
No announcement yet.

Backtest Help

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

  • Backtest Help

    I want to backtest a simple system for a 5min chart.

    Its basically a donchian system that using a 40 bar high to enter long and 40 bar low to exit long. Since the system always has a position on.. it also uses a 40 bar low to short and 40 bar high to exit.

    Can someone please code this up so I can run some backtests?


    Thanks.

  • #2
    mikexny
    The attached efs should do what you asked.
    The formula plots the Donchian channel with the parameters you specified and triggers a Buy/Sell when the upper/lower channels are breached and paints the bar accordingly in blue/red.
    Alex
    Attached Files

    Comment


    • #3
      Thanks it works great.

      Can u also create a backtest that has the same rules except the exit is the midpoint of the channel. The entry still remains the same.. just the exit is changed. This system is not an always in the market type system.

      thanks mike

      Comment


      • #4
        mike
        The attached revision does what you asked. It will Sell or Cover (if Long or Short respectively) when the basis line is breached and will paint that bar in yellow.
        Alex

        Attached Files

        Comment


        • #5
          Great.. ... just one more request..

          I need to test a 40 bar entry using a 20 bar exit.

          So u enter long on 40 bar high and exit the long on 20 bar low.

          Enter short on 40 bar low and exit short on 20 bar high.

          This system is also not always in the market.


          thanks

          Comment


          • #6
            mike
            The attached revision of the efs does what you asked.
            At this point I believe you should have enough examples on how to code this or similar scripts should you wish to further modify the strategy.
            Alex
            Attached Files

            Comment


            • #7
              Great.. how do u set it up so that when u backtest u exit all trades at the close.. so u have no overnight risk. Basically u want to be flat into the close. Then the system continues the following day.


              --MIKE

              Comment


              • #8
                You have to set up a condition where you test for time. Then based on this evaluation, exit the position when your time condition is met. See the attached link for an efs which can be reviewed/used for this purpose
                time time

                Comment


                • #9
                  Problem is that i dont know how to program. And efs is kinda difficult for people like me.

                  I like to use the wizard for basic things.. but when it comes to doing things that involve EFS coding.. i am completely lost.

                  If there was a way to do all this in the wizard it would be great for me.. for now I am still totally lost.

                  Comment


                  • #10
                    Try and run the efs I had sent you the link for and start try some basic if statements within that program.

                    PHP Code:
                    if (time 1600 ){go flat();} 
                    Based on my understanding, you should be able to do this with the wizard too.

                    Comment


                    • #11
                      Where do i put that line in the efs.. can i just copy it into the efs and make it work?

                      I dont know how to integrate this into my efs with the 40/20 donchian breakout because the efs was not written via the wizard.

                      I am totally lost with writing my own efs from scratch.

                      --MIKE

                      Comment


                      • #12
                        mike

                        If there was a way to do all this in the wizard it would be great for me..

                        Actually the whole Donchian strategy - as laid out by you - can be created using the Fomula Wizard alone (see attached efs)
                        At this point you can add all the time conditions you want still using only the Formula Wizard.
                        In the image below you can see that in Set1 I inserted as an example a time restriction on when the strategy can go Long by using the conditions
                        (getHour()*100)+getMinute()>=930
                        (getHour()*100)+getMinute()<1600
                        Using this as a guideline apply all the other time conditions you want to the other Sets. You may need to add some Sets to define the close of a trade at the end of day if the strategy is long or short.
                        Alex

                        Attached Files

                        Comment


                        • #13
                          Based off of the D. Strat 2, how would one close a long/short trade based off a bar close below/above a 10 EMA in lieu of violating the middle of the channel? and then going long/short again if it starts making new highs/lows?

                          Comment


                          • #14
                            JT
                            The attached efs should do what you asked.
                            All the parameters for the MA and the Donchian can be modified through Edit Studies
                            Alex

                            Attached Files

                            Comment


                            • #15
                              JT
                              One additional note regarding the DonchianMA-strategy from my prior post. That will work only in backtest. For real time one would need to add either setComputeOnClose() or a check for a new bar using getBarState(). In the latter case the logic of the conditions would also need a slight adjustment
                              Alex

                              Comment

                              Working...
                              X