Trabalhando um pouco mais no indicador, reparei que o erro tem relação com a falta de base histórica do IBOV.
Me parece que quando eu inicializo o terminal MT5 o histórico do IBOV não fica armazenado e por tanto é preciso adicionar o histórico.
Minha dúvida agora está em como chamar o histórico do IBOV do servidor via programação.
Obrigado,
Você está perdendo oportunidades de negociação:
- Aplicativos de negociação gratuitos
- 8 000+ sinais para cópia
- Notícias econômicas para análise dos mercados financeiros
Registro
Login
Você concorda com a política do site e com os termos de uso
Se você não tem uma conta, por favor registre-se
Prezados,
Estou tendo um problema para criar um indicador que na verdade trata-se apenas de plotar o gráfico do Bovespa no gráfico do papel que está no painel principal.
Estou fazendo a sincronia entre os papeis criando um Array do tipo "datetime" onde eu uso a função CopyTime para copiar o histórico do tempo do papel IBOV. Partindo dessa variável eu busco qual barra do gráfico do IBOV corresponde a barra atual do papel em questão no painel principal.
Na verdade, o indicador está funcionando mas só depois que eu rodo ele no testador de estratégia. Se eu fechar o terminal e abrir novamente o indicador está dando erro "Array out of range".
Acredito que o erro possa ser pelo fato deu não conseguir indexar a variável Array como um Buffer usando a função SetIndexBuffer.
Se alguém puder me ajudar eu agradeço.
Segue abaixo o trecho do código.
//--- indicator buffers
double IBOVBuffer[];
double IBOVInterBuffer[];
double ColorBuffer [];
datetime IBOVTimeBuffer[];
//---outros
bool TesteInicial = true ;
string Parpel = "IBOV" ;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,IBOVBuffer,INDICATOR_DATA);
SetIndexBuffer ( 1 , IBOVInterBuffer , INDICATOR_CALCULATIONS);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//---
if(TesteInicial)
{
TesteInicial = false ;
int TOTBAR = Bars( Parpel , PERIOD_CURRENT ) ;
//ArraySetAsSeries ( IBOVBuffer , false );
//ArraySetAsSeries ( IBOVInterBuffer , false );
//ArraySetAsSeries ( IBOVTimeBuffer , false );
CopyClose ( Parpel , PERIOD_CURRENT , time [rates_total -1 ] , TOTBAR , IBOVInterBuffer );
CopyTime ( Parpel , PERIOD_CURRENT , time [rates_total -1 ] , TOTBAR , IBOVTimeBuffer );
int TOTALARRAY = ArrayRange(IBOVTimeBuffer ,0);
int j = 1 ;
for(int i= 2 ; i <= rates_total - 1 ; i++)
{
IBOVBuffer [ i ] = IBOVBuffer [ i - 1 ];
// -- PROCURA A BARRA ATRAVES DA DATA
for(int k=j;k <= TOTALARRAY - 1 ;k++)
{
if( time [i] == IBOVTimeBuffer [ k ] )
{
IBOVBuffer [ i ] = IBOVInterBuffer [ k - 1 ] ;
j = k ;
break;
}
}
}
}
// plota a ultima barra
int ULTBAR = Bars( Parpel , PERIOD_CURRENT );
//ArraySetAsSeries ( IBOVBuffer , false );
//ArraySetAsSeries ( IBOVInterBuffer , false );
//ArraySetAsSeries ( IBOVTimeBuffer , false );
CopyClose ( Parpel , PERIOD_CURRENT , time [rates_total - 1 ] , ULTBAR , IBOVInterBuffer );
CopyTime ( Parpel , PERIOD_CURRENT , time [ rates_total - 1 ] , ULTBAR , IBOVTimeBuffer );
int ULTARRAY = ArrayRange(IBOVTimeBuffer ,0);
if ( time[ rates_total -1 ] == IBOVTimeBuffer[ ULTARRAY - 1 ] ) //IBOVTimeBuffer[ ULTARRAY - 1 ]
{
IBOVBuffer [ rates_total -1 ] = IBOVInterBuffer [ ULTARRAY -1] ;
}
else
{
IBOVBuffer [ rates_total -1 ] = IBOVBuffer [ rates_total -2 ];
}
//--- return value of prev_calculated for next call
return(rates_total);
}