//+------------------------------------------------------------------+ //| CustomTimeframe.mq4 | //| when-money-makes-money.com | //| when-money-makes-money.com | //+------------------------------------------------------------------+ #property copyright "when-money-makes-money.com" #property link "when-money-makes-money.com" #property indicator_chart_window #property indicator_buffers 8 #property indicator_color1 Black #property indicator_color2 Black #property indicator_color3 Red #property indicator_color4 Blue #property indicator_color5 Red #property indicator_color6 Red #property indicator_color7 Red #property indicator_color8 Red //---- buffers double open[]; double close[]; double high[]; double low[]; double ExtMapBuffer5[]; double ExtMapBuffer6[]; double ExtMapBuffer7[]; double ExtMapBuffer8[]; extern int MaxHistory=200; extern int TimeInSeconds=5; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ double a.open[]; double a.close[]; double a.high[]; double a.low[]; int init() { //---- indicators SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexBuffer(0,high); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexBuffer(1,low); SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,5); SetIndexBuffer(2,open); SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,5); SetIndexBuffer(3,close); SetIndexStyle(4,DRAW_LINE); SetIndexBuffer(4,ExtMapBuffer5); SetIndexStyle(5,DRAW_LINE); SetIndexBuffer(5,ExtMapBuffer6); SetIndexStyle(6,DRAW_LINE); SetIndexBuffer(6,ExtMapBuffer7); SetIndexStyle(7,DRAW_LINE); SetIndexBuffer(7,ExtMapBuffer8); ArrayResize(a.high,MaxHistory); ArrayResize(a.low,MaxHistory); ArrayResize(a.open,MaxHistory); ArrayResize(a.close,MaxHistory); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void redraw(){ for(int i=200;i>=0;i--){ if(i==200){ open[i]=0; close[i]=0; high[i]=0; low[i]=0; }else{ open[i]=a.open[i]; close[i]=a.close[i]; high[i]=a.high[i]; low[i]=a.low[i]; } } } void shift(){ for(int i=200;i>0;i--){ a.open[i]=a.open[i-1]; a.close[i]=a.close[i-1]; a.high[i]=a.high[i-1]; a.low[i]=a.low[i-1]; } } extern int sleep=100; int start() { int counted_bars=IndicatorCounted(); //---- bool running=true; static double price=0; static int t=0; static datetime t.r=0; static bool updates=false; //t=TimeCurrent(); //while(running){ updates=false; if(TimeCurrent()>(t+TimeInSeconds)){ shift(); if(a.open[1]==EMPTY || a.open[1]==EMPTY_VALUE || a.open[1]==0){ a.open[0]=Bid; a.close[0]=Bid; a.high[0]=Bid; a.low[0]=Bid; }else{ a.open[0]=a.close[1]; a.high[0]=a.close[1]; a.low[0]=a.close[1]; a.close[0]=a.close[1]; } Print("shift "+a.open[0]+" - "+a.open[1]); updates=true; t=TimeCurrent(); } if(price!=Bid){ price=Bid; a.close[0]=price; a.high[0]=MathMax(price,a.high[0]); a.low[0]=MathMin(price,a.low[0]); updates=true; } if(Time[0]!=t.r){ t.r=Time[0]; redraw(); }else{ if(updates){ redraw(); } } if(IsStopped()) running=false; // Sleep(sleep); //} //---- return(0); } //+------------------------------------------------------------------+