Help with code - 'PutOrder' Wrong parameters count

 

It returns as the code is wrong, but I am not able to know what could be wrong. Can anybody help me?


  if(TrailingStop>0) Trailing();


   if((CountTrades()<1 && (BuySell==0 || BuySell==1) && b) || (CountTrades()>0 && FindOrderType()==0 && (FindLastBuyPrice()-Ask)/Point>=Step*Plus) || (CountTrades()>1 && FindOrderType()==0 && (FindLastBuyPrice()-Ask)/Point>=Step))
     {
      PutOrder(0,Ask);
      ModifyOrders();
      b=0;s=1;
     }

   if((CountTrades()<1 && (BuySell==0 || BuySell==2) && s) || (CountTrades()>0 && FindOrderType()==1 && (Bid-FindLastSellPrice())/Point>=Step*Plus) || (CountTrades()>1 && FindOrderType()==1 && (Bid-FindLastSellPrice())/Point>=Step))
     {
      PutOrder(1,Bid);
      ModifyOrders();
      b=1;s=0;
     }
 
Yajaira Thibisay Martinez Jaimes:

It returns as the code is wrong, but I am not able to know what could be wrong. Can anybody help me?


  if(TrailingStop>0) Trailing();


   if((CountTrades()<1 && (BuySell==0 || BuySell==1) && b) || (CountTrades()>0 && FindOrderType()==0 && (FindLastBuyPrice()-Ask)/Point>=Step*Plus) || (CountTrades()>1 && FindOrderType()==0 && (FindLastBuyPrice()-Ask)/Point>=Step))
     {
      PutOrder(0,Ask);
      ModifyOrders();
      b=0;s=1;
     }

   if((CountTrades()<1 && (BuySell==0 || BuySell==2) && s) || (CountTrades()>0 && FindOrderType()==1 && (Bid-FindLastSellPrice())/Point>=Step*Plus) || (CountTrades()>1 && FindOrderType()==1 && (Bid-FindLastSellPrice())/Point>=Step))
     {
      PutOrder(1,Bid);
      ModifyOrders();
      b=1;s=0;
     }

how do you suppose we could help when you provide this tiny sample? were's the rest? or you expect use to be mind readers perhaps...

plus

when you insert code use Alt+S

code

 
Yajaira Thibisay Martinez Jaimes:

It returns as the code is wrong, but I am not able to know what could be wrong. Can anybody help me?


  if(TrailingStop>0) Trailing();


   if((CountTrades()<1 && (BuySell==0 || BuySell==1) && b) || (CountTrades()>0 && FindOrderType()==0 && (FindLastBuyPrice()-Ask)/Point>=Step*Plus) || (CountTrades()>1 && FindOrderType()==0 && (FindLastBuyPrice()-Ask)/Point>=Step))
     {
      PutOrder(0,Ask);
      ModifyOrders();
      b=0;s=1;
     }

   if((CountTrades()<1 && (BuySell==0 || BuySell==2) && s) || (CountTrades()>0 && FindOrderType()==1 && (Bid-FindLastSellPrice())/Point>=Step*Plus) || (CountTrades()>1 && FindOrderType()==1 && (Bid-FindLastSellPrice())/Point>=Step))
     {
      PutOrder(1,Bid);
      ModifyOrders();
      b=1;s=0;
     }

Check the declaration of PutOrder - it is 'your' function.

As we don't know it we can't help you.

 
Carl Schreiber:

Check the declaration of PutOrder - it is 'your' function.

As we don't know it we can't help you.

Thanks Carl. The declaration looks like this right now:

void PutOrder(int type,double price,double lot)

  {

   int r=0;

   color clr=clrNONE;

   double sl=SYMBOL_TRADE_STOPS_LEVEL,tp=SYMBOL_TRADE_STOPS_LEVEL;

   datetime expiration=0;



   if(type==1 || type==3 || type==5)

     {

      clr=Red;

      if(StopLoss>0)

         sl=NormalizeDouble(price+StopLoss*Point,Digits);

      if(TakeProfit>0)

         tp=NormalizeDouble(price-TakeProfit*Point,Digits);

     }



   if(type==0 || type==2 || type==4)

     {

      clr=Blue;

      if(StopLoss>0)

         sl=NormalizeDouble(price-StopLoss*Point,Digits);

      if(TakeProfit>0)

         tp=NormalizeDouble(price+TakeProfit*Point,Digits);

     }



   r=OrderSend(NULL,type,Lot(),NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,expiration,clr);

   return;

  }
 

