Нужна помощь в коде MQL

 

Ткните меня носом, пожайлуста, не могу понять как сделать правильно.

Задача: заполнит массив данными от индикатора.


//+------------------------------------------------------------------+
//|                                           Заполнение_Массива.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        https://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "https://www.metaquotes.net"
 
double RSIBuffer[];
extern int RSIPeriod=14;
int init()
  {
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
   int    i,counted_bars=IndicatorCounted();
   double rel,negative,positive;
//----
   if(Bars<=RSIPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=RSIPeriod;i++) RSIBuffer[Bars-i]=0.0;
//----
   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      RSIBuffer[i]=iRSI(Symbol(),NULL,RSIPeriod,PRICE_CLOSE,i);
      Print("/",i,"/",RSIBuffer[i],"/",iRSI(Symbol(),NULL,RSIPeriod,PRICE_CLOSE,i));
      i--;
     }
//----
   return(0);
  }

в результате видим по шаблону i/RSIBuffer[i]/iRSI(Symbol(),NULL,RSIPeriod,PRICE_CLOSE,i):

2008.06.17 21:48:11 2008.06.16 05:53 Заполнение_Массива EURUSD,M5: /858/0/51.2355
2008.06.17 21:48:11 2008.06.16 05:53 Заполнение_Массива EURUSD,M5: /859/0/53.2065
2008.06.17 21:48:11 2008.06.16 05:53 Заполнение_Массива EURUSD,M5: /860/0/55.1775
2008.06.17 21:48:11 2008.06.16 05:53 Заполнение_Массива EURUSD,M5: /861/0/48.0261
2008.06.17 21:48:11 2008.06.16 05:53 Заполнение_Массива EURUSD,M5: /862/0/48.0261

Подскажите пожалуйста почему RSIBuffer[i] равен Нулю?

Заранее Благодарен!

 

Хорошо,

вот тут

double RSIBuffer[];// а задать размер массива забыли?

к примеру, так

double RSIBuffer[1000];

И если надо изменить размер массива используем функцию ArrayResize();

Например,

ArrayResize(RSIBuffer,2000);
 
Nikolasnik писал (а) >>

Ткните меня носом, пожайлуста, не могу понять как сделать правильно.

//+------------------------------------------------------------------+
//|                                           Заполнение_Массива.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property indicator_buffers 1

double RSIBuffer[];
extern int RSIPeriod=14;
int init()
  {
   SetIndexBuffer(0,RSIBuffer);
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
   int    i,counted_bars=IndicatorCounted();
   double rel,negative,positive;
//----
   if(Bars<=RSIPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=RSIPeriod;i++) RSIBuffer[Bars-i]=0.0;
//----
   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      RSIBuffer[i]=iRSI(Symbol(),NULL,RSIPeriod,PRICE_CLOSE,i);
      Print("/",i,"/",RSIBuffer[i],"/",iRSI(Symbol(),NULL,RSIPeriod,PRICE_CLOSE,i));
      i--;
     }
//----
   return(0);
  }
 
//+------------------------------------------------------------------+
//|                                           Заполнение_Массива.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property indicator_buffers 1
#property indicator_separate_window
#property indicator_color1 Blue
double RSIBuffer[];
extern int RSIPeriod=14;
int init()
  {
   SetIndexBuffer(0,RSIBuffer);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexLabel(0,"NZZ");
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
   int    i,counted_bars=IndicatorCounted();
   double rel,negative,positive;
//----
   if(Bars<=RSIPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=RSIPeriod;i++) RSIBuffer[Bars-i]=0.0;
//----
   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   while(i>=0)
   {
      RSIBuffer[i]=iRSI(Symbol(),NULL,RSIPeriod,PRICE_CLOSE,i);
     Print("/",i,"/",RSIBuffer[i],"/",iRSI(Symbol(),NULL,RSIPeriod,PRICE_CLOSE,i));
    i--;
  }
 
 
   return(0);
  }

Это индикатор.

//+------------------------------------------------------------------+
//|                                           Заполнение_Массива.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property show_inputs
 
 
extern int RSIPeriod=14;
double RSIBuffer[100];
 
int start()
  {
   if (Bars>100) ArrayResize(RSIBuffer,Bars-RSIPeriod);
   if(Bars<=RSIPeriod) return(0);
   int limit=Bars-RSIPeriod-1;
   
   for(int i=0;i<=limit;i++)
   {
      RSIBuffer[i]=iRSI(Symbol(),NULL,RSIPeriod,PRICE_CLOSE,i);
     Print("/",i,"/",RSIBuffer[i],"/",iRSI(Symbol(),NULL,RSIPeriod,PRICE_CLOSE,i));
   }
   return(0);
  }
А это скрипт.
 
D500_Rised писал (а) >>

Это индикатор.

А это скрипт.

Понял разницу !!

Большое всем СПАСИБО! А то лоб разбил!!