ChartOnChart

Author: Copyright 2016 prostotrader
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
ChartOnChart
ÿþ//+------------------------------------------------------------------+

//|                                                 ChartOnChart.mq5 |

//|                                      Copyright 2016 prostotrader |

//|                                             https://www.mql5.com |

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

#property copyright "Copyright 2016 prostotrader"

#property link      "https://www.mql5.com"

#property version   "1.00"

#property indicator_separate_window



#property indicator_buffers 5

#property indicator_plots   1

//

input string SecSymb="RTS-12.16";  //B>1@0605<K9 A8<2>;

input bool   Match=true;           //">G=>5 A>2?045=85 A25G59 ?> 2@5<5=8

input color  LineColor = clrWhite; //&25B ;8=88

input color  BullColor = clrGreen; //&25B 1KGL59 A25G8

input color  BearColor = clrRed;   //&25B <54256L59 A25G8



//--- plot Label1

#property indicator_label1  ""

#property indicator_type1   DRAW_CANDLES

#property indicator_color1  clrWhite, clrGreen,clrRed

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- Levels

#property indicator_level1 0

#property indicator_levelwidth 1

#property indicator_levelstyle STYLE_DOT

//--- 8=48:0B>@=K5 1CD5@K 

double Buffer1[];

double Buffer2[];

double Buffer3[];

double Buffer4[];

double LastBuffer[];

//

double att_cnt;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   att_cnt = 1;

   if(!SymbolSelect(SecSymb,true))

     {

      Alert("5 ?@028;L=> 2K1@0= A8<2>; "+SecSymb);

      return(INIT_FAILED);

     }

   int digits=int(SymbolInfoInteger(SecSymb,SYMBOL_DIGITS));

   IndicatorSetInteger(INDICATOR_DIGITS,digits);

      IndicatorSetString(INDICATOR_SHORTNAME,SecSymb);

   SetIndexBuffer(0,Buffer1,INDICATOR_DATA);

   SetIndexBuffer(1,Buffer2,INDICATOR_DATA);

   SetIndexBuffer(2,Buffer3,INDICATOR_DATA);

   SetIndexBuffer(3,Buffer4,INDICATOR_DATA);

   SetIndexBuffer(4,LastBuffer,INDICATOR_CALCULATIONS);

//---

   ArraySetAsSeries(Buffer1,true);

   ArraySetAsSeries(Buffer2,true);

   ArraySetAsSeries(Buffer3,true);

   ArraySetAsSeries(Buffer4,true);

   ArraySetAsSeries(LastBuffer,true);

//---

   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);

   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,LineColor); 

   PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,BullColor); 

   PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,BearColor);

//---

   IndicatorSetInteger(INDICATOR_LEVELCOLOR,0,clrYellow);

   PlotIndexSetString(0,PLOT_LABEL," Open;"+" High;"+" Low;"+" Close");

//---

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

  {

   ArraySetAsSeries(time,true);

   MqlRates rates[];

   if(prev_calculated==0)

     {

      ArrayInitialize(Buffer1,EMPTY_VALUE);

      ArrayInitialize(Buffer2,EMPTY_VALUE);

      ArrayInitialize(Buffer3,EMPTY_VALUE);

      ArrayInitialize(Buffer4,EMPTY_VALUE);

      ArrayInitialize(LastBuffer,EMPTY_VALUE);

      //---

      int attempts=0;

      int result=0;

      int a_cnt=1000;

      //--- 45;05< 1000 ?>?KB>: ?>;CG8BL B09<A5@8N 

      while((attempts<a_cnt) && !IsStopped())

        {

         result=CopyRates(SecSymb,Period(),0,rates_total,rates);

         if(result>0) break;

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

           {

            result=1;

            result=0;

           }

         attempts++;

        }

      if(result>0)

        {

         int mem_pos=result;

         ArraySetAsSeries(rates,true);

         if(Match)

           {

            for(int i=rates_total-1;i>=0;i--)

              {

               int is_done=false;

               for(int j=mem_pos-1;j>=0;j--)

                 {

                  if(time[i]==rates[j].time)

                    {

                     mem_pos=j;

                     Buffer1[i] = rates[j].open;

                     Buffer2[i] = rates[j].high;

                     Buffer3[i] = rates[j].low;

                     Buffer4[i] = rates[j].close;

                     is_done=true;

                     break;

                    }

                 }

               if(!is_done)

                 {

                  Buffer1[i] = EMPTY_VALUE;

                  Buffer2[i] = EMPTY_VALUE;

                  Buffer3[i] = EMPTY_VALUE;

                  Buffer4[i] = EMPTY_VALUE;

                 }

              }

           }

         else

           {

            for(int i=result-1;i>=0;i--)

              {

               Buffer1[i] = rates[i].open;

               Buffer2[i] = rates[i].high;

               Buffer3[i] = rates[i].low;

               Buffer4[i] = rates[i].close;

              }

           }

        }

      else

        {

          if(att_cnt == 5)

          {

            Alert("0==K5 ?> A8<2>;C "+SecSymb+" =5 A:>?8@>20=K! 5@53@C78B5 8=48:0B>@.");

          }

          else

          {

            att_cnt++;

            return(0);

          }  

        }

     }

     else

     {

       int diff = rates_total - prev_calculated;

       if(diff>0)

       {

         for(int i=diff-1; i>0; i++)

         {

          Buffer1[i] = Buffer1[i+1];

          Buffer2[i] = Buffer2[i+1];

          Buffer3[i] = Buffer3[i+1];

          Buffer4[i] = Buffer4[i+1];

         }

         Buffer1[0]= EMPTY_VALUE;

         Buffer2[0] = EMPTY_VALUE;

         Buffer3[0] = EMPTY_VALUE;

         Buffer4[0] = EMPTY_VALUE;

       }

     }

   if(CopyRates(SecSymb,Period(),0,1,rates)==1)

     {

      if(time[0]==rates[0].time)

        {

         Buffer1[0]= rates[0].open;

         Buffer2[0] = rates[0].high;

         Buffer3[0] = rates[0].low;

         Buffer4[0] = rates[0].close;

        }

     }

     else

     {

       int attempts = 0;

       int a_cnt=10;

       int result =0;

       while((attempts<a_cnt) && !IsStopped())

        {

         result=CopyRates(SecSymb,Period(),0,1,rates);

         if(result>0) break;

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

           {

            result=1;

            result=0;

           }

         attempts++;

        }

        if(result>0)

        {

          if(time[0]==rates[0].time)

          {

           Buffer1[0]= rates[0].open;

           Buffer2[0] = rates[0].high;

           Buffer3[0] = rates[0].low;

           Buffer4[0] = rates[0].close;

         }

        }

        else

        {

          Alert("0==K5 B8:0 =5 A:>?8@>20=K!");

        }

     }

   double s_last=SymbolInfoDouble(SecSymb,SYMBOL_LAST);

   IndicatorSetDouble(INDICATOR_LEVELVALUE,s_last);

   LastBuffer[0]=s_last;

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