Wrong parameters count!

 

I've been working on this for a while today and I just can't find my mistake!


I modified an existing script that exports MT4 data and changed it a little. I added more pairs and removed the moving average export functionality.


Now I'm getting an error stating the parameter count is wrong. I've compared the original and my mod side to side for hours now and I think I just need another pair of eyes to look at it.


Any help is greatly appreciated. I attached both the original and my modification.


Thank you!!


R

 

Doesn't look like you are handling arrays properly. array_price[][6] has 6 elements in the second dimension which are numbered from 0 to 5.


You are not referencing the second dimension in the right order as well as referencing a non-existent element 6.


EURGBP_OPEN = array_price70[1][2];
EURGBP_CLOSE = array_price71[1][3];
EURGBP_HIGH = array_price72[1][4];
EURGBP_LOW = array_price73[1][5];
EURGBP_Volume = array_price74[1][6];


The correct order should be 0-5, and no number 6:


0 - time,
1 - open,
2 - low,
3 - high,
4 - close,
5 - volume.


Can't tell if this is related to the error you are seeing, but this is something you need to fix.

 
blogzr3:

Doesn't look like you are handling arrays properly. array_price[][6] has 6 elements in the second dimension which are numbered from 0 to 5.


You are not referencing the second dimension in the right order as well as referencing a non-existent element 6.


EURGBP_OPEN = array_price70[1][2];
EURGBP_CLOSE = array_price71[1][3];
EURGBP_HIGH = array_price72[1][4];
EURGBP_LOW = array_price73[1][5];
EURGBP_Volume = array_price74[1][6];


The correct order should be 0-5, and no number 6:


0 - time,
1 - open,
2 - low,
3 - high,
4 - close,
5 - volume.


Can't tell if this is related to the error you are seeing, but this is something you need to fix.

Thank you, Blogzr. The first script was created for use in conjunction with the DDE FX Multi-Fib Calculator (http://stideas.com/Free%20Trading%20Tools.htm). It wasn't working correctly for me in either OOo or Excel so I tried to take the format and create my own, much more simple version from the provided. I'm going to revise the existing code and... arrays notwithstanding, it looks like the error I keep getting is related to the fileWrite command at the very end. I cant, for the life of me, figure out what I'm doing wrong.


I'm going to go ahead and revise the array assignments and let you know the result.


Thank you many times, blogzr3...


R

 

Also you don't need multiple arrays in array_price70, 71, 72 etc - you only need one for each symbol/timeframe combination.


If fact, for what you are doing, you don't need arrays at all - just reference iOpen(), iClose() etc directly.


The compilation errors are most likely red-herrings :)

 
blogzr3:

Also you don't need multiple arrays in array_price70, 71, 72 etc - you only need one for each symbol/timeframe combination.


If fact, for what you are doing, you don't need arrays at all - just reference iOpen(), iClose() etc directly.


The compilation errors are most likely red-herrings :)


I had a sneaking suspicion that was the case...


I'll give it a shot. And thanks again.


For what it's worth, here's the new one with the updated arrays.


R

Files:
 
ra457:

I had a sneaking suspicion that was the case...


I'll give it a shot. And thanks again.


For what it's worth, here's the new one with the updated arrays.


R

Alright. I removed all the array-related commands and I believe it's all coded correctly. I'm still getting an invalid parameter error at the very end!! Maybe there's something wrong with the filewrite command?!


Help!

Files:
wexportg.mq4  10 kb
 
ra457:

Alright. I removed all the array-related commands and I believe it's all coded correctly. I'm still getting an invalid parameter error at the very end!! Maybe there's something wrong with the filewrite command?!


Help!

I solved this a while back. Each filewrite command can only use 63 parameters. I was using about 100 so I had to split it into two different filewrite commands


Thanks again for your help!


R

 
/+------------------------------------------------------------------+
//|                                                       manual.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "http://fx-strategist.com"
#property link      "http://fx-strategist.com"


extern string _EA                            = "_________SMART TRADE___________";
//extern int    StopLoss                       = 50;
extern int    TakeProfit                     = 20;
extern double Multiplier                     = 2;


 

