Volum_Up_Dw_05

Author: Inkov Evgeni ew123@mail.ru
Price Data Components
Series array that contains the highest prices of each barSeries array that contains open prices of each barSeries array that contains close prices for each barSeries array that contains tick volumes of each bar
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
Volum_Up_Dw_05
//+------------------------------------------------------------------+
//|                                               Volum_Up_Dw_05.mq4 |
//+------------------------------------------------------------------+
#property copyright "Inkov Evgeni ew123@mail.ru"
#property link      "+7-918-600-11-33"
//+------------------------------------------------------------------+
#property  indicator_separate_window
#property  indicator_buffers 1
#property  indicator_color1  Black
#property  indicator_width1  1
//.....................................
extern int Min_bar_VL=10;
//.....................................
double   ExtBuffer0[]; 
double   ExtBuffer1[]; 
//.....................................
datetime time_max_Bars_1;
string   VL="VL";
datetime pred_time_VL,Time_VL;
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(2);
   
   SetIndexBuffer(0,ExtBuffer0);
   SetIndexBuffer(1,ExtBuffer1);

   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_NONE);

   IndicatorDigits(0);
   
   SetIndexEmptyValue(0,EMPTY_VALUE);
   SetIndexEmptyValue(1,0);
   
   ArrayInitialize(ExtBuffer0,EMPTY_VALUE);
   ArrayInitialize(ExtBuffer1,0);
   
   IndicatorShortName("Volum_Up_Dw");
   
   ust_VL();   
   
   return(0);
}
//+------------------------------------------------------------------+
int deinit()
{
   if  (UninitializeReason()==REASON_REMOVE)ObjectDelete(VL);
   return(0);
}
//+------------------------------------------------------------------+
int start()
{
   ust_VL();   
   pred_time_VL=Time_VL;
   if (pred_time_VL==0 || pred_time_VL!=Time_VL)
   {
      ArrayInitialize(ExtBuffer0,EMPTY_VALUE);
      ArrayInitialize(ExtBuffer1,0);
   }
   int bar_VL=MathMin(iBarShift(Symbol(),0,Time_VL),Bars-1);

   //------------------------------
   int vol_dw,vol_up,i;
   time_max_Bars_1=iTime(Symbol(),1,iBars(Symbol(),1)-1);
   //------------------------------
   for(i=0; i<=bar_VL; i++)
   {
      vol_dw=Opred_Vol_dw_M1(i);
      if (vol_dw<0)vol_dw=Opred_Vol_dw(i);

      vol_up=Volume[i]-vol_dw;
      ExtBuffer1[i]=vol_dw;
   }
   //------------------------------
   for(i=bar_VL; i>=0; i--)
   {
      if (i==bar_VL)
         ExtBuffer0[i]=Volume[i]-2*ExtBuffer1[i];
      else
         ExtBuffer0[i]=ExtBuffer0[i+1]+Volume[i]-2*ExtBuffer1[i];
   }
   //------------------------------
   return(0);
}
//+------------------------------------------------------------------+
void ust_VL()
{
   if (Min_bar_VL==0)
   {
      if (ObjectFind(VL)<0)ObjectCreate(VL,OBJ_VLINE, 0, Time[10], 0);
      Time_VL=ObjectGet(VL, OBJPROP_TIME1);
   }
   else
   {
      Time_VL=Time[Min_bar_VL];
      ObjectDelete(VL);
   }

}
//+------------------------------------------------------------------+
int Opred_Vol_dw_M1(int n)
{
   datetime time1_bar, time2_bar;
   int bar1, bar2;
   double v,v1,co,hl;

   time1_bar=Time[n];
   if (time1_bar<time_max_Bars_1 || Period()==1)return(-1);
   if (n>0)
      time2_bar=Time[n-1];
   else
      time2_bar=TimeCurrent();
   
   // ïîèñê ïåðâîãî áàðà (áîëåå ðàííåãî)
   bar1 = iBarShift(Symbol(),1,time1_bar);
   datetime time1=iTime(Symbol(),1,bar1);
   if (time1>time2_bar || time1>time1_bar+Period()*60)return(-1);
   
   bar1 = -1;
   while (bar1<0)
   {
      if (time1_bar>time2_bar)return(-1);
      bar1 = iBarShift(Symbol(),1,time1_bar,true);
      time1_bar+=60;
   }  
   if (n>0)
   {
      time2_bar=Time[n-1];
      bar2 = iBarShift(Symbol(),1,time2_bar);
      datetime time2=iTime(Symbol(),1,bar2);
      if (time2<time1_bar || time2>time2_bar+Period()*60)return(-1);
      
      bar2=-1;
      // ïîèñê âòîðîãî áàðà
      while (bar2<0)
      {
         time2_bar-=60;
         if (time2_bar<time1_bar)return(-1);
         bar2= iBarShift(Symbol(),1,time2_bar,true);
      }
   }
   else
      bar2=0;
      
   v=0;
   double op,h,l,o;
   datetime sled;
   if (bar1<bar2)return(-1);
   for (int i=bar1;(i>=bar2) || (n==0 && i==0);i--)
   {
      sled=iTime(Symbol(), 0, i+1);
      if (sled==0)
      {
         h=iHigh(Symbol(),1,i);
         l=iLow (Symbol(),1,i);
         o=iOpen(Symbol(),1,i);
      }
      else
      {
         h=MathMax(iHigh(Symbol(),1,i),iClose(Symbol(),1,i+1));
         l=MathMin(iLow (Symbol(),1,i),iClose(Symbol(),1,i+1));
         o=iClose(Symbol(),1,i+1);
      }
         
      hl = h - l;
      if (hl==0)continue;
      co = iClose(Symbol(),1,i) - o;
      if (co>0)
         v1=iVolume(Symbol(),1,i)*(hl-co)/(2*hl-co);
      else
         if (co<0)
            v1=iVolume(Symbol(),1,i)*hl/(2*hl+co);
         else
            v1=iVolume(Symbol(),1,i)/2.0;
      v1=MathRound(v1);
      v += v1;   
   }
   return(v);
}
//----------------------------------------
int Opred_Vol_dw(int n)
{
   double v,h,l,o;
   
   datetime sled=iTime(Symbol(), 0, n+1);
   if (sled==0)
   {
      h=High [n];
      l=Low [n];
      o=Open[n];
   }
   else
   {
      h=MathMax(High[n],Close[n+1]);
      l=MathMin(Low [n],Close[n+1]);
      o=Close[n+1];
   }
   
   double hl = h - l;
   if (hl==0)return(0);
   
   double co = Close[n] - o;
   if (co>0)
      v=Volume[n]*(hl-co)/(2*hl-co);
   else
      if (co<0)
         v=Volume[n]*hl/(2*hl+co);
      else
         v=Volume[n]/2.0;
   v=MathRound(v);

   return(v);
}
//----------------------------------------

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