Need help with ichimoku cross indicator

 

Hello every one;

I'm rather new to indicator writing and trying to write a cross over indicator to use with ichimoku. It is supposed to shows the condition of Kijunsen and Tenkansen relative to each other

if Kijunsen<Tenkan the color will be Red .. if Kijunsen>Tenkan the color will be Blue and if they are equal the color should be Yellow. But it seems I'm missing something only one color is displayed in the cross over indicator.

Your help and comments are greatly appreciated. Thank you in advance.

//+------------------------------------------------------------------+
//|                                                     Ichimoku.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property description "Ichimoku Kinko Hyo"
//--- indicator settings
#property indicator_separate_window

#property indicator_buffers 8
#property indicator_plots   1

#property indicator_type1   DRAW_COLOR_HISTOGRAM

#property indicator_color1  Red,Blue,clrYellow
#property indicator_label1  "Cross"


#property indicator_width1  2

#property indicator_minimum 0
#property indicator_maximum 1

//--- input parameters
input int InpTenkan=9;     // Tenkan-sen
input int InpKijun=26;     // Kijun-sen
input int InpSenkou=52;    // Senkou Span B
//--- indicator buffers
double    ExtTenkanBuffer[];
double    ExtKijunBuffer[];
double    ExtSpanABuffer[];
double    ExtSpanBBuffer[];
double    ExtChinkouBuffer[];
double    ExtTenkanBuffer1[];
double    ExtKijunBuffer1[];
double    ExtColorBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtTenkanBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtKijunBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,ExtSpanABuffer,INDICATOR_DATA);
   SetIndexBuffer(3,ExtSpanBBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,ExtChinkouBuffer,INDICATOR_DATA);
   SetIndexBuffer(5,ExtTenkanBuffer1,INDICATOR_DATA);
   SetIndexBuffer(6,ExtKijunBuffer1,INDICATOR_DATA);
   SetIndexBuffer(7,ExtColorBuffer,INDICATOR_COLOR_INDEX);
//---- èينهêٌàِèے ‎ëهىهيٍîâ â لَôهًàُ êàê â ٍàéىٌهًèےُ   
   ArraySetAsSeries(ExtTenkanBuffer,true);
   ArraySetAsSeries(ExtKijunBuffer,true);  
   ArraySetAsSeries(ExtSpanABuffer,true);
   ArraySetAsSeries(ExtSpanBBuffer,true); 
   ArraySetAsSeries(ExtChinkouBuffer,true);
   ArraySetAsSeries(ExtTenkanBuffer1,true);
   ArraySetAsSeries(ExtKijunBuffer1,true);  
   ArraySetAsSeries(ExtColorBuffer,true);
////---
//   IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- sets first bar from what index will be drawn

//   PlotIndexSetInteger(7,PLOT_DRAW_BEGIN,MathMax(InpTenkan,InpKijun));
//
////--- change labels for DataWindow 
//   PlotIndexSetString(7,PLOT_LABEL,"Tenkan-sen("+string(InpTenkan)+")");
//   PlotIndexSetString(7,PLOT_LABEL,"Kijun-sen("+string(InpKijun)+")");

//--- initialization done
  }
//+------------------------------------------------------------------+
//| Ichimoku Kinko Hyo                                               |
//+------------------------------------------------------------------+
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 &TickVolume[],
                const long &Volume[],
                const int &Spread[])
  {
   int limit;
//---- èينهêٌàِèے ‎ëهىهيٍîâ â ىàٌٌèâàُ êàê â ٍàéىٌهًèےُ  
   ArraySetAsSeries(High,true);
   ArraySetAsSeries(Low,true);  
   ArraySetAsSeries(Close,true);
//---
   if(prev_calculated==0) limit=0;
   else                   limit=prev_calculated-1;
//---
   for(int i=limit;i<rates_total && !IsStopped();i++)
     {
      ExtChinkouBuffer[i]=Close[i];
      //--- tenkan sen
      double high=High[ArrayMaximum(High,i,InpTenkan)];
      double low=Low[ArrayMinimum(Low,i,InpTenkan)];
      ExtTenkanBuffer[i]=ExtTenkanBuffer1[i]=(high+low)/2.0;
      //--- kijun sen
      high=High[ArrayMaximum(High,i,InpKijun)];
      low=Low[ArrayMinimum(Low,i,InpKijun)];
      ExtKijunBuffer[i]=ExtKijunBuffer1[i]=(high+low)/2.0;
      //--- senkou span a
      ExtSpanABuffer[i]=(ExtTenkanBuffer[i]+ExtKijunBuffer[i])/2.0;
      //--- senkou span b
      high=High[ArrayMaximum(High,i,InpSenkou)];
      low=Low[ArrayMinimum(Low,i,InpSenkou)];
      ExtSpanBBuffer[i]=(high+low)/2.0;
      if(ExtKijunBuffer[i]<ExtTenkanBuffer[i]) ExtColorBuffer[i]=0;
      else if (ExtKijunBuffer[i]>ExtTenkanBuffer[i]) ExtColorBuffer[i]=1;
      else if (ExtKijunBuffer[i]==ExtTenkanBuffer[i]) ExtColorBuffer[i]=2;
     }
//--- done
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

I did it with two 'DRAW_ARROW' plots Ichimoku Tenkan Kijun Intersection

Ichimoku Tenkan Kijun Intersection
Ichimoku Tenkan Kijun Intersection
  • www.mql5.com
Индикатор ищет пересечения Tenkan и Kijun индикатора 'Ichimoku'
 
Vladimir Karputov #:

I did it with two 'DRAW_ARROW' plots Ichimoku Tenkan Kijun Intersection

Thank you very much Vladimir :)
Reason: