icustom mql5 returns wrog values

 

Hi, I am trying to use iCustom and I get wrong results can anybudy help me . thanks.






//+------------------------------------------------------------------+
//|                                                      TempExp.mq5 |
//|                             Gh.Hossein Eslamizadeh-98-9350506784 |
//|                                        https://www.ForexStore.ir |
//+------------------------------------------------------------------+
#property copyright "Gh.Hossein Eslamizadeh-98-9350506784"
#property link      "https://www.ForexStore.ir"
#property version   "1.00"




double zzBuffer[];
int limit=300;
//--- input parameters
input int MA_Period=21;
input int MA_Shift=0;
input ENUM_MA_METHOD MA_Method=MODE_SMA;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
ENUM_TIMEFRAMES eTF=PERIOD_CURRENT;
   ResetLastError();
   /*MaHandle=iCustom(NULL,eTF,"Examples\\ZigZag",
                     depth,
                     edeviation,
                     backStep
                     ); */
   int MaHandle=iCustom(Symbol(),PERIOD_CURRENT,"Examples/Custom Moving Average",
                        MA_Period,
                        MA_Shift,
                        MA_Method,
                        PRICE_CLOSE // using the close prices
                       );
   Print("zigzag Handle = ",MaHandle,"  error = ",GetLastError());
   int copy=CopyBuffer(MaHandle,0,0,limit,zzBuffer);
   Print("copy = ",copy,"    rates_total = ",limit);

   if(copy<=0)
      Print("An attempt to get the values if Custom ZZ has failed");
   for(int i=0 ; i < ArraySize(zzBuffer) ; i++)
     {
      if(zzBuffer[i] !=0)
         PrintFormat(" i: %d , time: %s Value: %f ", i,TimeToString(iTime(Symbol(),eTF,i)), zzBuffer[i]);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
Files:
Untitled.png  77 kb
 

Follow two basic rules:

  1. OnInit is intended FOR INITIALIZATION !!! CopyBuffer cannot be used inside OnInit !!!
  2. Be sure to read the ArraySetAsSeries help
Documentation on MQL5: Array Functions / ArraySetAsSeries
Documentation on MQL5: Array Functions / ArraySetAsSeries
  • www.mql5.com
ArraySetAsSeries - Array Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Gholamhossein Eslamizadeh:

Hi, I am trying to use iCustom and I get wrong results can anybudy help me . thanks.

to set your zzBuffer with ArraySetAsSeries as true might help.  that's the key difference vs mql4's.

Print("zigzag Handle = ",MaHandle,"  error = ",GetLastError());
ArraySetAsSeries(zzBuffer,true);
int copy=CopyBuffer(MaHandle,0,0,limit,zzBuffer);
 
Vladimir Karputov:

Follow two basic rules:

  1. OnInit is intended FOR INITIALIZATION !!! CopyBuffer cannot be used inside OnInit !!!
  2. Be sure to read the ArraySetAsSeries help
Tsungche Kuo:

to set your zzBuffer with ArraySetAsSeries as true might help.  that's the key difference vs mql4's.

I am really Grateful, you guys saved my day  and fixed my headache. I hope best for you . Thanks a lot.

Reason: