EURGBP Trend System
Forums › ProRealTime English forum › ProOrder support › EURGBP Trend System
- This topic has 5 replies, 2 voices, and was last updated 6 years ago by grimweasel47.
-
-
11/08/2017 at 11:28 AM #51920
Hello,
I have the code below for a H1 EURGBP system that I’m backtesting but as you can see from the code, I only want PRT to trade within certain times. On backtesting the system keeps ignoring these times with multiple trades at 00;00,00 (midnight) which is not what I expect the code to allow. These errant trades seem to be after the system has not traded the day before (such as after the weekend). Could anyone ascertain why it is not abiding by the if time= commands?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130defparam cumulateorders=false// --- settingsbalance = 10000 //balance of the strategy when activated the first timeminlot = 1 //minimum lot size for the current instrument (example: 1 for DAX)riskpercent = 2 //risk percent per tradeactivationtime = 080000 //Close time of the candle to activate the strategyLimitHour = 140000 //Time to close off strategy//choose days of week to tradeif dayofweek=1 then //Mondaydaytrading=1endifif dayofweek=2 then // Tuesdaydaytrading=1endifif dayofweek=3 then // Wednesdaydaytrading=1endifif dayofweek=4 then //Thursdaydaytrading=1endifif dayofweek=5 then // Fridaydaytrading=1endifif dayofweek=6 or dayofweek=7 then //Sat and Sundaytrading=0endif// ---// --- indicatorsema = exponentialaverage[150](close)ema2 = exponentialaverage[50](close)//set trend using highs and lowsTrend1= highest[1](high)Trend2= highest[20](high)Trend3 = trend2-trend1///Trend4= lowest[1](low)Trend5= lowest[20](low)Trend6 = trend4-trend5///EMAabove = ema2>emaEMAbelow = ema2<emaatr = averagetruerange[24]hh = highest[12](high)ll = lowest[12](low)Long = emaabove and trend3 >0Short = emabelow and trend6 >-1// ---if intradaybarindex=0 thenalreadytraded = 0case = 0levelhi = 0levello = 0endifif onmarket or (onmarket[1] and not onmarket) or (currentprofit<>strategyprofit) thenalreadytraded = 1endifif time=activationtime and time<limithour then// case 1 : If price candle touches MA (even wicks) then look at high or low of signal candleif trend3<0 or trend6<-1 thencase = 1levelhi = CALL"#floor and ceil"[high,10.0,1]levello = CALL"#floor and ceil"[low,10.0,-1]endif//case 2 : If price is above the MA then only trade long BUT only above the highest high of the past 24 hrsif long and case = 0 thencase = 2levelhi = hh[1]endif//case 3 : If price is below the MA then only trade short BUT only below the lowest low of the past 24 hrsif short and case = 0 thencase = 3levello = ll[1]endifendifif alreadytraded = 0 then//money managementif case=1 thenStopLoss = 10elseStopLoss = 10endifRisk = riskpercent/100//calculate contractsequity = balance + StrategyProfitmaxrisk = round(equity*Risk)size = max(minlot,abs(round((maxrisk/StopLoss)/PointValue)*pipsize))//in all cases put pending orders on marketwhile case <> 0 and daytrading=1 and time <=LimitHour doif levelhi>0 thenbuy size contract at levelhi stopendifif levello>0 thensellshort size contract at levello stopendifwendendif//set target and profitif onmarket thenif case = 1 thenset target profit 1*ATRset stop ploss StopLossendifif case = 2 or case = 3 thenset target profit 1*ATRset stop ploss StopLossendifendifcurrentprofit = strategyprofit//debugging//graph case as "case"//graph time=activationtime coloured(100,120,133) as "activation time!"graph time//graph ema//graph levelhi coloured(0,200,0) as "level high"//graph levello coloured(200,0,0) as "level low"//graph size as "mm"11/08/2017 at 6:37 PM #52000Hi, had a quick look at this, I don’t think your code is doing what you think it is doing:
if time=activationtime and time<limithour then
This will only perform the tests on the following lines at 080000, I think you meant it to be between the 2 times so time >= activationtime and time<limithour?
while case <> 0 and daytrading=1 and time <=LimitHour do
if levelhi>0 then
buy size contract at levelhi stopThis will execute orders at any time before LimitHour including 000000 if it meets the entry criteria
11/09/2017 at 9:26 AM #52047Thanks autostrategist.
I see what you mean for the first command, so the second element is correct further down under //in all cases put pending orders on market
1while case <> 0 and daytrading=1 and time <=LimitHour doSo this part of the code should ensure that trades are not activated beyond/past the limitHour set earlier in code?
11/09/2017 at 9:29 AM #52048Autostrategist
I just tried the above and sadly the system is still taking trades at 00:00.00 (midnight) randomly. Could this be linked to this part of the code?
123456789101112// ---if intradaybarindex=0 thenalreadytraded = 0case = 0levelhi = 0levello = 0endifif onmarket or (onmarket[1] and not onmarket) or (currentprofit<>strategyprofit) thenalreadytraded = 1endifIt seems to take the random midnight trades when the system has not traded the day before? (such as criteria not met, or weekends)?
11/09/2017 at 10:30 AM #52066You need to change this line:
while case <> 0 and daytrading=1 and time <=LimitHour doto be:while case <> 0 and daytrading=1 and (time >= activationtime and time <=LimitHour) do
1 user thanked author for this post.
11/10/2017 at 8:53 AM #52189Ahh, brilliant. Thanks AS! That should solve it.
Best wishes
-
AuthorPosts
Find exclusive trading pro-tools on