Errors, bugs, questions - page 256

 

Please tell me how to declare a 2-dimensional dynamic array. There is only an example with one dynamic dimension in the help for this:

double matrix[][10][20];// 3-dimensional dynamic array

ArrayResize(matrix,5);// set the size of the first dimension


And the declaration:

double matrix[][];

does not work, the compiler writes: ']' - invalid index value

 

Help, I can't understand what he doesn't like... he keeps writing 10016 (like a stop loss is not set correctly) Thank you

#property version   "1.00"
//+------------------------------------------------------------------+
#define MAGIC_NUMBER 12937
input double BASELOT=0.5;
input double stoploss=0.0;
input double takeprofit=0.0;
//+------------------------------------------------------------------+
int OnInit()
  {
   int send;
   int signalMA=signalMA();
   if(signalMA==1)
     {
      send=1;
      Send(send);
        } else if(signalMA==2) {
      send=2;
      Send(send);
     }
   return(0);
  }
//+------------------------------------------------------------------+
int signalMA() 
  {
   int signalMA=0;
   double inMA6 = iMA(NULL,0,6,0,MODE_SMA,0);
   double inMA1 = iMA(NULL,0,1,0,MODE_SMA,0);
   if(inMA6>inMA1)
     {
      signalMA=1;
     }
   if(inMA6<inMA1)
     {
      signalMA=2;
     }
   return(signalMA);
  }
//+------------------------------------------------------------------+
void Send(int send)
  {
   MqlTick tick;
   MqlTradeRequest request;
   MqlTradeResult tradeResult;
   MqlTradeCheckResult checkResult;
   static bool br=false;
   if(!br) 
     {
      if(send==1) 
        {
         br=true;
         request.price=tick.bid;
         request.sl = stoploss;
         request.tp = takeprofit;
         request.type=ORDER_TYPE_SELL;
           } else if(send==2){
         br=true;
         request.price=tick.ask;
         request.sl = stoploss;
         request.tp = takeprofit;
         request.type=ORDER_TYPE_BUY;
        }
      if(br) 
        {
         request.action       = TRADE_ACTION_DEAL;
         request.symbol       = _Symbol;
         request.volume       = BASELOT;
         request.deviation    = 5;
         request.type_filling = ORDER_FILLING_AON;
         request.type_time    = ORDER_TIME_GTC;
         request.comment      = "";
         request.magic        = MAGIC_NUMBER;
         if(OrderCheck(request,checkResult)) 
           {
            OrderSend(request,tradeResult);
              } else {
            Print("Error: ",checkResult.retcode);
           }
        }
     }
  }
//+------------------------------------------------------------------+
 
tmt0086:

Help, I can not understand what he does not like ... keeps writing 10016 (like stop loss is not set correctly) Thank you

First of all, you have this function written incorrectly.

int signalMA() 
  {
   int signalMA=0;
   double inMA6 = iMA(NULL,0,6,0,MODE_SMA,0);
   double inMA1 = iMA(NULL,0,1,0,MODE_SMA,0);
   if(inMA6>inMA1)
     {
      signalMA=1;
     }
   if(inMA6<inMA1)
     {
      signalMA=2;
     }
   return(signalMA);
  }

It should be like this. I can't tell you about the stop error.


//+------------------------------------------------------------------+
#define MAGIC_NUMBER 12937
input double BASELOT=0.5;
input double stoploss=0.0;
input double takeprofit=0.0;

int handleMA1=INVALID_HANDLE;
int handleMA2=INVALID_HANDLE;

double inMA6[];
double inMA1[];

