Like when after sell order is triggered I like to close Buy order if any order has been executed and when buy order is triggered, I like to close Sell order if any order has been present.
Can’t understand where to put close trade code and also how to use closetrade code in mql5. I don’t want any stop-loss and take profit methods and tickets all that. I want simple direct method.
input double Lots=0.01;
input ENUM_TIMEFRAMES Timeframe = PERIOD_CURRENT;
input double Step = 0.04;
input double Maximum = 0.2;
parabolicSarHandle = iSAR (_Symbol,Timeframe,Step,Maximum);
barsTotal = iBars(_Symbol,Timeframe);
void OnDeinit(const int reason)
double val ;
int bars = iBars(_Symbol,Timeframe);
if (barsTotal != bars)
double close0 = iClose(_Symbol,Timeframe,0); double close1 = iClose(_Symbol,Timeframe,1);
if (close0 >val  && close1 <val )
Print (__FUNCTION__ ">Buy Signal"); trade.Buy(Lots,_Symbol,0,0,0,"SAR BUY"); barsTotal = bars; }
else if (close0 < val  && close1 > val )
Print (__FUNCTION__ ">Sell Signal"); trade.Sell(Lots,_Symbol,0,0,0,"SAR SELL"); barsTotal = bars; }
Comment ("\nParabolic SAR: ",DoubleToString(val,_Digits),
"\nParabolic SAR: ",DoubleToString(val,_Digits)); }
After trade.Buy execution, I want to close Sell order of the same and when trade.Sell is executed, I want to close Buy order automatically.
How do i do it?
Like trade.CloseOrder(trade.Buy) or trade.ClosePosition(trade.Sell) ?
When and where and what to write?