daily_go_on_graph

Author: �������� ������
Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
daily_go_on_graph
/*
*/

#property copyright "Êëèìåíêî Ñåðãåé"
#property version   "2.00"
#property strict

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_label1  "go_avg_low"
#property indicator_label2  "go_avg_high"
#property indicator_label3  "go_max75_low"
#property indicator_label4  "go_max75_high"
#property indicator_label5  "go_max95_low"
#property indicator_label6  "go_max95_high"

input    int      Depth    =     50,  //ãëóáèíà èñòîðèè â äíÿõ
                  Size     =     15;   //ðàçìåð ãèñòîãðàììû
input    double   Border95 =     95,   //âåðõíÿÿ 95% ãðàíèöà
                  Border75 =     75;   //âåðõíÿÿ 75% ãðàíèöà

bool              redraw_histogram;

double            go_avg_low[],        // ñðåäíèé õîä
                  go_avg_high[],
                  go_max75_low[],      // 75%
                  go_max75_high[],
                  go_max95_low[],      // ìàêñèìàëüíûé õîä
                  go_max95_high[],

                  day_go_array[],      // ìàññèâ äíåâíûõ õîäîâ ãëóáèíîé Depth
                  day_go_histo[],      // ãèñòîãðàììà äíåâíûõ õîäîâ ãëóáèíîé Size

                  step,
                  startup,
                  avg,
                  max95,
                  max75,
                  disp,
                  today_go,
                  int_sum,
                  current_bar_go,
                  x;

int               k,
                  i,
                  top95,
                  top75,
                  scale,
                  today_bar_count;

MqlDateTime       time_full;
MqlRates          current_tf_array[];

datetime          last_midnight;

void day_go_update();

void OnInit()
   {
   //ôèêñèðóåì ìàñøòàá â çàâèñèìîñòè îò êîëè÷åñòâà çíàêîâ â öåíå ïîñëå äåñÿòè÷íîé òî÷êè
   if(Digits == 5) scale = 10000;
   if(Digits == 2) scale = 10;
   if(Digits == 3) scale = 10;
   if (  Symbol() == "USDJPY" ||
         Symbol() == "EURJPY" ||
         Symbol() == "XAGUSD")
         scale = 100;

   SetIndexStyle(    0, DRAW_LINE, STYLE_DOT, 1, clrDimGray);
   SetIndexBuffer(   0, go_avg_low);
   //SetIndexShift(    0, 0);

   SetIndexStyle(    1, DRAW_LINE, STYLE_DOT, 1, clrDimGray);
   SetIndexBuffer(   1, go_avg_high);
   //SetIndexShift(    1, 0);

   SetIndexStyle(    2, DRAW_LINE, STYLE_SOLID, 1, clrMaroon);
   SetIndexBuffer(   2, go_max75_low);
   //SetIndexShift(    2, 0);

   SetIndexStyle(    3, DRAW_LINE, STYLE_SOLID, 1, clrMaroon);
   SetIndexBuffer(   3, go_max75_high);
   //SetIndexShift(    3, 0);

   SetIndexStyle(    4, DRAW_LINE, STYLE_SOLID, 1, clrRed);
   SetIndexBuffer(   4, go_max95_low);
   //SetIndexShift(    4, 0);

   SetIndexStyle(    5, DRAW_LINE, STYLE_SOLID, 1, clrRed);
   SetIndexBuffer(   5, go_max95_high);
   //SetIndexShift(    5, 0);

   ArrayResize(day_go_array, Depth);
   ArrayResize(day_go_histo, Size);
   redraw_histogram = true;
   // íàäî ïåðåðèñîâàòü ãèñòîãðàììó äàëåå íà íîâîì òèêå îäèí ðàç ïðè èíèöèàëèçàöèè
   }


