This is my code trying to generate the ADC Cloud indicator. At first, it can work if I just generate the cloud.
Currently, I am trying to make the histogram green when it is above zero, otherwise red. Then, I separate the Could array into two buffers, GreenBuffer and RedBuffer. At this step, I stuck in an unknown error.
I can make sure the problem is coming from the ERROR PART, marked by Sharp Sign in Code.
Thank you first!
#property strict
#property indicator_separate_window
#property indicator_buffers 2
//--- input parameters
input int ADX_period=14;
double Cloud[];
double GreenBuffer[];
double RedBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
//SetIndexBuffer(0, GreenBuffer);
SetIndexBuffer(0, Cloud);
SetIndexLabel(0, "Cloud");
SetIndexStyle(0, DRAW_HISTOGRAM, 0, 2, clrGreen);
//SetIndexBuffer(1, Cloud);
//SetIndexStyle(1, DRAW_HISTOGRAM, 0, 2, clrRed);
//---
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[])
{
//---
int Limit_calc = 0;
int BarCnt = IndicatorCounted();
Limit_calc = Bars - BarCnt;
for (int i = Limit_calc-1; i >= 0 ; i--)
{
double output = iADX(NULL, 0, ADX_period, PRICE_CLOSE, MODE_PLUSDI, i)
- iADX(NULL, 0, ADX_period, PRICE_CLOSE, MODE_MINUSDI, i);
Cloud[i] = output;
// #########################################
// ###### Error Part #######################
//if (output > 0)
// {
// GreenBuffer[i] = output;
// RedBuffer[i] = 0.00;
// }
//else
// {
// GreenBuffer[i] = 0.00;
// RedBuffer[i] = output;
// }
// ##########################################
}
//Comment(Cloud[1]);
//--- return value of prev_calculated for next call
return(rates_total);
}