Prepare for automatic trading error
Forums › ProRealTime English forum › ProOrder support › Prepare for automatic trading error
- This topic has 15 replies, 5 voices, and was last updated 7 years ago by GraHal.
-
-
12/14/2016 at 7:59 PM #18528
Hi guys,
I’ve a problem with testing MGC Trend Chaser in demo. This is the code I am using:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657/// Definition of code parametersDEFPARAM CumulateOrders = false // Cumulating positions deactivatedCOI= CALL "MGC-Coppock"[14, 11, 10](close)MAC= MACDline[12,26,9](close)STO = Stochastic[14,5](close)ST = supertrend[a,b]// Conditions to enter long positionsc1 = (COI > COI[1])c2 = (MAC > MAC[1])c3 = (STO > 20)c4 = (STO < 40)c5 = (STO > STO[1])IF HIGHEST[5](c1)=1 AND HIGHEST[5](c2)=1 AND HIGHEST[5](c3)=1 AND HIGHEST[5](c4)=1 AND HIGHEST[5](c5)=1 AND NOT ONMARKET THENBUY 1 CONTRACT AT MARKETENDIF//SET STOP %Trailing 10// Conditions to exit long positions//c6 = (COI< COI[1])//c7 = (MAC< MAC[1])//c8 = (STO < 80)//c9 = (STO > 60)//c10 = (STO < STO[1])//IF HIGHEST[5](c6)=1 AND HIGHEST[5](c7)=1 AND HIGHEST[5](c8)=1 AND HIGHEST[5](c9)=1 AND HIGHEST[5](c10)=1 THENIF Close CROSSES UNDER ST THENSELL AT MARKETENDIF// Conditions to enter short positionsc11 = (COI< COI[1])c12 = (MAC< MAC[1])c13 = (STO < 80)c14 = (STO > 60)c15 = (STO < STO[1])IF HIGHEST[5](c11)=1 AND HIGHEST[5](c12)=1 AND HIGHEST[5](c13)=1 AND HIGHEST[5](c14)=1 AND HIGHEST[5](c15)=1 AND NOT ONMARKET THENSELLSHORT 1 CONTRACT AT MARKETENDIF//SET STOP %Trailing 10// Conditions to exit short positions//c16 = (COI> COI[1])//c17 = (MAC> MAC[1])//c18 = (STO > 20)//c19 = (STO < 40)//c20 = (STO > STO[1])//IF HIGHEST[5](c16)=1 AND HIGHEST[5](c17)=1 AND HIGHEST[5](c18)=1 AND HIGHEST[5](c19)=1 AND HIGHEST[5](c20)=1 THENIF close CROSSES OVER ST THENEXITSHORT AT MARKETENDIFI’m getting the following error (see yellow triangle in pdf).
I do not understand what to change in the code. Could someone help me?
Thanks,
Alco
12/14/2016 at 8:11 PM #18531123You have not defined variables a and b.ST <span class="token operator">=</span> <span class="token indicators">supertrend</span><span class="token punctuation">[</span>a<span class="token punctuation">,</span>b<span class="token punctuation">]</span>1 user thanked author for this post.
12/14/2016 at 8:19 PM #1853212/14/2016 at 8:54 PM #1853312/14/2016 at 10:01 PM #1853412/14/2016 at 11:37 PM #18537Hi Mike,
I tested in backtest the PRT code written in my first post. I got great results each day. I only tested it day by day. I had the best results in 10 min charts. So I wanted to test it in demo and got the error. I noticed that I used the wrong code. The code without MM. So I replaced it with this code
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106/// Definition of code parametersdefparam preloadbars = 3000DEFPARAM CumulateOrders = false // Cumulating positions deactivatedCOI= WEIGHTEDAVERAGE[14](ROC[11] +ROC[10])MAC= MACDline[12,26,9]STO = Stochastic[14,5]once RRreached = 0accountbalance = 10000 //account balance in money at strategy startriskpercent = 5 //whole account risk in percent%amount = 1 //lot amount to open each traderr = rr //risk reward ratio (set to 0 disable this function)//dynamic step gridminSTEP = 5 //minimal step of the gridmaxSTEP = 20 //maximal step of the gridATRcurrentPeriod = 5 //recent volatility 'instant' periodATRhistoPeriod = 100 //historical volatility periodATR = averagetruerange[ATRcurrentPeriod]histoATR= highest[ATRhistoPeriod](ATR)resultMAX = MAX(minSTEP*pipsize,histoATR - ATR)resultMIN = MIN(resultMAX,maxSTEP*pipsize)gridstep = (resultMIN)// Conditions to enter long positionsc1 = (COI > COI[1])c2 = (MAC > MAC[1])c3 = (STO > 20)c4 = (STO < 40)c5 = (STO > STO[1])// Conditions to enter short positionsc11 = (COI< COI[1])c12 = (MAC< MAC[1])c13 = (STO < 80)c14 = (STO > 60)c15 = (STO < STO[1])//first trade whatever conditionif NOT ONMARKET AND HIGHEST[5](c1)=1 AND HIGHEST[5](c2)=1 AND HIGHEST[5](c3)=1 AND HIGHEST[5](c4)=1 AND HIGHEST[5](c5)=1 then //close>close[1]BUY amount LOT AT MARKETendifif NOT ONMARKET AND HIGHEST[5](c11)=1 AND HIGHEST[5](c12)=1 AND HIGHEST[5](c13)=1 AND HIGHEST[5](c14)=1 AND HIGHEST[5](c15)=1 then //close<close[1]SELLSHORT amount LOT AT MARKETendif// case BUY - add orders on the same trendif longonmarket and close-tradeprice(1)>=gridstep*pipsize thenBUY amount LOT AT MARKETendif// case SELL - add orders on the same trendif shortonmarket and tradeprice(1)-close>=gridstep*pipsize thenSELLSHORT amount LOT AT MARKETendif//money managementliveaccountbalance = accountbalance+strategyprofitmoneyrisk = (liveaccountbalance*(riskpercent/100))if onmarket thenonepointvaluebasket = pointvalue*countofpositionmindistancetoclose =(moneyrisk/onepointvaluebasket)*pipsizeendif//floating profitfloatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize//actual trade gainsMAfloatingprofit = average[20](floatingprofit)BBfloatingprofit = MAfloatingprofit - std[20](MAfloatingprofit)*sd//floating profit risk reward checkif rr>0 and floatingprofit>moneyrisk*rr thenRRreached=1endif//GRAPH floatingprofit as "float"//GRAPH RRreached as "rr"//GRAPH floatingprofit as "floating profit"//GRAPH BBfloatingprofit as "BB Floating Profit"//GRAPH positionprice-mindistancetoclose//GRAPH moneyrisk//GRAPH onepointvaluebasket//GRAPH gridstep//stoploss trigger when risk reward ratio is not met alreadyif onmarket and RRreached=0 thenSELL AT positionprice-mindistancetoclose STOPEXITSHORT AT positionprice-mindistancetoclose STOPendif//stoploss trigger when risk reward ratio has been reachedif onmarket and RRreached=1 thenif floatingprofit crosses under BBfloatingprofit thenSELL AT MARKETEXITSHORT AT MARKETendifendif//resetting the risk reward reached variableif not onmarket thenRRreached = 0endifBut with the latest code, I don’t get the results like the old code in the backtests. I will try again tomorrow.
12/15/2016 at 9:11 AM #18539Hi Mike,
I’m testing mgc-trend-chaser-160914.itf again, I get great results in backtests for each day. But I know, before I can try it in demo, I need to optimize the supertrend variable a,b. But when I optimize the variable, like 1,4 or 2,8. Whatever I do, the results are not as good as before the optimizing. What configuration do I need, to get the same results if I optimize the supertrend for demo?
12/15/2016 at 9:25 AM #1854312/15/2016 at 9:43 AM #1854812/15/2016 at 10:19 AM #18556Sorry but I don’t understand your problem 🙂
Once you have found the optimised parameters that suit your needs (best results, low drawdown, etc.), you’ll have to write it directly into the code and delete the optimisation variables of the probacktest window.
In any case, the variables values that are set into the code are priority to the ones of the optimisation variables window.
12/15/2016 at 10:39 AM #18557Ok I try to explain it again Nicolas,
The first thing I did was testing this code
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657/// Definition of code parametersDEFPARAM CumulateOrders = false // Cumulating positions deactivatedCOI= CALL "MGC-Coppock"[14, 11, 10](close)MAC= MACDline[12,26,9](close)STO = Stochastic[14,5](close)ST = supertrend[a,b]// Conditions to enter long positionsc1 = (COI > COI[1])c2 = (MAC > MAC[1])c3 = (STO > 20)c4 = (STO < 40)c5 = (STO > STO[1])IF HIGHEST[5](c1)=1 AND HIGHEST[5](c2)=1 AND HIGHEST[5](c3)=1 AND HIGHEST[5](c4)=1 AND HIGHEST[5](c5)=1 AND NOT ONMARKET THENBUY 1 CONTRACT AT MARKETENDIF//SET STOP %Trailing 10// Conditions to exit long positions//c6 = (COI< COI[1])//c7 = (MAC< MAC[1])//c8 = (STO < 80)//c9 = (STO > 60)//c10 = (STO < STO[1])//IF HIGHEST[5](c6)=1 AND HIGHEST[5](c7)=1 AND HIGHEST[5](c8)=1 AND HIGHEST[5](c9)=1 AND HIGHEST[5](c10)=1 THENIF Close CROSSES UNDER ST THENSELL AT MARKETENDIF// Conditions to enter short positionsc11 = (COI< COI[1])c12 = (MAC< MAC[1])c13 = (STO < 80)c14 = (STO > 60)c15 = (STO < STO[1])IF HIGHEST[5](c11)=1 AND HIGHEST[5](c12)=1 AND HIGHEST[5](c13)=1 AND HIGHEST[5](c14)=1 AND HIGHEST[5](c15)=1 AND NOT ONMARKET THENSELLSHORT 1 CONTRACT AT MARKETENDIF//SET STOP %Trailing 10// Conditions to exit short positions//c16 = (COI> COI[1])//c17 = (MAC> MAC[1])//c18 = (STO > 20)//c19 = (STO < 40)//c20 = (STO > STO[1])//IF HIGHEST[5](c16)=1 AND HIGHEST[5](c17)=1 AND HIGHEST[5](c18)=1 AND HIGHEST[5](c19)=1 AND HIGHEST[5](c20)=1 THENIF close CROSSES OVER ST THENEXITSHORT AT MARKETENDIFResults where great in 5min and 10min time frames. But to use it in demo I got an error, because I didnt define: ST= supertrend [a,b]
After defining a and b, the results are bad. So I want to create the same results before the optimization.
02/06/2017 at 12:08 PM #24079Hi @Alco,
Sorry I have been off the air since early December.
The a and b variable are for optimising. I suggest you set ‘a’ at 1 to 10 with 2 step and ‘b’ at 5 to 40 with 5 step for faster optimisation. If the final results are close to either beginning or end, then adjust the variables until the result is somewhere in the middle of your beginning and end variables.
The next problem is that you have to have the MGC-Coppock defined in your platform so it can be called from your code. Better to substitute this for it “COI= WEIGHTEDAVERAGE[14](ROC[11] +ROC[10])”.
Now a word of warning, both codes with and without money management are quite complex with lots of variables. If you get a spectacular result in back-testing, it does not mean that you will get the same result in ProOrder. You need to forward test in ProOrder in demo mode for some time to be sure the code will produce a satisfactory result when run live.
If you read @cfta posts, you will find a good strategy for running ProOrder live.
02/06/2017 at 2:20 PM #24105Hi Alco
I note you say … I get great results in backtests for each day … and then you say you … results are not as good as before the optimizing? Also you provide a screen shot with good results for 1 day.
I’m confused, but would like to help, I hope I learn something while helping. I’m sure you know … if you optimise for 1 day then those optimised values will give highest profit that day or another day exactly the same (maybe never happen.).
Anyway, I couldn’t resist so attached is 100000 x 15M @ spread 2 on DAX with values ST = supertrend[6,25]. I’m setting it going on Demo Forward test right now.
Cheers
GraHalEdit: Attached MGC 2 with better curve / more profit using code with the following amendments
(Apologies Mods, Insert PRT Code button not visible)
IF Close CROSSES UNDER ST or RSI[14](close) < 22 THEN
SELL AT MARKET
ENDIFIF close CROSSES OVER ST or RSI[14](close) > 74 THEN
EXITSHORT AT MARKET
ENDIF02/06/2017 at 3:42 PM #24118@GraHal, what is your computer screen resolution please? the button is not available below a certain proportion to avoid problem with mobile/tablet…
1 user thanked author for this post.
02/06/2017 at 7:44 PM #24149Hi Nicolas
Due to not wanting to wear glasses and to give large font / text size … my screen resolution is 1024 x 768.
I can see the insert PRT button if I clear everything out as attached, but if I have loads of tabs open on other tasks then I not want to ‘clear all’ at that point.
I just deleted ‘all cookies associated with this PRC site’ (only) and I then had to log back in, but still the Inser PRT Code is not visible.
Cheers
GraHal -
AuthorPosts
Find exclusive trading pro-tools on