int OnCalculate (const int       rates_total,      // ðàçìåð âõîäíûõ òàéìñåðèé 
                 const int       prev_calculated,  // îáðàáîòàíî áàðîâ íà ïðåäûäóùåì âûçîâå 
                 const datetime  &time[],          // Time 
                 const double    &open[],          // Open 
                 const double    &high[],          // High 
                 const double    &low[],           // Low 
                 const double    &close[],         // Close 
                 const long      &tick_volume[],   // Tick Volume 
                 const long      &volume[],        // Real Volume 
                 const int       &spread[])        // Spread 
   {
//===============================================================================================
   if (redraw_histogram)  
   //ðèñóåì ãèñòîãðàììó îäíàæäû ïðè èíèöèàëèàöèè
      {
      //áåðåì òîëüêî çàêðûòûå äíåâíûå ñâå÷è
      for (i=0; i<Depth; i++) day_go_array[i] = iHigh(NULL,1440,i+1) - iLow(NULL,1440,i+1);

      //ââîäíûå äëÿ ãèñòîãðàììû ðàñïðåäåëåíèÿ
      startup  =  day_go_array[ArrayMinimum( day_go_array,  Depth,   0)];
      step     = (day_go_array[ArrayMaximum( day_go_array,  Depth,   0)]
               -  day_go_array[ArrayMinimum( day_go_array,  Depth,   0)])/Size;

      //âû÷èñëÿåì è çàïîëíÿåì ìàññèâ ãèñòîãðàììû
      top75 = top95 = Size;
      for (k= Size-1; k>=0; k--)
         {
         day_go_histo[k] = 0;
         for (i=0; i<Depth; i++)
            if (((startup+(Size-1-k)*step) <= day_go_array[i])
               && ((startup+(Size-1-k+1)*step) > day_go_array[i]))
               day_go_histo[k]++;
         int_sum = 0;
         for (i=Size-1; i>=k; i--)
            int_sum += day_go_histo[i];
         if ((int_sum/Depth > Border75/100) && top75==15) top75 = k;
         if ( int_sum/Depth > Border95/100)
            {
            top95 = k; // ôèêñèðóåì ãðàíèöó äîâåðèòåëüíîãî èíòåðâàëà;
            break; // ïðåêðàùàåì ñòðîèòü ãèñòîãðàììó
            }
         }
      max75 = startup + (Size - top75) * step;   
      max95 = startup + (Size - top95) * step;   
      avg   = 0;
      for   (i=0; i<Depth; i++) avg += day_go_array[i]/Depth;
      /*Print (
            "avg/max75/max95 = ",   MathRound(avg*scale),
            "/",                    MathRound(max75*scale),
            "/",                    MathRound(max95*scale),
            "; int_sum/Depth = ",   MathRound(int_sum/Depth),
            ">",                    Border95/100,
            "; top75 = ",           top75,
            "; top95 = ",           top95,
            "; startup = ",         MathRound(startup*scale),
            "; step = ",            MathRound(step*scale),
            "; histo[5]= ",         day_go_histo[10],
            "; int_sum = ",         int_sum
            );*/
      redraw_histogram = false;
      day_go_update();
      }
//==============================================================================================   
   if((iHigh(NULL, 1440, 0) - iLow(NULL, 1440, 0)) != today_go)
   // åñëè ðàçìàõ áàðà òåêóùåãî äíÿ óâåëè÷èëñÿ íà íîâîì òèêå    
      {
      day_go_update();
      today_go = (iHigh(NULL, 1440, 0) - iLow(NULL, 1440, 0));
      }
//=======================================NEW.BAR==============================================
   if(rates_total != prev_calculated) day_go_update();
//============================================================================================
   return(rates_total); 
   }//end.OnCalculate

//============================================================================================
void day_go_update()
      {
      // ñòðîèì äèàïàçîí òåêóùåãî äíåâíîãî õîäà
      x                 = (iHigh(NULL, 1440, 0) + iLow(NULL, 1440, 0))/2;    
      go_avg_low[0]     = x - avg/2;
      go_avg_high[0]    = x + avg/2;
      go_max75_low[0]   = x - max75/2;
      go_max75_high[0]  = x + max75/2;
      go_max95_low[0]   = x - max95/2;
      go_max95_high[0]  = x + max95/2;
 
      TimeCurrent(time_full);
      time_full.hour       = 0;
      time_full.min        = 0;
      time_full.sec        = 0;
      last_midnight        = StructToTime(time_full);
      today_bar_count      = CopyRates(NULL,
                                       Period(),
                                       last_midnight,
                                       TimeCurrent(),
                                       current_tf_array);

      for(i=1; i<=PERIOD_D1/Period()*4; i++)
         {
         go_avg_low[i]     = EMPTY_VALUE;
         go_avg_high[i]    = EMPTY_VALUE;
         go_max75_low[i]   = EMPTY_VALUE;
         go_max75_high[i]  = EMPTY_VALUE;
         go_max95_low[i]   = EMPTY_VALUE;
         go_max95_high[i]  = EMPTY_VALUE;
         }
      for(i=1; i<today_bar_count; i++)
         {
         go_avg_low[i]     = go_avg_low[0];
         go_avg_high[i]    = go_avg_high[0];
         go_max75_low[i]   = go_max75_low[0];
         go_max75_high[i]  = go_max75_high[0];
         go_max95_low[i]   = go_max95_low[0];
         go_max95_high[i]  = go_max95_high[0];
         }
      }

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