Jmalad :
Hello MQL5 community
Can someone please help me, by example; how do i close an open trade, either through a function or TP amount?
I tried this:
1. Please insert the code correctly: when editing a message, press the button and paste your code into the pop-up window. (The first time I corrected your message)
2. Nothing is clear from your explanation. Do you want to close all positions if the profit on your trading account is more than $ 2.0?
Jmalad:
Hello MQL5 community
Can someone please help me, by example; how do i close an open trade, either through a function or TP amount?
I tried this:
#include <trade/trade.mqh> void OnStart() { PendingOrderDelete() ; MarketOrderClose(); } void MarketOrderClose() { CTrade trade; int i=PositionsTotal()-1; while (i>=0) { if (trade.PositionClose(PositionGetSymbol(i))) // ulong o_ticket = OrderGetTicket(i); //trade.OrderDelete(o_ticket); i--; } PendingOrderDelete() ; } void PendingOrderDelete() { CTrade mytrade; int o_total=OrdersTotal(); for(int j=o_total-1; j>=0; j--) { ulong o_ticket = OrderGetTicket(j); if(o_ticket != 0) { // delete the pending order mytrade.OrderDelete(o_ticket); Print("Pending order deleted sucessfully!"); } } }
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 MQL5 community
Can someone please help me, by example; how do i close an open trade, either through a function or TP amount?
I tried this: