You have green and red.
These are CrossColour[0] = Green and CrossColour[1] = Red.
So you can not do CrossColour[-1]
You have green and red.
These are CrossColour[0] = Green and CrossColour[1] = Red.
So you can not do CrossColour[-1]
Hi, and thanks for the response.
I agree that the -1 is not sensible, but it is a value used only when no arrow is drawn, i.e. CrossBuffer[i] is 0 at that point.
I did actually set it as zero for no arrow initially, and the -1 was simply my attempts at trying to find the problem. Using a 0 or 1 gives the same result.
Thanks again.
Hello you can see example here: https://www.mql5.com/en/articles/135
//+------------------------------------------------------------------+ //| cand_color.mq5 | //| ProF | //| http:// | //+------------------------------------------------------------------+ #property copyright "ProF" //Author #property indicator_chart_window //Indicator in separate window //Specify the number of buffers of the indicator //4 buffer for candles + 1 color buffer + 1 buffer to serve the RSI data #property indicator_buffers 6 //Specify the names in the Data Window #property indicator_label1 "Open;High;Low;Close" #property indicator_plots 1 //Number of graphic plots #property indicator_type1 DRAW_COLOR_CANDLES //Drawing style - color candles #property indicator_width1 3 //Width of the graphic plot (optional) //Declaration of buffers double buffer_open[],buffer_high[],buffer_low[],buffer_close[]; //Buffers for data double buffer_color_line[]; //Buffer for color indexes double buffer_tmp[1]; //Temporary buffer for RSI data copying double buffer_RSI[]; //Indicator buffer for RSI int handle_rsi=0; //Handle for the RSI indicator //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { /** * The order of the buffers assign is VERY IMPORTANT! * The data buffers are first * The color buffers are next * And finally, the buffers for the internal calculations. */ //Assign the arrays with the indicator's buffers SetIndexBuffer(0,buffer_open,INDICATOR_DATA); SetIndexBuffer(1,buffer_high,INDICATOR_DATA); SetIndexBuffer(2,buffer_low,INDICATOR_DATA); SetIndexBuffer(3,buffer_close,INDICATOR_DATA); //Assign the array with color indexes with the indicator's color indexes buffer SetIndexBuffer(4,buffer_color_line,INDICATOR_COLOR_INDEX); //Assign the array with the RSI indicator data buffer SetIndexBuffer(5,buffer_RSI,INDICATOR_CALCULATIONS); //Define the number of color indexes, used for a graphic plot PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2); //Set color for each index PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,Blue); //Zeroth index -> Blue PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Orange); //First index -> Orande //Get handle of RSI indicator, it's necessary to get the RSI indicator values handle_rsi=iCustom(_Symbol,_Period,"Examples\\RSI"); return(0); } //+------------------------------------------------------------------+ //| 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[]) { //In the loop we fill the data buffers and color indexes buffers for each bar for(int i=prev_calculated;i<=rates_total-1;i++) { //Copying the RSI indicator's data to the temporary buffer - buffer_tmp CopyBuffer(handle_rsi,0,BarsCalculated(handle_rsi)-i-1,1,buffer_tmp); //Copying the values from the temporary buffer to the indicator's buffer buffer_RSI[i]=buffer_tmp[0]; //Set data for plotting buffer_open[i]=open[i]; //Open price buffer_high[i]=high[i]; //High price buffer_low[i]=low[i]; //Low price buffer_close[i]=close[i];//Close price //Add a simple condition -> If RSI less 50%: if(buffer_RSI[i]<50) { buffer_color_line[i]=0; } //Assign the bar with color index, equal to 0 else { buffer_color_line[i]=1; } //Assign the bar with color index, equal to 1 } return(rates_total-1); //Return the number of calculated bars, //Subtract 1 for the last bar recalculation } //+------------------------------------------------------------------+
- www.mql5.com
Thanks for the link.
I used that article and several others and some examples in my attempts to get as far as I have. I cannot see what I am doing that is not the same as in the article.
Thanks for the link.
I used that article and several others and some examples in my attempts to get as far as I have. I cannot see what I am doing that is not the same as in the article.
#property indicator_type1 DRAW_ARROW
replace it with
#property indicator_type1 DRAW_COLOR_ARROW
And, as you have already been told : color index -1 does not exist. Color indexes are going from 0 to +nnn (depending how much colors you have)
replace it with
And, as you have already been told : color index -1 does not exist. Color indexes are going from 0 to +nnn (depending how much colors you have)
Thank you SO much! I knew it was some tiny thing that I was overlooking.
Much appreciated that you took the time to check my code.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I am a complete noob, and trying to learn how to code an indicator.
At the moment I am simply trying to draw an arrow when a moving average cross occurs. It is working, except that I would like the colour of the arrow to correspond with the direction of the cross.
I have tried the simplest method that I believe should work, which I am presenting here, and several others, but the arrow always takes the first colour that I have defined.
I am sure that I am only missing a very small little detail. Any help will be most welcome, please.