Indicador personalizado plotando todas linhas no mesmo lugar no Testador de Estratégia

 
//--- input parameters
input double               K_Fibo_1 = 2;
input double               K_Fibo_2 = 1.75;
input double               K_Fibo_3 = 1.5;
input double               K_Fibo_4 = 0.618;
input double               K_Fibo_5 = 0.50;
input double               K_Fibo_6 = 0.25;
input double               K_Fibo_7 = 0;

input ENUM_TIMEFRAMES      Period_TF=PERIOD_D1;

//--- indicator buffers
double         buffer1[];
double         buffer2[];
double         buffer3[];
double         buffer4[];
double         buffer5[];
double         buffer6[];
double         buffer7[];
double         buffer8[];
double         buffer9[];
double         buffer10[];
double         buffer11[];
double         buffer12[];
double         buffer13[];
double         buffer14[];
double         buffer15[];

datetime time_tf[];
double high_tf[];
double low_tf[];
int bars_tf=0;
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,buffer1,INDICATOR_DATA);
   SetIndexBuffer(1,buffer2,INDICATOR_DATA);
   SetIndexBuffer(2,buffer3,INDICATOR_DATA);
   SetIndexBuffer(3,buffer4,INDICATOR_DATA);
   SetIndexBuffer(4,buffer5,INDICATOR_DATA);
   SetIndexBuffer(5,buffer6,INDICATOR_DATA);
   SetIndexBuffer(6,buffer7,INDICATOR_DATA);
   SetIndexBuffer(7,buffer8,INDICATOR_DATA);
   SetIndexBuffer(8,buffer9,INDICATOR_DATA);
   SetIndexBuffer(9,buffer10,INDICATOR_DATA);
   SetIndexBuffer(10,buffer11,INDICATOR_DATA);
   SetIndexBuffer(11,buffer12,INDICATOR_DATA);
   SetIndexBuffer(12,buffer13,INDICATOR_DATA);
   SetIndexBuffer(13,buffer14,INDICATOR_DATA);
   SetIndexBuffer(14,buffer15,INDICATOR_DATA);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int limit=prev_calculated;
   if(limit>0)limit--;

   int bar=Bars(_Symbol,Period_TF);
   if(bars_tf==0 || bar>bars_tf)array_copy(bar);

   
   f3(limit,rates_total,time,buffer8);
   
   f1(K_Fibo_7,limit,rates_total,time,buffer7,buffer9);
   f1(K_Fibo_1,limit,rates_total,time,buffer1,buffer15);
   f1(K_Fibo_2,limit,rates_total,time,buffer2,buffer14);
   f1(K_Fibo_3,limit,rates_total,time,buffer3,buffer13);   
   f1(K_Fibo_4,limit,rates_total,time,buffer4,buffer12);
   f1(K_Fibo_5,limit,rates_total,time,buffer5,buffer11);
   f1(K_Fibo_6,limit,rates_total,time,buffer6,buffer10);

   return(rates_total);
  }
//+------------------------------------------------------------------+  
void f1(double k_fibo,int q,int r,const datetime &time_[],double &b1[],double &b2[])
  {
   for(int i=q;i<r && !_StopFlag;i++)
     {
      int b=f2(time_[i]);//find the time of the current bar in the array of the higher
      double h=high_tf[b];//get the high
      double l=low_tf[b];//get the low
      double hl=h-l;//find the movement range
      b1[i]=h+hl*k_fibo;//add the calculated value to the support buffer
      b2[i]=l-hl*k_fibo;//add the calculated value to the resistance buffer
     }
  }
//+------------------------------------------------------------------+
int f2(datetime t_)
  {
   int b_=ArrayBsearch(time_tf,t_);//find a bar using a standard search in sorted arrays
   if(time_tf[b_]>t_)b_--;//if the time of the nearest bar of a higher timeframe is returned, we will reduce it by 1
   return(MathMax(0,b_-1));//do not forget to return a bars taking into account the minimum limit
  }
//+------------------------------------------------------------------+
void array_copy(int b_)
  {
   ArrayResize(time_tf,b_);//changing the buffer size for our data
   ArrayResize(high_tf,b_);
   ArrayResize(low_tf,b_);

   int total=b_-bars_tf;//calculate the required data copying

   CopyTime(_Symbol,Period_TF,0,total,time_tf);//copy missing data to the array
   CopyHigh(_Symbol,Period_TF,0,total,high_tf);
   CopyLow(_Symbol,Period_TF,0,total,low_tf);

   bars_tf=b_;//remember the array size and the amount of data
  }
//+------------------------------------------------------------------+
void f3(int q,int r,const datetime &time_[],double &b1[])
  {
   for(int i=q;i<r && !_StopFlag;i++)
     {
      int b=f2(time_[i]);//find the time of the current bar in the array of the higher
      double h=high_tf[b];//get the high
      double l=low_tf[b];//get the low
      double hl=h-l;//find the movement range
      b1[i]= (h+l)/2;
     }
  }
//+------------------------------------------------------------------+

Bom dia, pessoal! Fiz uma adaptação de um indicador e criei um novo indicador com 15 buffers que desenha linhas no gráfico. O indicador funciona bem no gráfico em tempo real, mas quando vou rodar esse indicador no Testador de Estratégia, todas as linhas são plotadas no mesmo lugar desde o dia que começa o backtest até o último dia. Preciso que as linhas sejam plotadas corretamente para fazer a conferência visual das entradas e das saídas para ver se estão corretas quando eu for jogar em um EA.

O que pode estar causando esse erro? Alguém pode me ajudar quanto a isso?

Deixo aqui o código que estou utilizando e as imagens em anexo de como funciona corretamente em tempo real, mas no Testador de Estratégia ocorre um erro.


OBs.: O teste está sendo feito no modo indicador e não dentro de um EA.

Estratégias de teste - Trading algorítmico, robôs comerciais - Ajuda para o MetaTrader 5
Estratégias de teste - Trading algorítmico, robôs comerciais - Ajuda para o MetaTrader 5
  • www.metatrader5.com
O testador de estratégias permite testar e otimizar estratégias de negociação ( experts ) antes de as usar em uma...
Arquivos anexados:
grtel.png  181 kb
grtel2.png  161 kb
 
LKalemba:

Bom dia, pessoal! Fiz uma adaptação de um indicador e criei um novo indicador com 15 buffers que desenha linhas no gráfico. O indicador funciona bem no gráfico em tempo real, mas quando vou rodar esse indicador no Testador de Estratégia, todas as linhas são plotadas no mesmo lugar desde o dia que começa o backtest até o último dia. Preciso que as linhas sejam plotadas corretamente para fazer a conferência visual das entradas e das saídas para ver se estão corretas quando eu for jogar em um EA.

O que pode estar causando esse erro? Alguém pode me ajudar quanto a isso?

Deixo aqui o código que estou utilizando e as imagens em anexo de como funciona corretamente em tempo real, mas no Testador de Estratégia ocorre um erro.


OBs.: O teste está sendo feito no modo indicador e não dentro de um EA.

Ficou sem o código sua mensagem.

 
Adailton Silva #:

Ficou sem o código sua mensagem.

Atualizei a postagem.