int    Magic                          = 0;
int    Trailing_Stop                  = 0;
double MinLots, MaxLots, minlot, TPBuy, SLBuy;
int    DIGIT, convert, slippage=10, spread, stoplevel;
double last_lot_sell, last_price_sell, last_lot_buy, last_price_buy, last_price, last_lot;
int    last_type, pending, OpenOrders, cnt, openbuy, opensell;
bool   CLOSE, DELETE;
datetime time;
double Lot_Marti;
//double SL;
double harga;
double last_tp_buy;
double last_tp_sell;
string status;
bool sudahbuka;


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
if (!IsExpertEnabled()) {Alert ("EA BELUM AKTIF, KLIK TOMBOL AKTIVASI EA");}
if (!IsTradeAllowed())  {Alert ("EA BELUM AKTIF, CENTANG PADA ALLOW LIVE TRADING");}

minlot =MarketInfo(Symbol(),MODE_MINLOT);
if (minlot/0.01==1) {DIGIT=2;} else {DIGIT=1;}
if (MarketInfo (Symbol(), MODE_LOTSTEP)*10<1)  {DIGIT=2;} else {DIGIT=1;}
if (Digits==5 ||Digits==3 || Symbol()=="GOLD" || Symbol()=="GOLD." || Symbol()=="GOLDm") {convert=10; slippage=100;} else {convert=1;}

stoplevel=NormalizeDouble(MarketInfo(Symbol(),MODE_STOPLEVEL),2);
spread = NormalizeDouble(MarketInfo(Symbol(),MODE_SPREAD),2);
if (Trailing_Stop*convert<stoplevel+spread && Trailing_Stop!=0) {Trailing_Stop=(stoplevel+spread)/convert;}
//if (StopLoss*convert<stoplevel+spread && StopLoss!=0) {StopLoss=(stoplevel+spread)/convert;}
if (TakeProfit*convert<stoplevel+spread && TakeProfit!=0) {TakeProfit=(stoplevel+spread)/convert;} 


ModifyTP(TakeProfit);
//ModifySL(StopLoss);
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {

minlot =MarketInfo(Symbol(),MODE_MINLOT);
if (minlot/0.01==1) {DIGIT=2;} else {DIGIT=1;}
if (MarketInfo (Symbol(), MODE_LOTSTEP)*10<1)  {DIGIT=2;} else {DIGIT=1;}
if (Digits==5 ||Digits==3 || Symbol()=="GOLD" || Symbol()=="GOLD." || Symbol()=="GOLDm") {convert=10; slippage=100;} else {convert=1;}

stoplevel=NormalizeDouble(MarketInfo(Symbol(),MODE_STOPLEVEL),2);
spread = NormalizeDouble(MarketInfo(Symbol(),MODE_SPREAD),2);
if (Trailing_Stop*convert<stoplevel+spread && Trailing_Stop!=0) {Trailing_Stop=(stoplevel+spread)/convert;}
//if (StopLoss*convert<stoplevel+spread && StopLoss!=0) {StopLoss=(stoplevel+spread)/convert;}
if (TakeProfit*convert<stoplevel+spread && TakeProfit!=0) {TakeProfit=(stoplevel+spread)/convert;} 


openord();
if (OpenOrders==0 && pending>0) {CloseAll("hedge", 4); CloseAll("hedge",5); ObjectsDeleteAll();}
if (OpenOrders==1 && pending>0) {CloseAll("smart", 4); CloseAll("smart",5); CloseAll("smart", 2); CloseAll("smart",3);ObjectsDeleteAll();}
 
  
//+------------------------------------------------------------------+
//| OPEN MARTINGALE HYBRID                                           |
//+------------------------------------------------------------------+
openord();
if (OpenOrders>0 && pending==0)
   {
      Lot_Marti = NormalizeDouble (last_lot * Multiplier, DIGIT);
     
      harga = last_price-TakeProfit*convert*Point;
      if (last_type==OP_BUY && Ask-harga>stoplevel*Point)
         {
            if (OPEN (Symbol(), OP_SELLSTOP, Red, Lot_Marti, slippage, harga, false,  TakeProfit, "hedge", Magic))
               {time=iTime (Symbol(),0,0);}
         }
         
      harga = last_price+TakeProfit*convert*Point;   
      if (last_type==OP_SELL && harga-Bid>stoplevel*Point)
         {
            if (OPEN (Symbol(), OP_BUYSTOP, Blue, Lot_Marti, slippage, harga, false,  TakeProfit, "hedge", Magic))
               {time=iTime (Symbol(),0,0);}
         }
   }

openord();
if (OpenOrders>0 || pending>0) {status="EA AKTIF";} else {status="EA TIDAK AKTIF";} 

  
if (GetLastError()==134) {Alert ("BALANCE TIDAK CUKUP UNTUK MEMBUKA ORDER"); return (0);}  

ModifyTP(TakeProfit);
//ModifySL(StopLoss);

   return(0);
  }
