//+------------------------------------------------------------------+ //| Rainbow.mq5 | //| Copyright 2011, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2011, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #property indicator_separate_window #property indicator_buffers 2 #property indicator_plots 1 //--- plot Rainbow #property indicator_label1 "Rainbow" #property indicator_type1 DRAW_COLOR_HISTOGRAM //--- 4 colors for 4 conditions #property indicator_color1 clrGreen,clrBlue,clrOrange,clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- input parameters input int period=10; // how many bars ago we compare to input ENUM_APPLIED_VOLUME use_volume=VOLUME_TICK; // tick or trade volume use //--- indicator buffers double RainbowBuffer[]; double RainbowColors[]; //--- auxiliary variable bool real_volume; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,RainbowBuffer,INDICATOR_DATA); SetIndexBuffer(1,RainbowColors,INDICATOR_COLOR_INDEX); //--- which volume type we use real_volume=use_volume==VOLUME_REAL; //--- IndicatorSetInteger(INDICATOR_DIGITS,0); //--- 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[]) { //--- start position for calculation int start=prev_calculated; if(start>0) start--; // for f else start=period; // for first calc we must add forward shift equals period variable //--- main cycle for(int i=start;iclose[i-period]) { //--- price is greater then period bars before if(v1>v2) RainbowColors[i]=0; // index of Green color else RainbowColors[i]=1; // index of Blue color } else { //--- price is less then period bars before if(v1