Add trailing step input to Trailing stops

 
void TrailingPositionBuy (int idTrailingStoploss,int idMagic,int idTicket)
{

int TS = idTrailingStoploss;

   for(int TS=0; TS<OrdersTotal(); TS++)
   {
   
      if(OrderSelect(idTicket, SELECT_BY_TICKET))
      {
      
         if(OrderSymbol()==Symbol())
         {
         
            if(OrderType()==OP_BUY&&OrderMagicNumber()==idMagic)
            {
               
               if(Bid-OrderOpenPrice()>idTrailingStoploss*_Point)
               {
               
                  if(OrderStopLoss()<Bid-idTrailingStoploss*_Point)
                     ModifyStoploss(Bid-idTrailingStoploss*_Point);

               }
               
            }
            
         }
         
      }
         
   }

}

void TrailingPositionSell (int idTrailingStoploss,int idMagic,int idsTicket)
{

int TS = idTrailingStoploss;

   for(int TS=0; TS<OrdersTotal(); TS++)
   {
   
      if(OrderSelect(idsTicket, SELECT_BY_TICKET))
      {
      
         if(OrderSymbol()==Symbol())
         {
         
            if(OrderType()==OP_SELL&&OrderMagicNumber()==idMagic)
            {
               
               if(Ask-OrderOpenPrice()>idTrailingStoploss*_Point)
               {
               
                  if(OrderStopLoss()<Ask-idTrailingStoploss*_Point)
                     ModifyStoploss(Ask-idTrailingStoploss*_Point);
                  
               }
               
            }
            
         }
         
      }
         
   }

}

Its working fine just need the steps input added

 

About getting coding free help.

Welcome,

  • Usually people who cannot code do not receive free help on this forum, although it could happen if you are lucky. Be patient.
  • If you show your attempts and describe your problem clearly, you will most probably receive an answer from the community.
  • If you do not want to learn to code, that is not a problem. You can either look at the Codebase if something free already exists, or in the Market for paid products (also sometimes free).
  • Finally, you also have the option to hire a programmer in the Freelance section.

Good luck.

 

Please don't post randomly in any section. Your question is not related to the section you posted.

MT4/mql4 has it's own section on the forum.

I have moved your topic to the correct section later, please don't create another topic.

 
  1.    for(int TS=0; TS<OrdersTotal(); TS++)
       {
       
          if(OrderSelect(idTicket, SELECT_BY_TICKET))

    Why are you selecting/processing your ticket multiple times. Once is enough.

  2.          if(OrderSymbol()==Symbol())
             {
             
                if(OrderType()==OP_SELL&&OrderMagicNumber()==idMagic)

    Where did you get that ticket number. Shouldn't it already be the correct symbol/magic?

  3. EAs must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover?

    Use a OrderSelect / Position select loop on the first tick, or persistent storage (GV+flush or files) of ticket numbers required.

  4. Stop using ChatGPT.
              Help needed to debug and fix an AI EA - Trading Systems - MQL5 programming forum (2023)