//+------------------------------------------------------------------+

void ModifyTP(double TP) // TP disini diambil dari OrderTakeProfit() dari OP terakhir
{
for (cnt = OrdersTotal(); cnt >= 0; cnt--)
    {
      if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)==true)
      if (OrderComment()=="smart" && OrderSymbol() == Symbol() && OrderMagicNumber()==Magic && (OrderType()==OP_BUY || OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT ) ) continue;
         {
           if (NormalizeDouble (OrderTakeProfit(),Digits)!=NormalizeDouble (OrderOpenPrice()+TP*convert*Point,Digits))
              {
                OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), NormalizeDouble (OrderOpenPrice()+TP*convert*Point,Digits), 0, CLR_NONE);
              }
         }
      if (OrderComment()=="smart" && OrderSymbol() == Symbol() && OrderMagicNumber()==Magic && (OrderType()==OP_SELL ||OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT) )
         {
           if (NormalizeDouble (OrderTakeProfit(),Digits)!=NormalizeDouble (OrderOpenPrice()-TP*convert*Point,Digits))
              {
                OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), NormalizeDouble (OrderOpenPrice()-TP*convert*Point,Digits), 0, CLR_NONE);
              }
         }  
     }
}   


void ModifySL(double SL) // TP disini diambil dari OrderTakeProfit() dari OP terakhir
{
for (cnt = OrdersTotal(); cnt >= 0; cnt--)
    {
     if( OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      if (OrderComment()=="smart" && OrderSymbol() == Symbol() && OrderMagicNumber()==Magic && (OrderType()==OP_BUY || OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT ) )continue;
         {
          
           if (NormalizeDouble (OrderStopLoss(),Digits)!=NormalizeDouble (OrderOpenPrice()-SL*convert*Point,Digits))
              {
               
                OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble (OrderOpenPrice()-SL*convert*Point,Digits), OrderTakeProfit() , 0, CLR_NONE);
              }
         }
      if (OrderComment()=="smart" && OrderSymbol() == Symbol() && OrderMagicNumber()==Magic && (OrderType()==OP_SELL ||OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT) )
         {
           if (NormalizeDouble (OrderStopLoss(),Digits)!=NormalizeDouble (OrderOpenPrice()+SL*convert*Point,Digits))
              { 
                OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble (OrderOpenPrice()+SL*convert*Point,Digits), OrderTakeProfit() , 0, CLR_NONE);
              }
         }  
     }
}  




void komentar (int baris, string label1, string label2)
{
if (!IsTradeAllowed() || !IsExpertEnabled()) {ObjectDelete("baris0"); return (0);}
int x,y;
switch(baris)
      {
         case 1: x=40; y=60;   break; 
         case 2: x=40; y=75;   break;
         case 3: x=40; y=90;   break;
         case 4: x=40; y=105;   break;
         case 5: x=40; y=120;   break;
         case 6: x=40; y=135;   break;
         case 7: x=40; y=150;   break;
         case 8: x=40; y=165;   break;
         case 9: x=40; y=180;   break;
         case 10: x=40; y=195;   break;
         case 11: x=40; y=210;   break;
         case 12: x=40; y=225;   break;
         case 13: x=40; y=240;   break;
         case 14: x=40; y=255;   break;
         case 15: x=40; y=270;   break;
         case 16: x=40; y=285;   break;
         case 17: x=40; y=300;   break;
      }
Monitor("baris0", WindowExpertName()+ " IS RUNNING", 10, 40, 20, Yellow,0);
Monitor("baris00", "Jasa Pembuatan Expert Advisor http://eCandleStick.com", 8, 40, 10, Yellow,2);
Monitor("baris"+baris, label1, 8, x, y, Yellow,0);
Monitor("baris_"+baris, ":", 8, x+150, y, Yellow,0);
Monitor("baris-"+baris, label2, 8, x+160, y, Yellow,0);
}



