AbsCandleTicks

Author: SnowBars
0 Views
0 Downloads
0 Favorites
AbsCandleTicks
//+------------------------------------------------------------------+
//|                                               AbsCandleTicks.mq4 |
//|                                                         SnowBars |
//|                           https://www.mql5.com/ru/users/snowbars |
//+------------------------------------------------------------------+
#property copyright "SnowBars"
#property link      "https://www.mql5.com/ru/users/snowbars"
#property version   "1.00"
#property strict
enum type {Chart,Lines};
input type TypeDraw=Chart;// Drawing type
int u,f;
double Abs,AbsTick;
string MQL_name;
datetime T;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   T=Time[0];
   MQL_name=MQLInfoString(MQL_PROGRAM_NAME);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectsDeleteAll(0,MQL_name);
  }  
//+------------------------------------------------------------------+
//| Expert Tick function                                   
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(Time[0]!=T)
     {
      T=Time[0];
      u=0;Abs=0;f=1;
      if(AbsTick==0){AbsTick=Low[1]+((High[1]-Low[1])/2);}
      DrawTrandLine(TimeToString(T),Time[1],AbsTick,T,AbsTick);
     }
//---      
   if(f==1)
     {
      u++;
      Abs+=Bid;
      AbsTick=Abs/u;
      AbsTick=NormalizeDouble(AbsTick,_Digits);
      if(TypeDraw==1){DrawTrandLine(TimeToString(T),Time[1],AbsTick,(T+(_Period*60)),AbsTick);}
      if(TypeDraw==0){DrawTrandLine(TimeToString(T),Time[1],AbsTick,T,AbsTick);}
     }
   ChartRedraw();
  }
//+------------------------------------------------------------------+
//| Expert Draw Trand Line function                                   
//+------------------------------------------------------------------+
void DrawTrandLine(string name,datetime t1,double p1,datetime t2,double p2,color clr=clrRed,int scale=1,int STYLE=STYLE_SOLID,bool SELECTABLE=false,bool SELECTED=false,bool HIDDEN=false,int sub_window=0)
  {
   name=MQL_name+name;
   if(ObjectFind(0,name)<0)
     {
      ObjectCreate(0,name,OBJ_TREND,sub_window,t1,p1,t2,p2);
      ObjectSetInteger(0,name,OBJPROP_BACK,false);
      ObjectSetInteger(0,name,OBJPROP_RAY,true);
      ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE);
      ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
      ObjectSetInteger(0,name,OBJPROP_WIDTH,scale);
      ObjectSetInteger(0,name,OBJPROP_HIDDEN,HIDDEN);
      ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,false);
      ObjectSetInteger(0,name,OBJPROP_SELECTABLE,SELECTABLE);
      ObjectSetInteger(0,name,OBJPROP_SELECTED,SELECTED);
     }
   else
     {
      if(TypeDraw==1){ObjectMove(0,name,0,t1,p1);}
      ObjectMove(0,name,1,t2,p2);
      ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
      ObjectSetInteger(0,name,OBJPROP_WIDTH,scale);
      ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE);
     }
  }
//+------------------------------------------------------------------+

Comments