1 : ->Signal
2 : opening a Position (remembering its SL Level)
3 : setting an opposite pending order with x2 the initial lot size and 10 pips TP and finally setting SL Below/Above your initial trade SL + 5 pips
4 : if your initial trade hit the TP (or Trailingstop) then cancel the pending order (<-this is where I struggle)
I dont find an accurate way to do step 4.
I tried to get the ticket of the initial Position & the Pending (i hope this is right):
doubleAsk =SymbolInfoDouble(_Symbol, SYMBOL_ASK);
Print ("Long!!");
if(LongPosition(Ask,Ask-StopLossLong,Ask+TakeProfitLong)) //Function for Positions
{
double Price = Ask-StopLossLong;
LastPosTicketLong = most_recently_opened_Pos();
if(ShortPending(Price,Price+StopLossShort2,Price-TakeProfitShort2)) //Function for Pending Order
{LastOrderTicketLong = most_recently_opened_Order();}
Tradeallow=false;
}
...
ulong most_recently_opened_Pos()
{
long youngestPositiontime=0;
ulong youngestPosition=-1;
int total =PositionsTotal();
for(int i=0;i<total;i++)
{
ulong ticket=PositionGetTicket(i);
long Positiontime = PositionGetInteger(POSITION_TIME);
if (Positiontime > youngestPositiontime)
{
youngestPositiontime = Positiontime;
youngestPosition = ticket; }
}
if (youngestPosition>0)
{
return(youngestPosition);
}
else {return(0);}
}
ulong most_recently_opened_Order()
{
long youngestOrdertime=0;
ulong youngestOrder=-1;
int total =OrdersTotal();
for(int i=0;i<total;i++)
{
if (OrderGetInteger(ORDER_TYPE)==(ORDER_TYPE_BUY_STOP||ORDER_TYPE_SELL_STOP))
{
ulong ticket=PositionGetTicket(i);
long Ordertime = OrderGetInteger(ORDER_TIME_SETUP);
if (Ordertime > youngestOrdertime)
{
youngestOrdertime = Ordertime;
youngestOrder = ticket;
}
}
}
if (youngestOrder>0)
{
return(youngestOrder);
}else {return(0);}
}
If this above is right I only need a way, how I can detect if the Initial order has been closed (wether by unchanged SL or by TP/Trailing stop or if it made a profit or a loss)
How can i get these Information of the closed Position???
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Question is above, This is my Plan:
1 : ->Signal
2 : opening a Position (remembering its SL Level)
3 : setting an opposite pending order with x2 the initial lot size and 10 pips TP and finally setting SL Below/Above your initial trade SL + 5 pips
4 : if your initial trade hit the TP (or Trailingstop) then cancel the pending order (<-this is where I struggle)
I dont find an accurate way to do step 4.
I tried to get the ticket of the initial Position & the Pending (i hope this is right):
If this above is right I only need a way, how I can detect if the Initial order has been closed (wether by unchanged SL or by TP/Trailing stop or if it made a profit or a loss)
How can i get these Information of the closed Position???
Thank you so much ! :O