void Monitor(string nama, string isi, int ukuran, int x, int y, color warna, int pojok)
{
  if (ObjectFind(nama)<0) {ObjectCreate  (nama,OBJ_LABEL,0,0,0,0,0);}
  ObjectSet     (nama,OBJPROP_CORNER,pojok);
  ObjectSet     (nama,OBJPROP_XDISTANCE,x);
  ObjectSet     (nama,OBJPROP_YDISTANCE,y);
  ObjectSetText (nama,isi,ukuran,"Tahoma",warna);
}




bool OPEN (string symbol, int tipe, color warna, double Lots, double slippage, double harga, bool hidden_mode, double StopLoss, double TakeProfit, string komen, int Magic  )
{
     double TP, SL;
     int ticket=0;
     MinLots = NormalizeDouble((MarketInfo(Symbol(), MODE_MINLOT)),DIGIT);
MaxLots = NormalizeDouble((MarketInfo(Symbol(), MODE_MAXLOT)),DIGIT);
if(Lots<MinLots){Lots=MinLots;}
if(Lots>MaxLots){Lots=MaxLots;}
Lots = NormalizeDouble (Lots,DIGIT);
     //while (ticket<=0)
     //      {
             RefreshRates();
             stoplevel=NormalizeDouble(MarketInfo(Symbol(),MODE_STOPLEVEL),0);
             spread = NormalizeDouble(MarketInfo(Symbol(),MODE_SPREAD),0);
             if (tipe==OP_BUY || tipe==OP_BUYLIMIT || tipe==OP_BUYSTOP)
                {
                  if (TakeProfit*convert>=stoplevel && !hidden_mode)            {TP=harga+TakeProfit*convert*Point;} else {TP=0;}
                  if (StopLoss*convert>=stoplevel+spread && !hidden_mode)       {SL=harga-StopLoss*convert*Point;}   else {SL=0;}
                }
               
             if (tipe==OP_SELL || tipe==OP_SELLLIMIT || tipe==OP_SELLSTOP)
                {
                  if (TakeProfit*convert>=stoplevel && !hidden_mode)         {TP=harga-TakeProfit*convert*Point;} else {TP=0;}
                  if (StopLoss*convert>=stoplevel+spread && !hidden_mode)    {SL=harga+StopLoss*convert*Point;}   else {SL=0;}
                }
               
             ticket = OrderSend(symbol,tipe,Lots,harga,slippage,SL,TP,komen,Magic,0,warna);
             if (ticket<=0) {Sleep(1000);} else {return (true);}
     //      }
    
}




void openord()
{
OpenOrders=0; openbuy=0; opensell=0; pending=0;
for(cnt=0;cnt<OrdersTotal();cnt++)  
   {
     if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      if (OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic || OrderComment()=="smart") && (OrderType()==OP_BUY ||OrderType()==OP_SELL))
         {
           OpenOrders++;
           last_price = OrderOpenPrice();
           last_lot   = OrderLots();
           last_type  = OrderType();
         }
    
     if (OrderSymbol()==Symbol()  && (OrderMagicNumber() == Magic || OrderComment()=="smart") && (OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT))
         {pending++;}
    
      if (OrderSymbol()==Symbol()  && (OrderMagicNumber() == Magic || OrderComment()=="smart") && OrderType()==OP_BUY)
         {
            openbuy++;
            last_price_buy = OrderOpenPrice();
            last_lot_buy   = OrderLots();
            last_tp_buy    = OrderTakeProfit();
           
         }
      if (OrderSymbol()==Symbol()  && (OrderMagicNumber() == Magic || OrderComment()=="smart") && OrderType()==OP_SELL)
         {
            opensell++;
            last_price_sell = OrderOpenPrice();
            last_lot_sell   = OrderLots();
            last_tp_sell    = OrderTakeProfit();
         }
   }
}