I am having several problems with SL TP / Volumes and Money for trades, it could be the reason.

Are there any codes to add as a filter at the beginning that will apply to all trades in the script?

 
  1. Yajaira Thibisay Martinez Jaimes:  The declaration looks like this right now:
    void PutOrder(int type,double price,double lot)

    You were asked in #1. Again: 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.  PutOrder(0,Ask);
    Your call has two arguments, your declaration has how many?
 
William Roeder:
  1. You were asked in #1. Again: 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. Your call has two arguments, your declaration has how many?

I will try to check all code. As I tried to introduce code to fit the SL and TP, Trades and Money I must have made a mess but I was too tired to realize. Thanks for making me able to realize about it. 

 
William Roeder:
  1. You were asked in #1. Again: 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. Your call has two arguments, your declaration has how many?

Do you know a good way to filter values providing Error 3, 130, 131, 148 since the start of the Script?

3

ERR_INVALID_TRADE_PARAMETERS

Invalid trade parameters

130

ERR_INVALID_STOPS

Invalid stops

131

ERR_INVALID_TRADE_VOLUME

Invalid trade volume

148

ERR_TRADE_TOO_MANY_ORDERS

The amount of open and pending orders has reached the limit set by the broker


I am constantly stuck on those errors and I keep adding code, making it look like a trash code without any good result. 

 
//--- Inputs
extern bool    Auto_Lot        = TRUE;     // Money Management
extern double  Risk_Multiplier = 1;        // Risk
extern double  Lots            = 0.1;      // Starting Lots
extern double  MaxLot          = 10;       // Maximum Lot
extern double  KLot            = 1;        // Increasing Lot
extern double  KStep           = 1;        // Increasing Step
extern double  Loss            = 4500;     // Balance Loss
extern double  Profit          = 50;       // Balance Profit

extern int     StopLoss        = 0;        // Stop Loss
extern int     TakeProfit      = 0;        // Take Profit
extern int     BULevel         = 0;        // BULevel
extern int     BUPoint         = 30;       // BUPoint
extern int     TrailingStop    = 0;        // Trailing
extern int     Step            = 100;      // Step
extern int     Delta           = 100;      // Delta
extern int     Count           = 5;        // Orders Count
extern int     Slip            = 3;        // Slippage
extern int     Exp             = 1111;     // Expiration Minutes
extern int     Magic           = 123;      // Magic Number

extern bool    BuyLimit        = 1;        // Buy Limit
extern bool    SellLimit       = 1;        // Sell Limit
extern bool    BuyStop         = 0;        // Buy Stop
extern bool    SellStop        = 0;        // Sell Stop

extern bool    GTrail          = 1;        // Grid Trailing True-ON False-OFF

//+------------------------------------------------------------------+
//|                                   				     |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                               				     |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,double lot)
  {
   int r=0;
   color clr=Green;
   double sl=0,tp=0;

   if(type==1 || type==3 || type==5)
     {
      clr=Red;
      if(StopLoss>0)
         sl=NormalizeDouble(price+StopLoss*Point,Digits);
      if(TakeProfit>0)
         tp=NormalizeDouble(price-TakeProfit*Point,Digits);
     }

   if(type==0 || type==2 || type==4)
     {
      clr=Blue;
      if(StopLoss>0)
         sl=NormalizeDouble(price-StopLoss*Point,Digits);
      if(TakeProfit>0)
         tp=NormalizeDouble(price+TakeProfit*Point,Digits);
     }

   r=OrderSend(NULL,type,lot,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Exp*60,clr);
  }
