Overcoming the lack of tick by tick data with simulation.
Forums › ProRealTime English forum › ProOrder support › Overcoming the lack of tick by tick data with simulation.
- This topic has 4 replies, 2 voices, and was last updated 5 years ago by pippo999.
Tagged: resistance, simulated strategy, simulation, support, tick by tick
-
-
12/08/2018 at 3:01 PM #86566
I wrote a long only daily strategy that bought at calculated support prices and sold at resistance prices and that required the use of tick by tick data as it used LIMIT and STOP pending orders. It looked great but using tick by tick limited the data sample to starting from just August 2010. The strategy never bought and sold on the same day so I decided to write an indicator that simulated the strategy so that I could test further back – this way I could have a much bigger data sample to test on. Obviously this will only work if your strategy has no zero bar trades – that is ones that open and close in the same bar.
As well as graphing my simulated equity curve I graphed my ‘onmark’ variable multiplied by the equity to show when the simulated strategy was on market.
Here is the simulated bit of code – I have removed the actual main parts of the strategy:
123456789101112131415161718192021222324252627282930Spread = 3.8//simulated entryif not onmark and close[1] > supportprice[1] and low < supportprice and open > supportprice and filter thenentryprice = supportpriceonmark = 1stoplossprice = (my calculated stoploss price)endif//simulated win exitif onmark and high > resistanceprice thenexitprice = resistancepriceonmark = 0equity = (equity + (exitprice - entryprice)) - spreadendif//simulated hit stoplossif onmark and low < stoplossprice thenexitprice = stoplosspriceonmark = 0equity = (equity + (exitprice - entryprice)) - spreadendifif onmark thenfloatingequity = (equity + (close - entryprice))elsefloatingequity = equityendifreturn floatingequity coloured(0,0,255) style(line,2) as "Equity", (onmark * floatingequity) coloured(0,128,0,150) style(histogram,2) as "OnMarket"Obviously my strategies entry and exit points are very simple to simulate and so if your strategy is very complicated then simulating it might not be quite so easy – but I post this here just in case someone else might find the concept useful for their own back testing of any strategy with STOP and LIMIT pending orders and no zero bar entry and exits.
Technically this is an indicator but as it is really a strategy equity curve I post it here rather than in the indicator section.
1 user thanked author for this post.
12/08/2018 at 3:23 PM #86570I made some slight improvements by adding a buy and hold line and also calculating the win rate and average gain per trade. In fact this is better than the PRT results as you can see historically how the win rate and average return has been rather than just the final totals.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849Spread = 3.8//simulated entryif not onmark and close[1] > supportprice[1] and low < supportprice and open > supportprice and filter thenentryprice = supportpriceonmark = 1stoplossprice = (my calculated stop loss price)endif//simulated win exitif onmark and high > resistanceprice thenexitprice = resistancepriceonmark = 0equity = (equity + (exitprice - entryprice)) - spreadendif//simulated hit stoplossif onmark and low < stoplossprice thenexitprice = stoplosspriceonmark = 0equity = (equity + (exitprice - entryprice)) - spreadif equity > equity[1] thenwin = win + 1count = count + 1endifif equity < equity[1] thencount = count + 1endifendifif onmark thenfloatingequity = (equity + (close - entryprice))elsefloatingequity = equityif equity > equity[1] thenwin = win + 1count = count + 1endifif equity < equity[1] thencount = count + 1endifendifbuyandhold = buyandhold + (close - open)winrate = (win/count) * 100avegain = (equity /count)return floatingequity coloured(0,0,255) style(line,2) as "Equity", buyandhold as "Buy and Hold", winrate as "Win Rate", avegain as "Average Gain", (onmark * floatingequity) coloured(0,128,0,150) style(histogram,2) as "OnMarket"12/08/2018 at 3:40 PM #86575I’ve just realised that if your strategy has no zero bar issues of trades opening and closing on the same bar then by just turning off the tick by tick you will get an accurate equity graph – so my above code is a waste of time! I suppose at least with it you can see a running win rate and average gain per trade.
I won’t delete the posts so that someone might read it and use my experience/stupidity and not waste their own time.
12/08/2018 at 3:48 PM #86576I modified it to just show the win rate and average gain. Maybe it is not all wasted time.
Interesting to note the win rate dropping but the average gain increasing.
123456789101112131415161718192021222324252627282930313233343536373839404142Spread = 3.8//simulated entryif not onmark and close[1] > supportprice[1] and low < supportprice and open > supportprice and filter thenentryprice = supportpriceonmark = 1stoplossprice = (my calculated stop loss price)endif//simulated win exitif onmark and high > resistanceprice thenexitprice = resistancepriceonmark = 0equity = (equity + (exitprice - entryprice)) - spreadendif//simulated hit stoplossif onmark and low < stoplossprice thenexitprice = stoplosspriceonmark = 0equity = (equity + (exitprice - entryprice)) - spreadif equity > equity[1] thenwin = win + 1count = count + 1endifif equity < equity[1] thencount = count + 1endifendifif equity > equity[1] thenwin = win + 1count = count + 1endifif equity < equity[1] thencount = count + 1endifwinrate = (win/count) * 100avegain = (equity /count)return winrate as "Win Rate", avegain as "Average Gain"12/12/2018 at 11:32 AM #86940 -
AuthorPosts
Find exclusive trading pro-tools on