I'll give a lazy answer first - if you tick visual mode in the strategy tester, you can see what happens when the bid or ask price hits the pending order. It should turn into a buy or sell position
Alright ORDER_TYPE_BUY and ORDER_TYPE_SELL are not pending orders. They might have been in MQL4, but they are instantly executed orders in MQL5. That is why the condition will never work
this will work:
void CheckOrderExistence(){ for(int i = 0; i < OrdersTotal(); i++){ ulong order = OrderGetTicket(i); if(order > 0 && OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_BUY_STOP){ Print("Buy stop order created", order); } else if(order > 0 && OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_SELL_STOP){ Print("Sell stop order created", order); } else if(order > 0 && OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_BUY_LIMIT){ Print("Buy limit order created", order); } else if(order > 0 && OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_SELL_LIMIT){ Print("Sell limit order created", order); } } }
Conor Mcnamara #:
Thank you so much! How would you go about to check if these have been triggered? For example; my buy stop is triggered and now it has become a market order that has been filled and is waiting for either Sl or TP. Meaning I want to do a new loop that enables you to change the stoploss and takeprofit for an activeorder as well.
Alright ORDER_TYPE_BUY and ORDER_TYPE_SELL are not pending orders. They might have been in MQL4, but they are instantly executed orders in MQL5. That is why the condition will never work
this will work:
Felix Lehmann #:
Thank you so much! How would you go about to check if these have been triggered? For example; my buy stop is triggered and now it has become a market order that has been filled and is waiting for either Sl or TP. Meaning I want to do a new loop that enables you to change the stoploss and takeprofit for an activeorder as well.
Thank you so much! How would you go about to check if these have been triggered? For example; my buy stop is triggered and now it has become a market order that has been filled and is waiting for either Sl or TP. Meaning I want to do a new loop that enables you to change the stoploss and takeprofit for an activeorder as well.
When a order is executed it becomes a Position
You can make a loop with PositionTotal()
Felix Lehmann #:
Thank you so much! How would you go about to check if these have been triggered? For example; my buy stop is triggered and now it has become a market order that has been filled and is waiting for either Sl or TP. Meaning I want to do a new loop that enables you to change the stoploss and takeprofit for an activeorder as well.
Thank you so much! How would you go about to check if these have been triggered? For example; my buy stop is triggered and now it has become a market order that has been filled and is waiting for either Sl or TP. Meaning I want to do a new loop that enables you to change the stoploss and takeprofit for an activeorder as well.
An activated order simply becomes a position. So you'll do that loop:
for (int i = PositionsTotal() - 1; i >= 0; i--){ ulong posTicket = PositionGetTicket(i); if (posTicket > 0) { if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL){ // the sell stop order turned into a position, handle it here now } } }

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
My MQL5 script places pending orders. I later want to be able to modify them ones activated. I've therefore made a couple of if statements in the "OnTick()" function. My desired result would be that the script prints "Order has been activated." once in the loop but it is not working.
Can anyone help me to se what i've done wrong? I've provided the code I think. this is the first time I'm posting here so sorry if I'm breaking any community rules. :)