Hi coder please guide me how change my this code.
I want ea set one tp for last OPEN order for all my previous open order like this image.
if(use_auto_tp) tp_prev_f();
////////////////////////////////////////////////////////////////////
void tp_prev_f()
{
int type;
double prev_price=-1;
double prev_tp=-1;
bool first=false;
for (int i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderMagicNumber()!=Magic || OrderSymbol()!=Symbol()) continue;
if(!first)
{
first=true;
prev_price=OrderOpenPrice();
prev_tp=OrderTakeProfit();
continue;
}
type=OrderType();
if (type==OP_BUY)
{
if (Bid>=prev_price && OrderTakeProfit()<prev_tp)
{
if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),prev_tp,0,clrNONE)) continue;
}
}
else
if (type==OP_SELL)
{
if (Ask<=prev_price && OrderTakeProfit()>prev_tp)
{
if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),prev_tp,0,clrNONE)) continue;
}
}
}
I want ea set one tp for last OPEN order for all my previous open order like this image.
if(use_auto_tp) tp_prev_f();
////////////////////////////////////////////////////////////////////
void tp_prev_f()
{
int type;
double prev_price=-1;
double prev_tp=-1;
bool first=false;
for (int i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderMagicNumber()!=Magic || OrderSymbol()!=Symbol()) continue;
if(!first)
{
first=true;
prev_price=OrderOpenPrice();
prev_tp=OrderTakeProfit();
continue;
}
type=OrderType();
if (type==OP_BUY)
{
if (Bid>=prev_price && OrderTakeProfit()<prev_tp)
{
if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),prev_tp,0,clrNONE)) continue;
}
}
else
if (type==OP_SELL)
{
if (Ask<=prev_price && OrderTakeProfit()>prev_tp)
{
if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),prev_tp,0,clrNONE)) continue;
}
}
}