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.
...
#include <Trade/Trade.mqh>
input double Lots=0.01;
input ENUM_TIMEFRAMES Timeframe = PERIOD_CURRENT;
input double Step = 0.04;
input double Maximum = 0.2;
int parabolicSarHandle;
int barsTotal;
CTrade trade;
int OnInit()
{
parabolicSarHandle = iSAR (_Symbol,Timeframe,Step,Maximum);
barsTotal = iBars(_Symbol,Timeframe);
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
}
void OnTick()
{
double val [];
CopyBuffer (parabolicSarHandle,0,0,2,val);
int bars = iBars(_Symbol,Timeframe);
if (barsTotal != bars)
{
double close0 = iClose(_Symbol,Timeframe,0);
double close1 = iClose(_Symbol,Timeframe,1);
if (close0 >val [1] && close1 <val [0])
{
Print (__FUNCTION__ ">Buy Signal");
trade.Buy(Lots,_Symbol,0,0,0,"SAR BUY");
barsTotal = bars;
}
else if (close0 < val [1] && close1 > val [0])
{
Print (__FUNCTION__ ">Sell Signal");
trade.Sell(Lots,_Symbol,0,0,0,"SAR SELL");
barsTotal = bars;
}
Comment ("\nParabolic SAR[0]: ",DoubleToString(val[0],_Digits),
"\nParabolic SAR[1]: ",DoubleToString(val[1],_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?