You need to use DRAW_COLOR_LINE instead of DRAW_LINE if you want to achieve that.
DRAW_COLOR_LINE uses two buffers for 1 plot.
#property indicator_buffers 2 #property indicator_plots 1 #property indicator_label1 "ColorLine" #property indicator_type1 DRAW_COLOR_LINE #property indicator_color1 clrRed,clrBlue,clrGreen
//--- A buffer for plotting double ColorLineBuffer[]; //--- A buffer for storing the line color on each bar double ColorLineColors[];
int OnInit() { //--- Binding an array and an indicator buffer SetIndexBuffer(0,ColorLineBuffer,INDICATOR_DATA); SetIndexBuffer(1,ColorLineColors,INDICATOR_COLOR_INDEX); 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[]) { for (int i=prev_calculated;i<rates_total;i++){ ColorLineBuffer[i] = ....... what data should be passed to the line if(condition1) ColorLineColors[i] = 0; //first color defined in properties if(condition2) ColorLineColors[i] = 1; //second color defined in properties //and so on }
Nice, thank you.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I am trying to code an indicator (lets say a MA for simplicity) that is calculated in higher time frame data to be displayed in a lower TF chart. For this code, I have recycle several codes available in the code base, but I am falling short to find a way to color code the direction of the line. Say blue when it goes up and red when it goes down. Does this requires to create a new buffer? I am trying to avoid using computer resources, as for some reason this code is very slow.... So are the originals I found.