//+------------------------------------------------------------------+ //| Heiken_Ashi.mq5 | //| Copyright 2009-2017, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "2009-2017, MetaQuotes Software Corp." #property link "http://www.mql5.com" //--- indicator settings #property indicator_chart_window #property indicator_buffers 5 #property indicator_plots 1 #property indicator_type1 DRAW_COLOR_CANDLES #property indicator_color1 DodgerBlue, Red #property indicator_label1 "Heiken Ashi Open;Heiken Ashi High;Heiken Ashi Low;Heiken Ashi Close" //--- indicator buffers double ExtOBuffer[]; double ExtHBuffer[]; double ExtLBuffer[]; double ExtCBuffer[]; double ExtColorBuffer[]; // // // #include RangeBarIndicator rangeBarsIndicator; // // // //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,ExtOBuffer,INDICATOR_DATA); SetIndexBuffer(1,ExtHBuffer,INDICATOR_DATA); SetIndexBuffer(2,ExtLBuffer,INDICATOR_DATA); SetIndexBuffer(3,ExtCBuffer,INDICATOR_DATA); SetIndexBuffer(4,ExtColorBuffer,INDICATOR_COLOR_INDEX); //--- IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //--- sets first bar from what index will be drawn IndicatorSetString(INDICATOR_SHORTNAME,"Heiken Ashi"); //--- sets drawing line empty value PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); //--- initialization done } //+------------------------------------------------------------------+ //| Heiken Ashi | //+------------------------------------------------------------------+ 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 i,limit; // // Process data through MedianRenko indicator // if(!rangeBarsIndicator.OnCalculate(rates_total,prev_calculated,time)) return(0); // // Make the following modifications in the code below: // // rangeBarsIndicator.GetPrevCalculated() should be used instead of prev_calculated // // rangeBarsIndicator.Open[] should be used instead of open[] // rangeBarsIndicator.Low[] should be used instead of low[] // rangeBarsIndicator.High[] should be used instead of high[] // rangeBarsIndicator.Close[] should be used instead of close[] // // rangeBarsIndicator.IsNewBar (true/false) informs you if a renko brick completed // // rangeBarsIndicator.Time[] shold be used instead of Time[] for checking the renko bar time. // (!) rangeBarsIndicator.SetGetTimeFlag() must be called in OnInit() for rangeBarsIndicator.Time[] to be used // // rangeBarsIndicator.Tick_volume[] should be used instead of TickVolume[] // rangeBarsIndicator.Real_volume[] should be used instead of Volume[] // (!) rangeBarsIndicator.SetGetVolumesFlag() must be called in OnInit() for Tick_volume[] & Real_volume[] to be used // // rangeBarsIndicator.Price[] should be used instead of Price[] // (!) rangeBarsIndicator.SetUseAppliedPriceFlag(ENUM_APPLIED_PRICE _applied_price) must be called in OnInit() for rangeBarsIndicator.Price[] to be used // int _prev_calculated = rangeBarsIndicator.GetPrevCalculated(); // // // //--- preliminary calculations if(_prev_calculated==0) { //--- set first candle ExtLBuffer[0]=rangeBarsIndicator.Low[0]; ExtHBuffer[0]=rangeBarsIndicator.High[0]; ExtOBuffer[0]=rangeBarsIndicator.Open[0]; ExtCBuffer[0]=rangeBarsIndicator.Close[0]; limit=1; } else limit=_prev_calculated-1; //--- the main loop of calculations for(i=limit;i