Help for trailing stop please

 

Hi friends, i want to enter the position and for example when i buy, trailing stop must to placed 300 points below and must follow the current price.
Where did i went wrong?


#include <Trade\Trade.mqh>

CTrade trade;

int OnInit(void){

   return(INIT_SUCCEEDED);

}



void OnTick(void)

  {

      myOnTick();

  }



void myOnTick()

{

 

 double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);  //satış fiyatını sorguladık

 double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);  //alış fiyatını sorguladık

 

  //******************************************************************mum tanımlama****************************

   

  double current_close=iClose(_Symbol,PERIOD_CURRENT,0);

  double current_low = iLow(_Symbol,PERIOD_CURRENT,0);

  double current_high = iHigh(_Symbol,PERIOD_CURRENT,0);

  

  

  //******************************************************************some indicator definitons are here *************************

   double ...[];

   int ...Definition = iCustom(_Symbol,_Period,"...");  

   ArraySetAsSeries(...,true);

   CopyBuffer(...Definition,0,0,5,...);

   

   ***

//***********************************************************

  

   if (PositionsTotal() == 0){

      if (current_close>...[1])

        trade.Buy(0.01,NULL,Ask,(Ask-1000*_Point),(Ask + 500 * _Point),NULL); 

         

      if ( current_close<...[1])

         trade.Sell(0.01,NULL,Ask,(Ask-1000*_Point),(Ask + 500 * _Point),NULL); 

   } else {

   

  

 

      CheckTrailingStop(Ask);

   

   }

}





void CheckTrailingStop (double Ask)

  {

   double SL = NormalizeDouble(Ask - 300 * _Point, _Digits);   

   for(int i=PositionsTotal()-1; i>=0;i--)                     

      {

       string symbol=PositionGetSymbol(i);                       

         if(_Symbol==symbol)                                          

         {

           ulong PositionTicket = PositionGetInteger(POSITION_TICKET);                 

           double CurrentStopLoss=PositionGetDouble(POSITION_SL);                    

           if (CurrentStopLoss<SL)                                                                         

             {  trade.PositionModify(PositionTicket,(CurrentStopLoss + 300*_Point),0);  

             }

         }            //end symbol for loop

      }              //end trailin stop bracket

 }


Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Position ticket. Unique number assigned to each newly opened position. It usually matches the ticket of an order used to open the position except when the ticket is changed as a result of service operations on the server, for example, when charging swaps with position re-opening. To find an order used to open a position, apply the...
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Use the debugger or print out your variables, including _LastError and prices and . Do you really expect us to debug your code for you?
Reason: