iAO Multi Timeframe ARROW

Author: Copyright © 2020, Vladimir Karputov
Indicators Used
Bill Williams Awesome oscillator
0 Views
0 Downloads
0 Favorites
iAO Multi Timeframe ARROW
ÿþ//+------------------------------------------------------------------+

//|                                    iAO Multi Timeframe ARROW.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"

#property version   "1.001"

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_plots   1

//--- plot Label1

#property indicator_label1  "iAO Signal"

#property indicator_type1   DRAW_COLOR_ARROW

#property indicator_color1  clrDeepSkyBlue,clrTomato

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- input parameters

//--- Arrows

input uchar    InpSignalCode     = 172;         // Arrow code for 'Signal' (font Wingdings)

input int      InpShift          = 10;          // Vertical shift of arrows in pixel

//--- indicator buffers

double   iAOBuffer[];

double   iAOColors[];

//---

int      handles[3];

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- indicator buffers mapping

   SetIndexBuffer(0,iAOBuffer,INDICATOR_DATA);

   SetIndexBuffer(1,iAOColors,INDICATOR_COLOR_INDEX);

//--- setting a code from the Wingdings charset as the property of PLOT_ARROW

   PlotIndexSetInteger(0,PLOT_ARROW,InpSignalCode);

//--- set the vertical shift of arrows in pixels

   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,-InpShift);

//--- an empty value for plotting, for which there is no drawing

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);

//---

   ENUM_TIMEFRAMES timeframes[3]= {PERIOD_M15,PERIOD_H1,PERIOD_H4};

   for(int i=0; i<3; i++)

     {

      //--- create handle of the indicator iAO

      int handle_iAO=iAO(Symbol(),timeframes[i]);

      //--- if the handle is not created

      if(handle_iAO==INVALID_HANDLE)

        {

         //--- tell about the failure and output the error code

         PrintFormat("Failed to create handle of the iAO indicator for the symbol %s/%s, error code %d",

                     Symbol(),

                     EnumToString(timeframes[i]),

                     GetLastError());

         //--- the indicator is stopped early

         return(INIT_FAILED);

        }

      handles[i]=handle_iAO;

     }

//---

   return(INIT_SUCCEEDED);

  }

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

//| 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[])

  {

//---

   int limit=prev_calculated-1;

   if(prev_calculated==0)

     {

      for(int i=0; i<rates_total; i++)

        {

         iAOBuffer[i]=0.0;

         iAOColors[i]=0.0;

        }

      return(rates_total);

     }

//--- main loop

   for(int i=0; i<3; i++)

      if(BarsCalculated(handles[i])<0)

         return(rates_total);



   double values[3]= {0.0,0.0,0.0};

   for(int i=0; i<3; i++)

     {

      double color_value[];

      //--- fill a part of the iAOBuffer array with values from the indicator buffer that has 0 index

      if(CopyBuffer(handles[i],1,0,1,color_value)<0)

         return(rates_total);

      values[i]=color_value[0];

     }



   iAOBuffer[rates_total-1]=0.0;

   iAOColors[rates_total-1]=0.0;

   if(values[0]==values[1] && values[1]==values[2])

     {

      if(values[0]==0.0)

        {

         iAOBuffer[rates_total-1]=high[rates_total-1];

         iAOColors[rates_total-1]=0.0;

        }

      else

         if(values[0]==1.0)

           {

            iAOBuffer[rates_total-1]=high[rates_total-1];

            iAOColors[rates_total-1]=1.0;

           }

     }

//--- return value of prev_calculated for next call

   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 ---