Heiken Ashi Separate Window

Author: Copyright © 2020, Vladimir Karputov
Price Data Components
0 Views
0 Downloads
0 Favorites
Heiken Ashi Separate Window
ÿþ//+------------------------------------------------------------------+

//|                                  Heiken Ashi Separate Window.mq5 |

//|                              Copyright © 2020, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43516 |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2020, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43516"

//--- indicator settings

#property indicator_separate_window

#property indicator_buffers 5

#property indicator_plots   1

#property indicator_type1   DRAW_COLOR_CANDLES

#property indicator_color1  clrDodgerBlue, clrRed

#property indicator_label1  "Heiken Ashi Open;Heiken Ashi High;Heiken Ashi Low;Heiken Ashi Close"

//--- indicator buffers

double OpenBuffer[];

double HighBuffer[];

double LowBuffer[];

double CloseBuffer[];

double ColorBuffer[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

void OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,OpenBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,HighBuffer,INDICATOR_DATA);

   SetIndexBuffer(2,LowBuffer,INDICATOR_DATA);

   SetIndexBuffer(3,CloseBuffer,INDICATOR_DATA);

   SetIndexBuffer(4,ColorBuffer,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;

//--- preliminary calculations

   if(prev_calculated==0)

     {

      //--- set first candle

      LowBuffer[0]=low[0];

      HighBuffer[0]=high[0];

      OpenBuffer[0]=open[0];

      CloseBuffer[0]=close[0];

      limit=1;

     }

   else

      limit=prev_calculated-1;

//--- the main loop of calculations

   for(i=limit; i<rates_total && !IsStopped(); i++)

     {

      double haOpen=(OpenBuffer[i-1]+CloseBuffer[i-1])/2;

      double haClose=(open[i]+high[i]+low[i]+close[i])/4;

      double haHigh=MathMax(high[i],MathMax(haOpen,haClose));

      double haLow=MathMin(low[i],MathMin(haOpen,haClose));



      LowBuffer[i]=haLow;

      HighBuffer[i]=haHigh;

      OpenBuffer[i]=haOpen;

      CloseBuffer[i]=haClose;



      //--- set candle color

      if(haOpen<haClose)

         ColorBuffer[i]=0.0; // set color DodgerBlue

      else

         ColorBuffer[i]=1.0; // set color Red

     }

//--- done

   return(rates_total);

  }

//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---