// BUY = 0
// SELL = 1
// BUYLIMIT=2
// SELLIMIT=3
// BUYSTOP = 4
// SELLSTOP = 5
void CloseAll(string komen, int tipe)
{
    CLOSE=false;
    DELETE=false;
    for(cnt=OrdersTotal();cnt>=0;cnt--)
       {
         if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
          if (OrderComment()==komen && OrderSymbol()==Symbol() && OrderMagicNumber() == Magic)
             {
               if (OrderType()==OP_BUY && (tipe==0 || tipe==7))
                  {
                   
                    int retry=0;
                    while (CLOSE==false)
                            {
                             RefreshRates();
                             CLOSE = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Blue);
                            if (CLOSE==false) {Sleep(1000); retry++;}
                             if (GetLastError()==4108 || GetLastError()==145) {CLOSE=true;}
                            }
                      CLOSE=false;
                  }
               if (OrderType()==OP_SELL && (tipe==1 || tipe==7))
                  {
                   
                    retry=0;
                    while (CLOSE==false)
                            {
                              RefreshRates();
                              CLOSE = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Red);
                              if (CLOSE==false) {Sleep(1000); retry++;}
                              if (GetLastError()==4108 || GetLastError()==145) {CLOSE=true;}
                            }
                      CLOSE=false;
                  }
                    
              }
        }
     for(cnt=OrdersTotal();cnt>=0;cnt--)
       {
         if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
          if (OrderComment()==komen && OrderSymbol()==Symbol() && OrderMagicNumber() == Magic)
             {
              
               if (OrderType()==OP_BUYLIMIT && (tipe==2 || tipe==7))
                  {
                   
                    retry=0;
                    while (DELETE==false)
                           {
                             RefreshRates();
                             DELETE = OrderDelete(OrderTicket());
                             if (DELETE==false) {Sleep(1000); retry++;}
                             if (GetLastError()==4108 || GetLastError()==145) {DELETE=true;}
                           }
                      DELETE=false;
                  }
               if (OrderType()==OP_SELLLIMIT && (tipe==3 || tipe==7))
                  {
                    retry=0;
                    while (DELETE==false)
                           {
                             RefreshRates();
                             DELETE = OrderDelete(OrderTicket());
                             if (DELETE==false) {Sleep(1000); retry++;}
                             if (GetLastError()==4108 || GetLastError()==145) {DELETE=true;}
                           }
                      DELETE=false;
                  }
               if (OrderType()==OP_BUYSTOP && (tipe==4 || tipe==7))
                  {
                    retry=0;
                    while (DELETE==false)
                           {
                             RefreshRates();
                             DELETE = OrderDelete(OrderTicket());
                             if (DELETE==false) {Sleep(1000); retry++;}
                             if (GetLastError()==4108 || GetLastError()==145) {DELETE=true;}
                           }
                      DELETE=false;
                  } 
               if (OrderType()==OP_SELLSTOP && (tipe==5 || tipe==7))
                  {
                    retry=0;
                    while (DELETE==false)
                           {
                             RefreshRates();
                             DELETE = OrderDelete(OrderTicket());
                             if (DELETE==false) {Sleep(1000); retry++;}
                             if (GetLastError()==4108 || GetLastError()==145) {DELETE=true;}
                           }
                      DELETE=false;
                  }                   
              }
        }
}
 
euricks008:
/+------------------------------------------------------------------+
//|                                                       manual.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |

Don't paste code
Play video
Please edit your post.
For large amounts of code, attach it.
 
Hello, I would like a little help so I'm creating a little robot and I put an order to be giving error
 
Please post in English in the forum
Reason: