Cancelling pending orders
Forums › ProRealTime English forum › ProOrder support › Cancelling pending orders
- This topic has 18 replies, 4 voices, and was last updated 1 year ago by GraHal.
-
-
10/27/2020 at 10:29 PM #148736
Replace line 4 with
Once C1=1
After line 264, add line
C1=0
What this will do is that for the first candle, C1 being true will place a long order. However, for second candle, C1 being false will not place order but first order should be cancelled automatically. This will explain how the candle loops work.
You are facing this confusion because you have hardcoded the condition to be ALWAYS TRUE regardless of what happens. Your strategy need to update your conditions to be “true” or “false” based on some criteria (whatever criteria you chose) and it will work like a breeze.
Rgds, kaq
10/27/2020 at 10:43 PM #14873802/28/2023 at 10:59 AM #148803@kaq52 @juanj @Nicolas @martentornquist @robertogozzi @Bard
Dear All, thank you very much for your support. The idea suggested by kaq52 is very much what I was looking for. For what it’s worth, I’m sharing here my code and the result of the backtest. Please bear with me if you find erros or room for improvement.
I’m not proficient in PRT, but I tired to assemble a few pieces here and there found on this forum. I used ML based on code published by Bard here https://www.prorealcode.com/reply/128486/
Variables have obviously been over-optimized for DAX 15 minutes 1€ with IG CFDs. WF provides a relatively high result… Not sure how this will work in live trading.
I’d apprecite if some of you can test it (live if possible) and share their feedback. I’ve doubts about:
1/ the price distance between certain orders calculated by the system vs what IG accepts.
2/ the interaction between Stop Loss calculated by this system, Spread and actual execution price… I’ve seen that for orders with nearly breakeven results in backtest I ended losing 1 or 2 euros in actual trading.
3/ overnight holding cost.
4 /not sure how these impressive Backtest results will translate in reality over a few weeks
4/ Last but not least… I tried ML with one and with two variables on a very simple SMA cross Algo and I’ve observed on different TF that ML with only one variable provides better results than ML with two variables… I’m very interested in your thoughts on this.
Next steps: add conditions/optimize entry points to reduce false signals, try wider SL (?),
Again, thank you and look forward to hear your feedback.
DAX M15 Test with ML123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313// DAX M15 Test with MLDEFPARAM CUMULATEORDERS = FALSEDEFPARAM PRELOADBARS = 10000N = 1ONCE C1 = 0ONCE C2 = 0iMACD = MACD[12,26,9](close)iRSI = RSI[14](close)StochK = Stochastic[14,3](close)StochD = Average[5](Stochastic[14,3](close))indicator7, indicator6 = CALL KST1 //Standard KST Indicatorc1L = (iMACD > 0) AND (iMACD > iMACD[1])c2L = (iRSI > iRSI[1])c3L = (StochK > StochD)c4L = (StochD > StochD[1])c5L = (indicator6 < indicator7)c1S = (iMACD < 0) AND (iMACD < iMACD[1])c2S = (iRSI < iRSI[1])c3S = (StochK < StochD)c4S = (StochD < StochD[1])c5S = (indicator6 > indicator7)IF c1L AND c2L AND c3L AND c4L AND c5L THENC1 = 1ENDIFIF c1S AND c2S AND c3S AND c4S AND c5S THENC2 = 1ENDIF// ALOG AND MLheuristicscyclelimit = 7once heuristicscycle = 0once heuristicsalgo1 = 1once heuristicsalgo2 = 0if heuristicscycle >= heuristicscyclelimit thenif heuristicsalgo1 = 1 thenheuristicsalgo2 = 1heuristicsalgo1 = 0elsif heuristicsalgo2 = 1 thenheuristicsalgo1 = 1heuristicsalgo2 = 0endifheuristicscycle = 0elseonce valuex = startingvalueonce valuey = startingvalue2endifif heuristicsalgo1 = 1 then//heuristics algorithm 1 startif (onmarket[1] = 1 and onmarket = 0) or (longonmarket[1] = 1 and longonmarket and countoflongshares < countoflongshares[1]) or (longonmarket[1] = 1 and longonmarket and countoflongshares > countoflongshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares < countofshortshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares > countofshortshares[1]) or (longonmarket[1] and shortonmarket) or (shortonmarket[1] and longonmarket) thenoptimise = optimise + 1endif//Settings 1 & 2startingvalue = 5 //5 //10 //40 //5, 100, 10 //LONG BOXSIZEResetPeriod = 1 //3 //1, 0.5 Specify no of months after which to reset optimisationincrement = 5 //10 //5 //10 //10 //5, 20, 10maxincrement = 5 //20 //5, 10 limit of no of increments either up or downreps = 6 //3 //1 number of trades to use for analysis //2maxvalue = 5 //5 //10 //70 //50 //50, 20, 300, 150 //maximum allowed valueminvalue = increment //15, 5, minimum allowed valuestartingvalue2 = 5 //5 //10 //50 //15 //40 //5, 100, 50 //SHORT BOXSIZEResetPeriod2 = 3 //1, 0.5 Specify no of months after which to reset optimisationincrement2 = 5 //10 //10 //5, 10maxincrement2 = 5 //20 //1, 30 limit of no of increments either up/down //4reps2 = 2 //3 //1, 2 nos of trades to use for analysis //3maxvalue2 = 5 //5 //50, 20, 300, 200 maximum allowed valueminvalue2 = increment2 //15, 5, minimum allowed valueonce monthinit = monthonce yearinit = yearIf (year = yearinit and month = (monthinit + ResetPeriod)) or (year = (yearinit + 1) and ((12 - monthinit) + month = ResetPeriod)) ThenValueX = StartingValueWinCountB = 0StratAvgB = 0BestA = 0BestB = 0monthinit = monthyearinit = yearEndIfonce valuex = startingvalueonce pincpos = 1 //positive increment positiononce nincpos = 1 //negative increment positiononce optimise = 0 //initialize heuristicks engine counter (must be incremented at position start or exit)once mode1 = 1 //switches between negative and positive increments//once wincountb = 3 //initialize best win count//graph wincountb coloured (0,0,0) as "wincountb"//once stratavgb = 4353 //initialize best avg strategy profit//graph stratavgb coloured (0,0,0) as "stratavgb"if optimise = reps thenwincounta = 0 //initialize current win countstratavga = 0 //initialize current avg strategy profitheuristicscycle = heuristicscycle + 1for i = 1 to reps doif positionperf(i) > 0 thenwincounta = wincounta + 1 //increment current wincountendifstratavga = stratavga + (((positionperf(i)*countofposition[i]*close)*-1)*-1)nextstratavga = stratavga/reps //calculate current avg strategy profit//graph (positionperf(1)*countofposition[1]*100000)*-1 as "posperf1"//graph (positionperf(2)*countofposition[2]*100000)*-1 as "posperf2"//graph stratavga*-1 as "stratavga"//once besta = 300//graph besta coloured (0,0,0) as "besta"if stratavga >= stratavgb thenstratavgb = stratavga //update best strategy profitbesta = valuexendif//once bestb = 300//graph bestb coloured (0,0,0) as "bestb"if wincounta >= wincountb thenwincountb = wincounta //update best win countbestb = valuexendifif wincounta > wincountb and stratavga > stratavgb thenmode1 = 0elsif wincounta < wincountb and stratavga < stratavgb and mode1 = 1 thenvaluex = valuex - (increment*nincpos)nincpos = nincpos + 1mode1 = 2elsif wincounta >= wincountb or stratavga >= stratavgb and mode1 = 1 thenvaluex = valuex + (increment*pincpos)pincpos = pincpos + 1mode1 = 1elsif wincounta < wincountb and stratavga < stratavgb and mode1 = 2 thenvaluex = valuex + (increment*pincpos)pincpos = pincpos + 1mode1 = 1elsif wincounta >= wincountb or stratavga >= stratavgb and mode1 = 2 thenvaluex = valuex - (increment*nincpos)nincpos = nincpos + 1mode1 = 2endifif nincpos > maxincrement or pincpos > maxincrement thenif besta = bestb thenvaluex = bestaelseif reps >= 10 thenweightedscore = 10elseweightedscore = round((reps/100)*100)endifvaluex = round(((besta*(20-weightedscore)) + (bestb*weightedscore))/20) //lower reps = less weight assigned to win%endifnincpos = 1pincpos = 1elsif valuex > maxvalue thenvaluex = maxvalueelsif valuex < minvalue thenvaluex = minvalueendifoptimise = 0endif// heuristics algorithm 1 endelsif heuristicsalgo2 = 1 then// heuristics algorithm 2 startif (onmarket[1] = 1 and onmarket = 0) or (longonmarket[1] = 1 and longonmarket and countoflongshares < countoflongshares[1]) or (longonmarket[1] = 1 and longonmarket and countoflongshares > countoflongshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares < countofshortshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares > countofshortshares[1]) or (longonmarket[1] and shortonmarket) or (shortonmarket[1] and longonmarket) thenoptimise2 = optimise2 + 1endif//Settings 2once monthinit2 = monthonce yearinit2 = yearIf (year = yearinit2 and month = (monthinit2 + ResetPeriod2)) or (year = (yearinit2 + 1) and ((12 - monthinit2) + month = ResetPeriod2)) ThenValueY = StartingValue2WinCountB2 = 0StratAvgB2 = 0BestA2 = 0BestB2 = 0monthinit2 = monthyearinit2 = yearEndIfonce valuey = startingvalue2once pincpos2 = 1 //positive increment positiononce nincpos2 = 1 //negative increment positiononce optimise2 = 0 //initialize heuristicks engine counter (must be incremented at position start or exit)once mode2 = 1 //switches between negative and positive incrementsif optimise2 = reps2 thenwincounta2 = 0 //initialize current win countstratavga2 = 0 //initialize current avg strategy profitheuristicscycle = heuristicscycle + 1for i2 = 1 to reps2 doif positionperf(i2) > 0 thenwincounta2 = wincounta2 + 1 //increment current wincountendifstratavga2 = stratavga2 + (((positionperf(i2)*countofposition[i2]*close)*-1)*-1)nextstratavga2 = stratavga2/reps2 //calculate current avg strategy profitif stratavga2 >= stratavgb2 thenstratavgb2 = stratavga2 //update best strategy profitbesta2 = valueyendifif wincounta2 >= wincountb2 thenwincountb2 = wincounta2 //update best win countbestb2 = valueyendifif wincounta2 > wincountb2 and stratavga2 > stratavgb2 thenmode2 = 0elsif wincounta2 < wincountb2 and stratavga2 < stratavgb2 and mode2 = 1 thenvaluey = valuey - (increment2*nincpos2)nincpos2 = nincpos2 + 1mode2 = 2elsif wincounta2 >= wincountb2 or stratavga2 >= stratavgb2 and mode2 = 1 thenvaluey = valuey + (increment2*pincpos2)pincpos2 = pincpos2 + 1mode2 = 1elsif wincounta2 < wincountb2 and stratavga2 < stratavgb2 and mode2 = 2 thenvaluey = valuey + (increment2*pincpos2)pincpos2 = pincpos2 + 1mode2 = 1elsif wincounta2 >= wincountb2 or stratavga2 >= stratavgb2 and mode2 = 2 thenvaluey = valuey - (increment2*nincpos2)nincpos2 = nincpos2 + 1mode2 = 2endifif nincpos2 > maxincrement2 or pincpos2 > maxincrement2 thenif besta2 = bestb2 thenvaluey = besta2elseif reps2 >= 10 thenweightedscore2 = 10elseweightedscore2 = round((reps2/100)*100)endifvaluey = round(((besta2*(20-weightedscore2)) + (bestb2*weightedscore2))/20) //lower reps = less weight assigned to win%endifnincpos2 = 1pincpos2 = 1elsif valuey > maxvalue2 thenvaluey = maxvalue2elsif valuey < minvalue2 thenvaluey = minvalue2endifoptimise2 = 0endif// heuristics algorithm 2 endendif//boxsizeL = max ( ValueX , (maxvalue+minvalue)/2)boxsizeS = max ( ValueY , (maxvalue2+minvalue2)/2)//renkomaxl = round(close / boxsizel) * boxsizelrenkominl = renkomaxl - boxsizelrenkomaxs = round(close / boxsizes) * boxsizesrenkomins = renkomaxs - boxsizes//if high > renkomaxl + boxsizel thenrenkomaxl = renkomaxl + boxsizelrenkominl = renkominl + boxsizelendifif low < renkomins - boxsizes thenrenkomaxs = renkomaxs - boxsizesrenkomins = renkomins - boxsizesendifIF time>=001500 AND time>060000 thenspread = 2ELSIF (time>=060000 AND time>070000) AND (time>=153000 AND time>200000)thenspread = 1ELSIF time>=070000 AND time>153000 thenspread = 0.6ELSIF time>=200000 AND time>001500 thenspread = 2.5ENDIFIF C1=1 THENBUY N CONTRACT at (renkoMaxL + boxSizeL + spread) STOPENDIFIF C2=1 THENSELLSHORT N CONTRACT at (renkoMinS - boxSizeS - spread) STOPENDIFC1 = 0C2 = 0SET STOP pTRAILING 2SET TARGET pPROFIT 20002/28/2023 at 8:01 PM #210671I’d love to try it, but where is KST1 Indicator?
KST1 is not the standard Indicator as Line 14 (copied below) needs 2 values and the standard KST returns only 1 value.
indicator7, indicator6 = CALL KST1 //Standard KST Indicator
-
AuthorPosts
Find exclusive trading pro-tools on