//+------------------------------------------------------------------+
//| Binary Time Checker.mq4 |
//| Copyright 2018, Izumov Juriy |
//| https://www.mql5.com/ru/users/tormovies |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, Izumov Juriy"
#property link "https://www.mql5.com/ru/users/tormovies"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots 5
#property indicator_level1 60
#property indicator_level2 -60
#property indicator_color1 clrGreen
#property indicator_color2 clrRed
#property indicator_color3 clrNONE
#property indicator_color4 clrNONE
#property indicator_color5 clrBlack
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width5 2
input int limits = 0; // Day limit (0 = no limit)
double buyplus[], buyminus[], sellplus[], sellminus[], dodji[], buyres[], sellres[];
double bp[], sp[], dj[];
int limBr = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
if(_Period>=PERIOD_D1){ Alert("Maximum TimeFrame - D1"); return(INIT_FAILED); }
IndicatorShortName("Binary Checker");
SetIndexBuffer(0,buyres); // buy %
SetIndexBuffer(1,sellres); // sell %
SetIndexBuffer(2,bp);// proffit buy
SetIndexBuffer(3,sp);// proffit sell
SetIndexBuffer(4,dj);// dodji
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2,indicator_color1);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2,indicator_color2);
SetIndexStyle(2,DRAW_NONE);
SetIndexStyle(3,DRAW_NONE);
SetIndexStyle(4,DRAW_HISTOGRAM,STYLE_SOLID,2,indicator_color5);
SetIndexEmptyValue(0,0);
SetIndexEmptyValue(1,0);
SetIndexEmptyValue(2,0);
SetIndexEmptyValue(3,0);
SetIndexEmptyValue(4,0);
SetIndexLabel(0,"Buy Result");
SetIndexLabel(1,"Sell Result");
SetIndexLabel(4,"Dodji Result");
SetLevelValue(0, indicator_level1);
SetLevelValue(1, indicator_level2);
ArrayResize(buyplus,2400); ArrayResize(buyminus,2400); ArrayResize(sellplus,2400); ArrayResize(sellminus,2400); ArrayResize(dodji,2400);
ArrayInitialize(buyplus, 0); ArrayInitialize(buyminus, 0); ArrayInitialize(sellplus, 0); ArrayInitialize(sellminus, 0); ArrayInitialize(dodji, 0);
limBr = (1440*limits)/(int)_Period;
if(limBr>=Bars(_Symbol,PERIOD_CURRENT)-1){ limBr = Bars(_Symbol,PERIOD_CURRENT)-1; }
//---
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[])
{
//---
int limit;
static datetime lastOpen = 0;
//---
if(rates_total<=1)
return(0);
//--- last counted bar will be recounted
limit=rates_total-prev_calculated;
if(prev_calculated>0)
limit=limit+1;
if(limits>0 && limit>limBr){ limit = limBr; }
for(int x=limit-1; x>=0; x--){
if(lastOpen<Time[x]){
MqlDateTime str;
TimeToStruct(Time[x],str);
int indx = (int)((string)str.hour+""+(string)str.min);
if(buyplus[indx]>0 || sellplus[indx]>0 || dodji[indx]>0){
if(buyplus[indx]>buyminus[indx]){
bp[x] = buyplus[indx]-buyminus[indx];
}
if(sellplus[indx]>sellminus[indx]){
sp[x] = -(sellplus[indx]-sellminus[indx]);
}
buyres[x] = (buyplus[indx]*100)/(buyplus[indx]+sellplus[indx]+dodji[indx]);
sellres[x] = -((sellplus[indx]*100)/(buyplus[indx]+sellplus[indx]+dodji[indx]));
dj[x] = (dodji[indx]*100)/(buyplus[indx]+sellplus[indx]+dodji[indx]);
}
if(Open[x]<Close[x]){
buyplus[indx] = buyplus[indx]+1;
sellminus[indx] = sellminus[indx]+1;
}
if(Open[x]>Close[x]){
sellplus[indx] = sellplus[indx]+1;
buyminus[indx] = buyminus[indx]+1;
}
if(Open[x]==Close[x]){
dodji[indx] = dodji[indx]+1;
}
}
}
lastOpen = Time[0];
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Comments