//+------------------------------------------------------------------+
//|                                   			             |
//+------------------------------------------------------------------+
int CountOrders(int type=-1)
  {
   int count=0;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==type || (OrderType()>=0 && type==-1))
               count++;
           }
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Lot(int type)
  {
   double lots=Lots;
   if(Auto_Lot=TRUE)
      Lots=((AccountBalance()*Risk_Multiplier)/100)/1000;

   double MaximumLot=MarketInfo(NULL,MODE_MAXLOT);
   double MinimumLot=MarketInfo(NULL,MODE_MINLOT);

   if(KLot>0)
      lots=NormalizeDouble(Lots*(CountOrders(type)+1),2);
   if(lots>MaximumLot)
      lots=MaximumLot;
   if(lots<MinimumLot)
      lots=MinimumLot;
   return(lots);
  }
//+------------------------------------------------------------------+
//|                                                 		     |
//+------------------------------------------------------------------+
double Steps(int ot)
  {
   double step=Step;
   step=NormalizeDouble(Step*MathPow(KStep,CountOrders(ot)),2);
   return(step);
  }
//+------------------------------------------------------------------+
//|                                				     |
//+------------------------------------------------------------------+
double AllProfit(int ot=-1)
  {
   double pr=0;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==0 && (ot==0 || ot==-1))
              {
               pr+=OrderProfit()+OrderCommission()+OrderSwap();
              }

            if(OrderType()==1 && (ot==1 || ot==-1))
              {
               pr+=OrderProfit()+OrderCommission()+OrderSwap();
              }
           }
        }
     }
   return(pr);
  }
//+------------------------------------------------------------------+
//|                               				     |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
  {
   bool cl;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==0 && (ot==0 || ot==-1))
              {
               RefreshRates();
               cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
              }
            if(OrderType()==1 && (ot==1 || ot==-1))
              {
               RefreshRates();
               cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                				     |
//+------------------------------------------------------------------+
void DelOrder(int type=-1)
  {
   bool del;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==type || type==-1)
               del=OrderDelete(OrderTicket());
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Trailing()
  {
   bool mod;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY)
              {
               if(Bid-OrderOpenPrice()>TrailingStop*Point)
                 {
                  if(OrderStopLoss()<Bid-TrailingStop*Point)
                    {
                     mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Yellow);
                     return;
                    }
                 }
              }

            if(OrderType()==OP_SELL)
              {
               if((OrderOpenPrice()-Ask)>TrailingStop*Point)
                 {
                  if((OrderStopLoss()>(Ask+TrailingStop*Point)) || (OrderStopLoss()==0))
                    {
                     mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
                     return;
                    }
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void BU()
  {
   bool m;
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY)
              {
               if(OrderOpenPrice()<=(Bid-(BULevel+BUPoint)*Point) && OrderOpenPrice()>OrderStopLoss())
                 {
                  m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+BUPoint*Point,OrderTakeProfit(),0,Yellow);
                  return;
                 }
              }

            if(OrderType()==OP_SELL)
              {
               if(OrderOpenPrice()>=(Ask+(BULevel+BUPoint)*Point) && (OrderOpenPrice()<OrderStopLoss() || OrderStopLoss()==0))
                 {
                  m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Yellow);
                  return;
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void GridTrailing(int type,int step)
  {
   bool mod;
   double oop=0,sl=0,tp=0;

   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if((OrderType()==2 && type==2) || (OrderType()==5 && type==5))
              {
               oop=NormalizeDouble(OrderOpenPrice()+step*Point,Digits);
               if(OrderType()==2 && StopLoss>0)
                 {
                  sl=NormalizeDouble(oop-StopLoss*Point,Digits);
                 }
               if(OrderType()==5 && StopLoss>0)
                 {
                  sl=NormalizeDouble(oop+StopLoss*Point,Digits);
                 }
               if(OrderType()==2 && TakeProfit>0)
                 {
                  tp=NormalizeDouble(oop+TakeProfit*Point,Digits);
                 }
               if(OrderType()==5 && TakeProfit>0)
                 {
                  tp=NormalizeDouble(oop-TakeProfit*Point,Digits);
                 }

               mod=OrderModify(OrderTicket(),oop,sl,tp,OrderExpiration(),Lime);
              }

            if((OrderType()==3 && type==3) || (OrderType()==4 && type==4))
              {
               oop=NormalizeDouble(OrderOpenPrice()-step*Point,Digits);
               if(OrderType()==3 && StopLoss>0)
                 {
                  sl=NormalizeDouble(oop+StopLoss*Point,Digits);
                 }
               if(OrderType()==4 && StopLoss>0)
                 {
                  sl=NormalizeDouble(oop-StopLoss*Point,Digits);
                 }
               if(OrderType()==3 && TakeProfit>0)
                 {
                  tp=NormalizeDouble(oop-TakeProfit*Point,Digits);
                 }
               if(OrderType()==4 && TakeProfit>0)
                 {
                  tp=NormalizeDouble(oop+TakeProfit*Point,Digits);
                 }

               mod=OrderModify(OrderTicket(),oop,sl,tp,OrderExpiration(),Lime);
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double hiPrice()
  {
   double pr=0,oldpr=0,newpr=0;

   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==2 || OrderType()==5)
              {
               newpr=OrderOpenPrice();
               if(newpr>oldpr)
                 {
                  pr=OrderOpenPrice();
                  oldpr=newpr;
                 }
              }
           }
        }
     }
   return(pr);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double loPrice()
  {
   double pr=0,oldpr=1111,newpr=0;

   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==3 || OrderType()==4)
              {
               newpr=OrderOpenPrice();
               if(newpr<oldpr)
                 {
                  pr=OrderOpenPrice();
                  oldpr=newpr;
                 }
              }
           }
        }
     }
   return(pr);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double OrderDist(int type)
  {
   double dist=0;

   if(type==2 || type==5)
     {
      if(Bid-hiPrice()>Delta*Point)
        {
         dist=(Bid-hiPrice()-Delta*Point)/_Point;
        }
     }

   if(type==3 || type==4)
     {
      if(loPrice()-Bid>Delta*Point)
        {
         dist=(loPrice()-Bid-Delta*Point)/_Point;
        }
     }

   return(dist);
  }