MqlTick tick;
MqlTradeRequest request;
MqlTradeResult tradeResult;
MqlTradeCheckResult checkResult;
//+------------------------------------------------------------------+
int OnInit()
  {
   handleMA1=iMA(NULL,0,6,0,MODE_SMA,0);
   handleMA2= iMA(NULL,0,1,0,MODE_SMA,0);

   int send;
   int signalMA=signalMA();
   if(signalMA==1)
     {
      send=1;
      Send(send);
        } else if(signalMA==2) {
      send=2;
      Send(send);
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int signalMA()
  {
   int sig=0;
   if(handleMA1==INVALID_HANDLE)
     {
      handleMA1=iMA(NULL,0,6,0,MODE_SMA,0);
      return(0);
     }
   if(handleMA2==INVALID_HANDLE)
     {
      handleMA2=iMA(NULL,0,1,0,MODE_SMA,0);
      return(0);
     }
   if(CopyBuffer(handleMA1,0,0,1,inMA6)<1) return(0);
   if(CopyBuffer(handleMA2,0,0,1,inMA1)<1) return(0);
   if(!ArraySetAsSeries(inMA6,true)) return(0);
   if(!ArraySetAsSeries(inMA1,true)) return(0);

   if(inMA6[0]>inMA1[0]) sig=1;
   else if(inMA6[0]<inMA1[0]) sig=2;
   else sig=0;
   return(sig);
  }
//+------------------------------------------------------------------+
void Send(int send)
  {
   static bool br=false;
   if(!br)
     {
      if(send==1)
        {
         br=true;
         request.price=tick.bid;
         request.sl = stoploss;
         request.tp = takeprofit;
         request.type=ORDER_TYPE_SELL;
           } else if(send==2){
         br=true;
         request.price=tick.ask;
         request.sl = stoploss;
         request.tp = takeprofit;
         request.type=ORDER_TYPE_BUY;
        }
      if(br)
        {
         request.action       = TRADE_ACTION_DEAL;
         request.symbol       = _Symbol;
         request.volume       = BASELOT;
         request.deviation    = 5;
         request.type_filling = ORDER_FILLING_AON;
         request.type_time    = ORDER_TIME_GTC;
         request.comment      = "";
         request.magic        = MAGIC_NUMBER;
         if(OrderCheck(request,checkResult))
           {
            OrderSend(request,tradeResult);
              } else {
            Print("Error: ",checkResult.retcode);
           }
        }
     }
  }
//+------------------------------------------------------------------+
 
-Alexey-:

Please tell me how to declare a 2-dimensional dynamic array. There is only an example with one dynamic dimension in the help for this:

double matrix[][10][20];// 3-dimensional dynamic array

ArrayResize(matrix,5);// set the size of the first dimension


And the declaration:

double matrix[][];

does not work, compiler writes: ']' - invalid index value

In MQL5 there is only one dynamic dimension.

To use more than one dimension you can use structures

struct SDynamic
  {
   double            data[];
  };

...

SDynamic Arr2D[];

...

bool Arr2DResize(SDynamic &a2d[],int d1,int d2)
  {
   if(ArrayResize(a2d,d1)!=d1) return(false);
   for(int i=0;i<d1;i++)
      if(ArrayResize(a2d[i].data,d2)!=d2) return(false);
   return(true);
  }

...

Arr2DResize(Arr2D,10,10);

...

Print(Arr2D[0].data[3]);
 
mql5:

There is only one dynamic dimension in MQL5.

to use more than one, you can use structures

Dear mql5, thank you for your help, explanations and practical example.
 

Should have gone to a neighbouring forum, but there's a problem with the pictures (it didn't work to upload them)... :(


To the developers.

From the MT4 229 report. Is this a bug or what?


 
Interesting:

Should have gone to a neighbouring forum, but there's a problem with the cortinas (it didn't work to upload them)... :(



The picture, as I understand it, is given.

Need the browser version.

 
alexvd:

A picture, as I understand it, is given.

I need the browser version.

I tried to put the picture in Png and Gif format (I also tried to put it as Jpg, using radikal.ru service).

Browser Firefox 3.6.13.

PS

I tried to put it in this thread - New version of MetaTrader 4 Client Terminal build 228

What is strange Png seems to be present there.

Новая версия MetaTrader 4 Client Terminal build 228 - MQL4 форум
  • www.mql5.com
Новая версия MetaTrader 4 Client Terminal build 228 - MQL4 форум
 
Interesting:

Developers.

From the MT4 229 report. Is this a bug or what?



Doesn't seem to be.

It turns out that there were only 2 (out of 45) losing trades, and both of them were buying.

Maybe I am looking in the wrong place?

 
Interesting:

I tried to put the picture in Png and Gif format (I also tried to put it as Jpg, using radikal.ru).

Firefox 3.6.13 browser.

PS

I tried to insert it into this thread - New version MetaTrader 4 Client Terminal build 228

What is strange Png seems to be present there.

Try cleaning cache. I tried different options, different browsers - adding was successful.

You do paste the image directly in the comments, not as an atach?

Reason: