Close Buy after SL change

EnrichWave

Master Trader
May 15, 2018
347
83
74
India
Sorry, but your request isn't clear. Please explain what you are trying to do.
Thank you so much for the reply @Enivid .

MQL5:
void OnStart()
  {
      for(int i = PositionsTotal(); i >= 0; i--)
         {
         if(m_position.SelectByIndex(i))
           if (PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
            m_trade.PositionClose(m_position.Ticket());          
         }
  }


It's is the script I'm using to close the buy order.. But I would like to move all the SL's to near that open order price before close.. for example
in EURUSD If the order is bought at 1.1012.. While I use the script It should move the SL to 1.1010 (2 point below the open price), and close it.

Kind regards
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,058
1,472
144
Odesa
www.earnforex.com
Thank you so much for the reply @Enivid .

MQL5:
void OnStart()
  {
      for(int i = PositionsTotal(); i >= 0; i--)
         {
         if(m_position.SelectByIndex(i))
           if (PositionGetString(POSITION_SYMBOL)==Symbol() && PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
            m_trade.PositionClose(m_position.Ticket());         
         }
  }


It's is the script I'm using to close the buy order.. But I would like to move all the SL's to near that open order price before close.. for example
in EURUSD If the order is bought at 1.1012.. While I use the script It should move the SL to 1.1010 (2 point below the open price), and close it.

Kind regards
But what's the point of moving the position's SL just before closing it?
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,058
1,472
144
Odesa
www.earnforex.com
I'm implementing a kind of strategy Enivid. I would open an opposite order with higher SL, So the total order risk will be calculated as higher risk.
I still have no idea what's the point is, but you can use the PositionModify() method (I assume m_position is a CTrade object?) just before calling the PositionClose().
 

EnrichWave

Master Trader
May 15, 2018
347
83
74
India
I still have no idea what's the point is,
Yes Enivid, I understood it's hard to understand.
m_position is a CTrade object?
Yes. its CTrade
you can use the PositionModify()
Yes Enivid. the PositionModify() has (ticket,SL,TP)..
ticket = (I don't know how to get this ticket)
SL=(How to get open price of that order here so we can subtract 2 point from that)
TP=(PositionGetDouble(POSITION_TP)) works fine (without modifying the older TP)
I don't know how to do that..
 

Enivid

Administrator
Staff member
Nov 30, 2008
19,058
1,472
144
Odesa
www.earnforex.com
  • 🚀
Reactions: EnrichWave

Enivid

Administrator
Staff member
Nov 30, 2008
19,058
1,472
144
Odesa
www.earnforex.com
I misunderstood. Works clear.

But sometime while we have more multiple orders. It's not changing the SL as we give value. It keeps as it was in the beginning.

View attachment 26652
What is the output in the Journal tab then? It should say something about its attempt to modify the trades.