scrip PO sell does not work

 

Why this scrip does not work,.

when there is no error 

anyone can help

,. 

//+------------------------------------------------------------------+
//|                        SCRIPT PENDING ORDER NFP JPY              |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "t3300"
#property show_inputs


 
//+------------------------------------------------------------------+
//| input parameters:                                                |
//+------------------------------------------------------------------+



extern string  scripted_BY = "-=====__NFP JPY___==== ";
extern double  star_SELL_STOP=1.3049;

extern double  LotSize = 0.02;  
extern double  LotExponent = 1.24;   
 
extern int     jarak_antar_Po  = 13;       
extern int     MaxTrades=50;
extern string  tpsl = "-=====PAKE TPSL atau ngga=== ";
extern bool    dgn_TPSL=true;         
extern int     TP=500;
extern int     SL=25;

extern string  auto = "-=====auto_PENDING_ORDER==== ";
extern bool    auto_PO =true;
extern int     PipStep = 26; 


 bool          InformationOnChart = true; 
 int           MagicNumber = 0;       
  int          LotDecimal = 0;
   string      CommentTrades;
   bool        pending_stop=true;
   
   
   

//============= 
int start()



{

      int expiration=CurTime()+PERIOD_H4*28800;
     
      
      CommentTrades= "PO "+Symbol();
     
      if (LotDecimal==0) LotDecimal = LotDecimal();
      
   //--------------
     
    
    
    
    
    //--------------
    if(pending_stop==true)
    
    {
    double start_SELL_STOPx=pricex1("pricex1");
   
    double slbx=SLTP("slb");
    double slsx=SLTP("sls");
    double tpbx=SLTP("tpb");
    double tpsx=SLTP("tps");
     double  SELL_STOPx;
     
    int x;
    for(x=0;x<=MaxTrades;x++)
    {
    
    
    
    if(x==1)
    
   
     // if(totalPO("totalPO")==0)
      
      
      {
        
     OrderSend(Symbol(),OP_SELLSTOP,LotSize,NormalizeDouble(start_SELL_STOPx,Digits),3,slsx,tpsx,CommentTrades,MagicNumber,expiration);//,0,LightCyan);
      
      }
          
       
     
     if(x>1)
     
       
        
     // if(totalPO("totalPO")>0 && totalPO("totalPO")<MaxTrades )
     
     {
    
        SELL_STOPx=FindLastOrder("sellstop","Price")+jarak_antar_Po *Point;
    OrderSend(Symbol(),OP_SELLSTOP,NextLot("sellstop"),NormalizeDouble(SELL_STOPx,Digits),3,slsx,tpsx,CommentTrades,MagicNumber,expiration);//,0,LightCyan);
    
       }
       if (x==MaxTrades)break;
      }
      }  
         
    
 return(0);
}
   //--------------
 
double NextLot(string OrdType){
   double tLots;
   
   if (OrdType=="sellstop"){
    tLots = NormalizeDouble(FindLastOrder(OrdType, "Lots") * LotExponent, LotDecimal);
      
   }
      return(tLots);
      }
      




//====================
double FindLastOrder(string OrdType, string inf)
{
   double OrderPrice;
   double LastLot;
   
   int trade, oldticketnumber=0;
   
   for(trade=OrdersTotal()-1;trade>=0;trade--)
   {
      OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber) continue;
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
         {
         //----
            if (OrdType=="sellstop")
            {
               if(OrderType()==OP_SELLSTOP)
               {
                  if(OrderTicket()>oldticketnumber)
                  {
                     OrderPrice=OrderOpenPrice();
                     LastLot = OrderLots();
                     oldticketnumber=OrderTicket();
                    
                     
                  }
                }
             }
             //---- 
   }
}
if (inf=="Price") return(OrderPrice);
if (inf=="Lots")  return(LastLot);


}
//+------------------------------------------------------------------+//+------------------------------------------------------------------+

//+------------------------------------------------------------------+



