stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

reliable delete pending code
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1607
Page 1 of 1
Author:  Spectre [ Mon Mar 11, 2013 7:18 pm ]
Post subject:  reliable delete pending code

hello

i am growing increasingly frustrated with myself. i cannot get my code to work right.

i want the code to close all pending orders at bar close, but whatever i try it sometimes leaves trades behind. it goes on offline/renko charts, so using expiration on the pending is unfortunately not going to work. i have tried
Time[0] > Time[1], Close[] value coding,

Code: Select all

 static int OldBar = Time[0]
if (Time[0] != OldBar) 
anyone have a good solution that will work everytime?? (preferably copy paste code , i am sick and tired of pending orders :roll: )

i bet if someone here gives me the answer or something closer to a solution, i will slap my head and cry myself to sleep in shame over its simplicity

Thomas
Author:  magft [ Mon Mar 11, 2013 10:02 pm ]
Post subject:  Re: reliable delete pending code

Spectre wrote:hello

i am growing increasingly frustrated with myself. i cannot get my code to work right.

i want the code to close all pending orders at bar close, but whatever i try it sometimes leaves trades behind. it goes on offline/renko charts, so using expiration on the pending is unfortunately not going to work. i have tried
Time[0] > Time[1], Close[] value coding,

Code: Select all

 static int OldBar = Time[0]
if (Time[0] != OldBar) 
anyone have a good solution that will work everytime?? (preferably copy paste code , i am sick and tired of pending orders :roll: )

i bet if someone here gives me the answer or something closer to a solution, i will slap my head and cry myself to sleep in shame over its simplicity

Thomas
Why not try

Code: Select all

static int OldBars=Bars;
if(OldBars!=Bars)
{
    OldBars=Bars
    //delete pendings etc
}
This is time independent and works on offline charts as well. You could replace

Code: Select all

Bars
with

Code: Select all

iBarShift(Symbol(),tf)
to check new bar on a different tf.

Regards

Mike
Author:  slipshod [ Sat Apr 06, 2013 6:32 am ]
Post subject:  Re: reliable delete pending code

Not sure if Spectre's found a solution to this problem yet, but its one I ran into as well. A couple of things to check:-

Firstly are you looping from 0 to OrdersTotal() in a for loop? If so, OrdersTotal() will vary with each trade deleted & you're highly likely to get some left behind. This happens even if you do: int total=OrdersTotal() and then for (i=0; i<total; i++). The solution is for (i=total-1; i>=0; i--)

Secondly its possible that even that doesn't get the job done. You might want to try something like this:-

Code: Select all

int total = OrdersTotal(), i;
static int orders[];
int deltotal = 0;
ArrayResize(orders, total);

for (i=total-1; i>=0; i--)
{
   OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
   if statement checking to ensure its your order, magic # ordertype etc etc
   {
      orders[deltotal] = OrderTicket();
      deltotal++;
   }
}

for (i=0; i<deltotal; i++)
   OrderDelete(orders[i]);
Btw this might prove useful for deleting live orders as well. Never hurts to be paranoid :)
All times are UTC Page 1 of 1