Kevin Johnson:
Hello,
I've coded a basic MQL4 EA to open a BUY order and SELL STOP order at the same time.
I would like to know if it's possible to remove the TP from the BUY order once SELL STOP order is activated.
So below is the BUY order with TP 10 points...but I would like for the EA to set that TP to 0 once my SELL STOP is activated.
It can be done simply like this. However, if you want to code professionally, the Magicnumber of both orders should be different. and if the sum of BUY and SELL is equal to 2, you can make TP zero.
//+------------------------------------------------------------------+ //| Haskayafx.mq4 | //| Copyright 2017, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2017, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict double BuyTotal=0; double SellTotal=0; int init() { BuyTotal=0; SellTotal=0; return(0); } int OrderBUYSELL() { BuyTotal=0; SellTotal=0; int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; if (OrderType()==OP_BUY) BuyTotal=BuyTotal+1; if (OrderType()==OP_SELL) SellTotal=SellTotal+1; } return(0); } int HedefAyarla() { bool ticket; for (int lx = 0; lx < OrdersTotal(); lx++) { if(OrderSelect(lx,SELECT_BY_POS,MODE_TRADES)==false) break; if(OrderTakeProfit()!=0) ticket= OrderModify(OrderTicket(), OrderOpenPrice(),OrderStopLoss(), 0, 0, CLR_NONE); } return(0); } int start() { BuyTotal=0; SellTotal=0; OrderBUYSELL(); if(BuyTotal>0 && SellTotal>0) HedefAyarla(); return(0); }
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
Hello,
I've coded a basic MQL4 EA to open a BUY order and SELL STOP order at the same time.
I would like to know if it's possible to remove the TP from the BUY order once SELL STOP order is activated.
So below is the BUY order with TP 10 points...but I would like for the EA to set that TP to 0 once my SELL STOP is activated.