/*
int orderPOx(string OrdType)
{
   int count=0;
   int trade;
   for(trade=OrdersTotal()-1;trade>=0;trade--)
   {
      OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber) continue;
      if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
      {
      //----
         if (OrdType == "sellstop")
         {
            if(OrderType()==OP_SELLSTOP) count++;
         }
         //----
      }
   }
   return(count);
}
//+------------------------------------------------------------------+
int totalPO(string OrdType)
   {
   int count=0;
   {
   if(OrdType=="totalPO")count=orderPOx("sellstop");
   }
   return(count);

   }
  
*/
//----------------------------------------------------------------------
double LotDecimal()
{
   double steplot=MarketInfo(Symbol(), MODE_LOTSTEP);
   int LotsDigits = MathCeil(MathAbs(MathLog(steplot)/MathLog(10)));

return(LotsDigits);
}

//----------------------------------------------------------------------



double pricex1(string inf)
   {
   double pricexx1=0;
   if(inf=="pricex1")
   {
   if(auto_PO)pricexx1=Ask +(PipStep/1)*Point;
   }
   return(pricexx1);
   
   }


double get_tpsl(string inf)
     
     {
     
     double harga=0;
     double pricex1;
    pricex1=pricex1("pricex1");
      {
      if(inf=="slbz")harga=pricex1-SL*Point;
      if(inf=="tpbz")harga=pricex1+TP*Point;
    
      }
      return(harga);
      }
    //--------------
    double SLTP(string inf)
    
    {
     
     double slb,tpb,sls,tps;
     
     slb=get_tpsl("slbz");
     sls=get_tpsl("slsz");
     tpb=get_tpsl("tpbz");
     tps=get_tpsl("tpsz");
     
     if(dgn_TPSL)
     {
      slb=tps;sls=tpb;tps=slb;tpb=sls;
     }
     else 
     {
     slb=0;tps=0;sls=0;tpb=0;
     }
      if(inf=="slb")return (slb);
       if(inf=="tpb")return (tpb);
        if(inf=="sls")return (sls);
         if(inf=="tps")return (tps);
    
    }
Files:
 
yudidarso:

Why this scrip does not work,.

when there is no error 

anyone can help

Check your return values,  report your errors . . .  What are Function return values ? How do I use them ?
 

You have two issues here, suggest you revisit your Lots function and the ordersend function:

1. Invalid Lots amount for ordersend function

2. Order Send Error 148 (The amount of open and pending orders has reached the limit set by the broker. New open positions and pending orders can be placed only after the existing positions or orders have been closed or deleted.)

Mod edit: Advertising removed

 

Look here: https://www.mql5.com/en/users/register

It says . . . "4. Posting of advertising messages is forbidden. "

 

Do not attempt to Advertise,  next time you will receive a Ban. 

 

Review:

1. The script creates to many orders because the loop to create the order repeats itself non-stop. Perhaps place a limit so that it does not re-run the order send function:

2. The order operation type is incorrect. I modified the operation type to OP_BUYLIMIT for it to start opening orders.

3. There also seems an issue with calculating the next lot size. Try changing all to correct operation type of buy limit, including comments.

bool enter = true;

----------------------------------

 if (enter == true)
{
 for(x=0;x<=MaxTrades;x++)
 {
 if(x<=1) 
{ 
OrderSend(Symbol(),OP_BUYLIMIT,LotSize,NormalizeDouble(start_BUY_STOPx,Digits),3,slbx,tpbx,CommentTrades,MagicNumber,expiration);

 }
 if(x>1) 
{
 BUY_STOPx=FindLastOrder("buystop","Price")+jarak_antar_Po *Point;
 OrderSend(Symbol(),OP_BUYLIMIT,NextLot("buystop"),NormalizeDouble(BUY_STOPx,Digits),3,slbx,tpbx,CommentTrades,MagicNumber,expiration);
 }
 if (x==MaxTrades)
 { 
break;
 }
 }
 enter = false;
 } 
} 
return(0);

Thank you
DTK_Forex 

 

Play video
Please edit your post.
For large amounts of code, attach it.
Reason: