- OrderSelect loop
- iBarShift( ... OrderOpenTime() )
- OrderDelete(OrderTicket()
- Loops and Closing or Deleting Orders - MQL4 forum
Does anybody know any other way of closing orders if there was no trigger after a specified number of bars? thank you.
- OrderSelect loop
- check if Time[specified number of bars] > OrderOpenTime() selected pending
- OrderDelete(OrderTicket()
- Loops and Closing or Deleting Orders - MQL4 forum
Thank you deVries,I am almost there, now please answer me this:
Is this one the correct way to put it?
I've declared DelTimeInSec as an external int var..Please advice.
datetime OOpenTime = OrderOpenTime(); if(Time[0] - OOpenTime > DelTimeInSec)
Here is the whole loop:
for(int a=OrdersTotal()-1;a>=0;a--) { if(OrderSelect(a,SELECT_BY_TICKET) if(OrderMagicNumber()==MagicNumber) if(OrderSymbol()==Symbol()) if(OrderType()==OP_SELLSTOP || OP_BUYSTOP) datetime OOpenTime = OrderOpenTime(); if(Time[0] - OOpenTime > DelTimeInSec)
if(OrderType()==OP_SELLSTOP || OP_BUYSTOP)
that line is wrong written
if(OrderType()==OP_SELLSTOP || OrderType()==OP_BUYSTOP)
if(OrderSelect(a,SELECT_BY_TICKET)
SELECT_BY_TICKET ??? You didn't read
You asked Please advice on how to write a function to delete a pending order if it has not been triggered for a specified number of periods (candles).
So you can't use DelTimeInSec because you don't know how many bars that will be
don't forget weekend
that line is wrong written
You asked Please advice on how to write a function to delete a pending order if it has not been triggered for a specified number of periods (candles).
So you can't use DelTimeInSec because you don't know how many bars that will be
don't forget weekend
Here is what i've thought of, should work no?
for(int a=OrdersTotal()-1;a>=0;a--) { if(OrderSelect(a,SELECT_BY_TICKET)) if(OrderMagicNumber()==MagicNumber) if(OrderSymbol()==Symbol()) if(OrderType()==OP_SELLSTOP || OrderType()==OP_BUYSTOP) datetime OOpenTime = OrderOpenTime(); int nBarsSinceOpen = iBarShift(NULL,0,OOpenTime); if(nBarsSinceOpen >= 2 && (OrderType() == OP_SELLSTOP || OrderType() == OP_BUYSTOP)) OrderDelete(OrderTicket(),CLR_NONE); }
if(OrderSelect(a,SELECT_BY_TICKET)
SELECT_BY_TICKET ??? You didn't read
- Loops and Closing or Deleting Orders - MQL4 forum
for(int a=OrdersTotal()-1;a>=0;a--) { if(OrderSelect(a,SELECT_BY_TICKET))
Is 'a' here your OrderTicketnumber ????
select | - | Selecting flags. It can be any of the following values: SELECT_BY_POS - index in the order pool, SELECT_BY_TICKET - index is order ticket. |
ok so it should be:
(OrderSelect(a,SELECT_BY_TICKET,MODE_TRADES)) Is there anything else I did wrong?
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi!
Please advice on how to write a function to delete a pending order if it has not been triggered for a specified number of periods (candles).
Thanks.