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/26/2020 at 10:32 PM #148591
Good evening, I’m having a similar issue and tried various combinations but couldn’t solve it. I’m running a small programme on TF 15 minutes. I’ve read a few posts thanks to Nicolas which say that non executed STOP Orders are cancelled at the end of the candle. This doesn’t work in my case. So I tried to add the following lines and still doesn’t cancel the pending orders. The objective is to auto cancel the non executed orders at the end of the 15 minutes candle. I’m really stuck and this results either in keeping orders with irrelevant conditions. Please help me see clearer. Many thanks.
1234567891011121314151617181920212223242526ONCE LONG = 0ONCE SHORT = 0ONCE NbBarLimit = 1IF LongOnMarket THENLONG = 1MyIndex = BarindexENDIFIF ShortOnMarket THENSHORT = 1MyIndex = BarindexENDIFIF (Barindex >= (MyIndex + NbBarLimit)) THENLONG = 0SHORT = 0ENDIFIF LONG=0 THENVarible A = max ( Value X1 , Value Y1)ENDIFIF SHORT=0 THENVarible A = max ( Value X2 , Value Y2)ENDIF10/26/2020 at 11:41 PM #148596Pending orders are automatically cancelled every bar.
If one of them keeps being placed again is because somewhere you have written your strategy to.
1 user thanked author for this post.
10/27/2020 at 12:16 AM #148598Thank you Roberto for taking the time. Can you please help me with what’s wrong in my code that makes the pending orders alive after the end of the 15 minutes candle? Much appreciated.
123456789101112131415161718192021222324252627282930313233343536373839404142defparam cumulateorders = falsedefparam preloadbars = 2000TIMEFRAME (15 minutes)N = 1 //Number of Contracts/////////////////////////////////////////// CALCULATION OF VALUE X AND VALUE Y //////////////////////////////////////////boxsizeL = max ( ValueX , 20)boxsizeS = max ( ValueY , 10)renkomaxL = round(close / boxsizeL) * boxsizeLrenkominL = renkomaxL - boxsizeLrenkomaxS = round(close / boxsizeS) * boxsizeSrenkominS = renkomaxS - boxsizeSif high > renkomaxl + boxsizel thenrenkomaxl = renkomaxl + boxsizelrenkominl = renkominl + boxsizelendifif low < renkomins - boxsizes thenrenkomaxs = renkomaxs - boxsizesrenkomins = renkomins - boxsizesendifIF time>=133000 AND time>200000 thenspread = 0.5ELSIF time>=200000 AND time>220000 thenspread = 2.5ELSIF time>=220000 AND time>133000 thenspread = 1ENDIFIF NOT ONMARKET THENBUY N CONTRACT at (renkoMaxL + boxSizeL + spread) STOPSELLSHORT N CONTRACT at (renkoMinS - boxSizeS - spread) STOPENDIFSET STOP pTRAILING 5SET TARGET pPROFIT 100010/27/2020 at 12:38 AM #14859910/27/2020 at 1:12 AM #148600No, it’s because at line 36 the only condition to enter a trade is NOT ONMARKET, so when this condition is true it opens a new position.
You need to add another condition. When do you want your trades to be opened?
1 user thanked author for this post.
10/27/2020 at 1:47 AM #14860210/27/2020 at 3:52 PM #148677Roberto, I’ve spoken a little bit too quickly I think. I’ve tried a few conditions to enter a trade and the problem persists: pending orders are not cancelled at the end of each candle, and I keep carying a pending order with irrelevant entry conditions for a few hours. So, I’ve just removed all the conditions to trigger a trade and the result is the same. I stopped the Algo after the Orders have been sent and still they are not cancelled. Below you will see a snaphopt of two pending orders on 3min TF. The most recent is the Short one (3.18pm), but the Long (3.15pm) should have been cancelled.
The most important question for me is how to get the pending order cancelled, not how to get a new one executed.
Thanks for your help.
12345678910111213141516171819202122232425262728293031323334353637383940414243defparam cumulateorders = falsedefparam preloadbars = 2000TIMEFRAME (15 minutes)N = 1 //Number of ContractsCondition = 1/////////////////////////////////////////// CALCULATION OF VALUE X AND VALUE Y //////////////////////////////////////////boxsizeL = max ( ValueX , 20)boxsizeS = max ( ValueY , 10)renkomaxL = round(close / boxsizeL) * boxsizeLrenkominL = renkomaxL - boxsizeLrenkomaxS = round(close / boxsizeS) * boxsizeSrenkominS = renkomaxS - boxsizeSif high > renkomaxl + boxsizel thenrenkomaxl = renkomaxl + boxsizelrenkominl = renkominl + boxsizelendifif low < renkomins - boxsizes thenrenkomaxs = renkomaxs - boxsizesrenkomins = renkomins - boxsizesendifIF time>=133000 AND time>200000 thenspread = 0.5ELSIF time>=200000 AND time>220000 thenspread = 2.5ELSIF time>=220000 AND time>133000 thenspread = 1ENDIFIF CONDITION=1 THENBUY N CONTRACT at (renkoMaxL + boxSizeL + spread) STOPSELLSHORT N CONTRACT at (renkoMinS - boxSizeS - spread) STOPENDIFSET STOP pTRAILING 5SET TARGET pPROFIT 100010/27/2020 at 5:01 PM #148686Pending orders ARE ALWAYS cancelled every candle (in your case every 15 minutes). If you don’t focus on this you will never be able to understand why this happens.
If ProOrder keeps placing them is because your strategy KEEPS placing them again and again.
You were using only NOT ONMARKET, which is true whenever there’s no open position. So I suggested you to add another condition to filter entries and you replaced NOT ONMARKET (instead of adding a new one) with CONDITION=1 which is set at the beginning and NEVER changes, so it will always be true candle after candle and pending orders will be entered each time. That’s why nothing changed.
Choose a condition that makes sense to you and use it. YOU know what condition must be used, I can’t be of any help, just as an example I could write:
1IF Not OnMarket AND close CROSSES OVER average[200,0](close) THENI used two conditions, but you can use just one or add more.
10/27/2020 at 5:05 PM #148695I decided to make a topic of its own because:
- the subject is a little be different
- the topic is growing
1 user thanked author for this post.
10/27/2020 at 5:51 PM #148706Thank you Roberto. Are you saying that as far as the conditions for entry stay the same, the pending order is not cancelled?
Example:
1IF Not OnMarket AND Close > average[200,0](close) THENif I understand what you said: if the Close stays above the SMA200, the pending order stays active?
Thanks
Khaled
10/27/2020 at 7:05 PM #148713I don’t know how to explain that!
As I already said twice, pending orders are ALWAYS cancelled when a bar closes. You need to be aware of this, because you think a pending order has to be cancelled, while the opposite is true… you have to place again a pending order when you need to. Forget about cancelling them, ProOrder gets rid of them automatically when a bar closes!
In your example if the next bar is Not OnMarket and Close > average[200,0](close), a NEW pending order (the previous one has already been cancelled automatically by ProOrder) is placed.
Instructions within IF…ENDIF are executed when the condition (or more than one) is true. If your conditions are true bar after bar, then a pending order (or more than one) will be placed again bar after bar.
1 user thanked author for this post.
10/27/2020 at 7:44 PM #148718Dear Roberto,
First, I want to really thank you again for taking the time to answer my questions. I’m a beginner and may ask candide questions and I hope one day I’ll be in position to generously help others, like you do.
Secondly, I understand your point but as you can see on the screenshot I’ve attached above, it shows two pending orders, created with the same Algo running under 3min TF, the first generated at 3.15pm and the second generated at 3.18pm, meaning that the first Order has not been cancelled at 3.18pm despite the closure of the previous 3min candle. If the first order was cancelled automatically and has been replaced by a new one at the smae price conditions, then it would show the 3.18pm timing instead of 3.15pm.
I didn’t want to bother you with so much details, but below is the complete code of the Algo that doesn’t work as expected, may be something wrong with my coding skills or the order of appearance of the instructions. This code is largely inspired from https://www.prorealcode.com/topic/machine-learning-in-proorder/page/26/#post-129120
Again, my concern is that the pending orders are not cancelled automatically at the end of each candle.
Your help is much appreciated.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292defparam cumulateorders = falsedefparam preloadbars = 2000N = 0.5C1 = 1C2 = 2heuristicscyclelimit = 2once 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 = 40 //5, 100, 10 //LONG BOXSIZEResetPeriod = 3 //1, 0.5 Specify no of months after which to reset optimisationincrement = 10 //10 //5, 20, 10maxincrement = 20 //5, 10 limit of no of increments either up or downreps = 3 //1 number of trades to use for analysis //2maxvalue = 5 //10 //70 //50 //50, 20, 300, 150 //maximum allowed valueminvalue = increment //15, 5, minimum allowed valuestartingvalue2 = 15 //40 //5, 100, 50 //SHORT BOXSIZEResetPeriod2 = 3 //1, 0.5 Specify no of months after which to reset optimisationincrement2 = 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) //added (maxvalue+minvalue)/2 to avoid division by zero errorboxsizeS = max ( ValueY , (maxvalue2+minvalue2)/2) //added (maxvalue+minvalue)/2 to avoid division by zero error//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 - boxsizesendif// IG SPREAD for DAX 1€IF 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.5ENDIF// Conditions C1 and C2 (can be customized) set to 1 to test the programmeIF C1=1 THENBUY N CONTRACT at (renkoMaxL + boxSizeL + spread) STOPENDIFIF C2=2 THENSELLSHORT N CONTRACT at (renkoMinS - boxSizeS - spread) STOPENDIF// SL and TP and Breakevenset stop ptrailing 3set target pprofit 500startBreakeven = 6PointsToKeep = 1IF NOT ONMARKET THENbreakevenLevel=0ENDIFIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIFIF SHORTONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)-PointsToKeep*pipsizeENDIFIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIFIF breakevenLevel>0 THENEXITSHORT AT breakevenLevel STOPENDIF10/27/2020 at 8:35 PM #148720There are some basic programming rules that we cannot discuss further here, such as IF…ENDIF and conditions. I already explained you basically what it is all about and you continue adding conditions that are ALWAYS true. What sense does it make writing:
1234567C1 = 1...IF C1 = 1 THEN//place pending orderENDIFand complaining again and again about pending orders not being cancelled! C1 is set to 1 initially and NEVER changes, but you still keep it as a condition to place a pending order. Why after the first time, ProOrder should not place it again and again…. ?
Pending orders ARE automatically cancelled (I will stop replying to you until this is clear, there are tons of examples and topics about this, beyond official documentation and forum searches).
It’s YOU who have coded you strategy so that it places pending orders continuosly.
I can help you code your conditions if you can’t, but you need to tell me WHICH are those conditions that you need for a pending order to be PLACED (not cancelled, forget about cancelling them and focus on how to place them).
1 user thanked author for this post.
10/27/2020 at 9:08 PM #148727Khaled, let me also try to explain, may be you will get it.
Your condition to buy is
123IF C1=1 THENBUY N CONTRACT at (renkoMaxL + boxSizeL + spread) STOPENDIFFor first candle, when C1=1, your strategy places one stop order, which stays active for the duration of the candle, and gets cancelled if not fulfilled during that candle’s lifetime.Then for second candle again, C1=1 and an exactly similar order gets placed (to you it seems like same order as earlier), and just like above, gets cancelled if not fulfilled during that candle’s lifetime.And this loops continues at every candle as long as C1=1.Your problem is that C1(or C2) never gets updated…so, as Roberto has advised, unless you write a logic to update your conditions, you will keep on seeing the issue.Hope it helps….kaq1 user thanked author for this post.
10/27/2020 at 9:18 PM #148729Thank you Kaq. I get the point. Just want to understand then why the time of the first order doesn’t change, order that is supposed to be cancelled and replaced by another order at the same price conditions doesn’t change? stays 3.15 pm, while the most recent order is marked 3.18pm? This is what leads me to think that the first order is not cancelled. I’m not arguing or whatsover, I’m just trying to understand and learn properly.
-
AuthorPosts
Find exclusive trading pro-tools on