//+------------------------------------------------------------------+
//| 			                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(CountOrders(2)<1 && BuyLimit)
      for(int i=0; i<Count; i++)
         PutOrder(2,Bid-Delta*Point-Steps(2)*Point*i,Lot(2));//buylimit
   if(CountOrders(3)<1 && SellLimit)
      for(int i=0; i<Count; i++)
         PutOrder(3,Bid+Delta*Point+Steps(3)*Point*i,Lot(3));//selllimit
   if(CountOrders(4)<1 && BuyStop)
      for(int i=0; i<Count; i++)
         PutOrder(4,Bid+Delta*Point+Steps(4)*Point*i,Lot(4));//buystop
   if(CountOrders(5)<1 && SellStop)
      for(int i=0; i<Count; i++)
         PutOrder(5,Bid-Delta*Point-Steps(5)*Point*i,Lot(5));//sellstop

   if((Profit>0 && AllProfit()>Profit) || (Loss>0 && AllProfit()<-Loss))
     {
      CloseAll();
      DelOrder();
     }

   if(GTrail)
     {
      if(OrderDist(2)>Delta)
         GridTrailing(2,(int)OrderDist(2));
      if(OrderDist(3)>Delta)
         GridTrailing(3,(int)OrderDist(3));
      if(OrderDist(4)>Delta)
         GridTrailing(4,(int)OrderDist(4));
      if(OrderDist(5)>Delta)
         GridTrailing(5,(int)OrderDist(5));
     }

   if(BULevel>0)
      BU();
   if(TrailingStop>0)
      Trailing();

   Comment(");
  }
//+------------------------------------------------------------------+

I am not able to implement a filter for those errors. I am copying the code without the corrections. Can anybody help me? 

 
Yajaira Thibisay Martinez Jaimes:

Do not double post!

I have deleted your post in another topic.

 
Keith Watford:

Do not double post!

I have deleted your post in another topic.


Ok. I am just looking for help. Sorry

Reason: