I need your Help. Thank you and Thank you !

 

Hello everyone,

I have written the code for Trailing Stop based on Pending Orders. Could anyone please have a look on it? it has warning but allowing execution. I have no idea does it work or not. And the Trailing Stop sets at 30, does it mean 30 pips or 30 fractional pips? 

Thank you very much if someone could rewrite it. 

P.S.: the purpose of the code below is setting Buy Stop & Sell Stop with Trailing Stop  

Lawrence

//+------------------------------------------------------------------+
//|                                      TestingTrailing+Pending.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

#property copyright "Copyright 2016, WidiPramana."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

extern string  Name_EA                 = "PendingOrder";
extern int     TP                      = 100;    
extern int     SL                      = 100;      
extern double  Lots                    = 0.01;
extern int     Distance                = 10;      
extern int     Magic                   = 69;
extern double  TrailStop               = 30;      

int      digit=0;
double slb,tpb,sls,tps,pt;
int res,wt,wk,tiket,ticet;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if(Digits==3 || Digits==5) pt=10*Point;   else   pt=Point;
//----
   return(0);
  }
  
  
  // ---- Trailing Stops
void TrailStops()
{        
    int total=OrdersTotal();
    for (int cnt=0;cnt<total;cnt++)
    {
     OrderSelect(cnt, SELECT_BY_POS);  
     int mode=OrderType();    
        if ( OrderSymbol()==Symbol() )
        {
            if ( mode==OP_BUY )
            {
               if ( Bid-OrderOpenPrice()>Point*TrailStop )
               {
               double BuyStop = OrderOpenPrice();
               OrderModify(OrderTicket(),OrderOpenPrice(),
                           NormalizeDouble(BuyStop, digit),
                           OrderTakeProfit(),0,LightGreen);
                              }
                           }
            if ( mode==OP_SELL )
            {
               if ( OrderOpenPrice()-Ask>Point*TrailStop )
               {
               double SellStop = OrderOpenPrice();
               OrderModify(OrderTicket(),OrderOpenPrice(),
                                  NormalizeDouble(SellStop, digit),
                                  OrderTakeProfit(),0,Yellow);      
               }    
            }
         }  
      }
}

// ---- Scan Trades
int ScanTrades()
{  
   int total = OrdersTotal();
   int numords = 0;
      
   for(int cnt=0; cnt<total; cnt++)
   {        
   OrderSelect(cnt, SELECT_BY_POS);            
   if(OrderSymbol() == Symbol() && OrderType()<=OP_SELL)
   numords++;
   }
   return(numords);
}


//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
label();

   digit  = MarketInfo(Symbol(),MODE_DIGITS);

   if(Hour_trade()==1){
      if(totalorder(4)==0){res=OrderSend(Symbol(), OP_BUYSTOP,NR(Lots) , Ask+Distance*Point, 3, Ask+Distance*Point-SL*Point,Ask+Distance*Point+TP*Point, "", Magic, 0, Blue);}
      if(totalorder(5)==0){res=OrderSend(Symbol(), OP_SELLSTOP,NR(Lots) , Bid-Distance*Point, 3, Bid-Distance*Point+SL*Point,Bid-Distance*Point-TP*Point, "", Magic, 0, Red);}
      if (ScanTrades()<1) return(0);
      else
      if (TrailStop>0) TrailStops();
           }
   return(0);
  }
//+------------------------------------------------------------------+

int Hour_trade()
{
   bool trade = true;
   return (trade);
}

int totalorder( int tipe)
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
  {
      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=tipe) continue;
     total++;
  }

return(total);
}
double NR(double thelot)
{
    double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
    minilot = MarketInfo(Symbol(), MODE_MINLOT),
    lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
    double lots = lstep * NormalizeDouble(thelot / lstep, 0);
    lots = MathMax(MathMin(maxlots, lots), minilot);
    return (lots);
}

void label()
{
Comment("\n ",
   "\n ",
   "\n ------------------------------------------------",
   "\n :: Pending+Order",
   "\n ------------------------------------------------",
   "\n :: Spread                 : ", MarketInfo(Symbol(), MODE_SPREAD),
   "\n :: Leverage               : 1 : ", AccountLeverage(),
   "\n :: Equity                 : ", AccountEquity(),
   "\n :: Hour Server             :", Hour(), ":", Minute(),
   "\n ------------------------------------------------");
}


 

 
Please check this EA, I already fix the warning.
Files:
Check_EA.mq4  6 kb
 
Biantoro Kunarto:
Please check this EA, I already fix the warning.

Hi Biantoro Kunarto,

 Thank you for your fixing the EA, I am going to test it later. Could you please tell me the Trailing Stop sets at 30, does it mean 30 pips or 30 fractional pips?  And does the Trailing Stop have any signal showing when trading?

 Thank you once again for your kindly help!

 Look forward to your reply.

Lawrence 

 
30 points (or fractional pips like you call them). If you want pips, you should replace 'Point', at all sites where it appears, by 'pt' variable. Regards.
 
Lawrencema0829:

Hi Biantoro Kunarto,

 Thank you for your fixing the EA, I am going to test it later. Could you please tell me the Trailing Stop sets at 30, does it mean 30 pips or 30 fractional pips?  And does the Trailing Stop have any signal showing when trading?

 Thank you once again for your kindly help!

 Look forward to your reply.

Lawrence 

Trailing stop, Stop loss & Take profit are in points.

I don't understand about "does the Trailing Stop have any signal showing when trading?", what do you mean ?

 
If you want to change to pips, just like  Jose Francisco Casado Fernandez  said : you must change the Point with pt . Please check below EA, I already change it too
Files:
Check_EA1.mq4  6 kb
 
Biantoro Kunarto:

Trailing stop, Stop loss & Take profit are in points.

I don't understand about "does the Trailing Stop have any signal showing when trading?", what do you mean ?

Hi Biantoro, 

Buy Stop and Sell Stop are green line, SL and TP are red lines, I am wondering does Trailing Stop has a color line to show up when trading?

Unifying Trailing Stop, SL and TP in points is good, I just couldn't see the parameter of Trailing Stop under the Trade Panel.

Lawrence 

 
Lawrencema0829:

Hi Biantoro, 

Buy Stop and Sell Stop are green line, SL and TP are red lines, I am wondering does Trailing Stop has a color line to show up when trading?

Unifying Trailing Stop, SL and TP in points is good, I just couldn't see the parameter of Trailing Stop under the Trade Panel.

Lawrence 

For trailing stop there is no color, but you can see the SL lines (red line )

About the trailing stop, you can see the setting at this picture :


 
Biantoro Kunarto:

For trailing stop there is no color, but you can see the SL lines (red line )

About the trailing stop, you can see the setting at this picture :


Thank you! it works well!
Reason: