Back testing strategies
Forums › ProRealTime English forum › ProOrder support › Back testing strategies
- This topic has 103 replies, 5 voices, and was last updated 6 years ago by Vonasi.
-
-
06/26/2018 at 11:44 AM #7440906/26/2018 at 12:30 PM #74420
I got it to work.
On the time code you gave me this suggests to only enter trades between 8am and 1pm, is this correct? If so how do I get it to work to only place trades between 11pm and 7am which is the NYE market for me in Australia?
12345678starttime = 080000endtime = 130000timeok = opentime >= starttime and opentime <= endtimeif timeok and (your conditions) thenbuy 1 contract at marketendif06/26/2018 at 1:40 PM #7443206/26/2018 at 2:27 PM #74440It is saying syntax error
Sorry – my fault. I put MaxDays instead of MaxBars (I usually trade daily charts so use the MaxDays as a name but changed it to MaxBars for you but I missed one of them! I edited my post moments later but you were obviously too quick!
06/26/2018 at 2:31 PM #74441If so how do I get it to work to only place trades between 11pm and 7am which is the NYE market for me in Australia?
I just used those times as an example as you did not say what times you actually wanted. Time is in HHMMSS. So 130000 is 13Hr 0Min 0Sec and 144859 is 14Hr 48Min 59Sec. But you should be aware that the latter time does not actually exist in bar form on anything but second time frame charts.
06/26/2018 at 11:49 PM #744641234starttime = 230000endtime = 070000timeok = opentime >= starttime and opentime <= endtimeOk so when I use the above code I get no trades. I think it has to do with the start and end times?
1234starttime = 080000endtime = 130000timeok = opentime >= starttime and opentime <= endtimeBut when I use the above code I get lots of entries?
06/27/2018 at 7:05 AM #74472starttime = 230000 endtime = 070000 timeok = opentime >= starttime and opentime <= endtime Ok so when I use the above code I get no trades. I think it has to do with the start and end times?
For me in the UK on GMT, starttime = 230000 endtime = 070000 is out of hours for USA Market.
You are GMT + 10 in Australia soooo, 🙂 oh it’s too early and the coffee has not woke my brain up yet, but you can see where I am coming from???
Use the link below to work out you have the correct times in your code for USA Market open in relation to the time standard you have set on your Platform etc?
06/27/2018 at 7:16 AM #74475It is because you have your start time as a higher number than your endtime. If you want to straddle midnight then you have to change the AND to an OR
1234starttime = 230000endtime = 070000timeok = opentime >= starttime or opentime <= endtime1 user thanked author for this post.
06/27/2018 at 8:05 AM #7448406/29/2018 at 6:09 AM #746641234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = exponentialAverage[5](close)indicator2 = exponentialAverage[10](close)c1 = (indicator1 crosses over indicator2)indicator3 = exponentialAverage[200](close)c2 = (indicator2 > indicator3)IF c1 AND c2 THENBUY 250/myatr contracts at marketENDIF// Conditions to enter short positionsindicator4 = exponentialAverage[5](close)indicator5 = exponentialAverage[10](close)c3 = (indicator4 crosses under indicator5)indicator6 = exponentialAverage[100](close)c4 = (indicator5 < indicator6)IF c3 AND c4 THENSELLSHORT 250/myatr contracts at marketENDIF// Stops and targetsSET STOP $LOSS 250SET TARGET $PROFIT 250myATR = 4* (averagetruerange[24](medianprice))//trailing stop functiontrailingstart = 1*myatr //trailing will start @trailinstart points profittrailingstep = 1*myatr //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFThe above code wipes out my account balance and incurs losses of say $45k. So why if I reverse the buy and sell entries it does not produce the same level of profit being $45k?
06/29/2018 at 6:51 AM #74674I have not tested it but I would guess it is because bad entries coupled with bad exits do not change just because you are selling instead of buying.
I notice that you have the calculation for ‘myatr’ after you first use the variable myatr in the code so for the first bar myatr will equal zero until line 30 is first read. You should move it to higher to above line 12 at least.
06/29/2018 at 6:55 AM #74675I also notice that you are not testing with level stakes. Take out the money management until you know that you have a strategy that can win at a level stake of 1 and then see if you can improve it with the ATR based position sizing once you know your idea works. You are just muddying the water of your analysis of whether the basic idea works by including money management from the start.
It might also be useful for others to know what market and what time frame you are testing on.
06/29/2018 at 6:57 AM #7467606/29/2018 at 6:59 AM #7467706/29/2018 at 7:21 AM #74678I keep it very basic. If I can’t describe my strategy theory in one sentence then the idea is too complicated.
My best strategies might start off with just ten lines of code (maybe more if I am including the code from a home made indicator within the strategy). I analyse the output then optimize one thing at a time and re-analyse, then I start taking things out to see how important they are to the decision making process – the more conditions the more likely it is to be curve fitted. Every fixed variable is a potential curve fit – every single one must be analysed to compare with values either side of it. It is not until I am happy that my basic idea has been analysed to within an inch of its life that I will start thinking about money management or variable position sizing. Then I will forward test it in demo for a few months to decide if it really is something I want to risk actual money on.
The final strategy might be 100 lines of code but 90 of that will be money management options and 10 lines the actual strategy!
Others might do it differently but that is my method and philosophy on strategy coding.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on