if OrderProfit()>0) { }
In your orderselect loop.
At first: thanks a lot for the quick reply! The only thing is that I am a absolute newbie in coding. Where should I put this information? And is the OrderProfit calculated included with swap costs and commissions?
Thanks!
Where should I put this information?
If you want the program to check constantly whether the profit of a trade reached a particular level, place your codes on the OnTick() function of an EA..
And is the OrderProfit calculated included with swap costs and commissions?
No, First of all in order to use OrderProfit(), you should have selected the order as mentioned by @Marco vd Heijden..
To include Swap and Commissions you should calculate them..
input double X_Amount = 5.0; // X Amount //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { for(int i=OrdersTotal()-1;i>=0;i--) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderType() > 1)continue; if(OrderSymbol() != Symbol()) continue; if(OrderStopLoss() == OrderOpenPrice())continue; double totProfit = OrderProfit() + OrderSwap() + OrderCommission(); if(totProfit >= X_Amount) if(!OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0)) Print("Order Modify Error = ",GetLastError()); } }
This is an example code..
Note I assumed that the orders are opened manually, So I didn't use Magic Number when filtering the orders..
Check out this one <Deleted>
Please do not use the forum to advertise products even if they are in the MQL5 market.
Do so again and you may be banned.
Please do not use the forum to advertise products even if they are in the MQL5 market.
Do so again and you may be banned.
- 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 guys,
Looked through the archives of the coding database. I am looking for a script which does the following:
As soon as I open a trade and it reached X amount of profit it need to move the SL to BE immediately and automated. Is there already a script available for this matter?
Kind regards,
Mark