AlligatorAndStochastic/AlligatorAndStochastic histogram.mq5
super.admin db3307fa1e convert
2025-05-30 14:39:55 +02:00

137 lines
14 KiB
MQL5

//+------------------------------------------------------------------+
//| AlligatorAndStochastic histogram.mq5 |
//| Copyright © 2018, Vladimir Karputov |
//| http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2018, Vladimir Karputov"
#property link "http://wmua.ru/slesar/"
#property version "1.001"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_HISTOGRAM
#property indicator_color1 clrMediumPurple,clrNONE,clrLawnGreen
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
double Color_HistogramBuffer[]; // a buffer of values
double Color_HistogramColors[]; // a buffer of color indexes
//--- input parameters
input int Inp_Alligator_jaw_period = 13; // Alligator: period for the calculation of jaws
input int Inp_Alligator_jaw_shift = 8; // Alligator: horizontal shift of jaws
input int Inp_Alligator_teeth_period = 8; // Alligator: period for the calculation of teeth
input int Inp_Alligator_teeth_shift = 5; // Alligator: horizontal shift of teeth
input int Inp_Alligator_lips_period = 5; // Alligator: period for the calculation of lips
input int Inp_Alligator_lips_shift = 3; // Alligator: horizontal shift of lips
input ENUM_MA_METHOD Inp_Alligator_ma_method = MODE_SMMA; // Alligator: type of smoothing
input ENUM_APPLIED_PRICE Inp_Alligator_applied_price= PRICE_MEDIAN;// Alligator: type of price
//---
input int Inp_Stochastic_Kperiod = 5; // Stochastic: K-period (number of bars for calculations)
input int Inp_Stochastic_Dperiod = 3; // Stochastic: D-period (period of first smoothing)
input int Inp_Stochastic_slowing = 3; // Stochastic: final smoothing
input ENUM_MA_METHOD Inp_Stochastic_ma_method = MODE_SMA; // Stochastic: type of smoothing
input ENUM_STO_PRICE Inp_Stochastic_price_field = STO_LOWHIGH; // Stochastic: stochastic calculation method
//---
input datetime Inp_time_open_start = D'1970.01.01 08:59:00'; // Time to open positions start
input datetime Inp_time_open_end = D'1970.01.01 10:59:00'; // Time to open positions end
input datetime Inp_time_close_start = D'1970.01.01 19:59:00'; // Time to close positions start
input datetime Inp_time_close_end = D'1970.01.01 21:59:00'; // Time to close positions end
//---
MqlDateTime SOpenStart;
MqlDateTime SOpenEnd;
MqlDateTime SCloseStart;
MqlDateTime SCloseEnd;
long open_start;
long open_end;
long close_start;
long close_end;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- check input parameters
TimeToStruct(Inp_time_open_start,SOpenStart);
TimeToStruct(Inp_time_open_end,SOpenEnd);
TimeToStruct(Inp_time_close_start,SCloseStart);
TimeToStruct(Inp_time_close_end,SCloseEnd);
open_start = SOpenStart.hour*3600+SOpenStart.min*60+SOpenStart.sec;
open_end = SOpenEnd.hour*3600+SOpenEnd.min*60+SOpenEnd.sec;
close_start = SCloseStart.hour*3600+SCloseStart.min*60+SCloseStart.sec;
close_end = SCloseEnd.hour*3600+SCloseEnd.min*60+SCloseEnd.sec;
if(open_start>=open_end)
{
Print(__FUNCTION__,
" ERROR: \"Time to open positions start\" (",TimeToString(Inp_time_open_start,TIME_SECONDS),
") >= \"Time to open positions end\" (",TimeToString(Inp_time_open_end,TIME_SECONDS),")");
return(INIT_PARAMETERS_INCORRECT);
}
if(close_start>=close_end)
{
Print(__FUNCTION__,
" ERROR: \"Time to close positions start\" (",TimeToString(Inp_time_close_start,TIME_SECONDS),
") >= \"Time to close positions end\" (",TimeToString(Inp_time_close_end,TIME_SECONDS),")");
return(INIT_PARAMETERS_INCORRECT);
}
if(open_end>=close_start)
{
Print(__FUNCTION__,
" ERROR: \"Time to open positions end\" (",TimeToString(Inp_time_open_end,TIME_SECONDS),
") >= \"Time to close positions start\" (",TimeToString(Inp_time_close_start,TIME_SECONDS),")");
return(INIT_PARAMETERS_INCORRECT);
}
//--- print time's
Print("\"Time to open positions start\": ",TimeToString(Inp_time_open_start,TIME_SECONDS));
Print("\"Time to open positions end\" : ",TimeToString(Inp_time_open_end,TIME_SECONDS));
Print("\"Time to close positions start\": ",TimeToString(Inp_time_close_start,TIME_SECONDS));
Print("\"Time to close positions end\" : ",TimeToString(Inp_time_close_end,TIME_SECONDS));
Print("//---");
//--- indicator buffers mapping
SetIndexBuffer(0,Color_HistogramBuffer,INDICATOR_DATA);
SetIndexBuffer(1,Color_HistogramColors,INDICATOR_COLOR_INDEX);
IndicatorSetInteger(INDICATOR_DIGITS,0);
//---
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=prev_calculated-1;
if(prev_calculated==0)
limit=0;
MqlDateTime STime;
for(int i=limit;i<rates_total;i++)
{
TimeToStruct(time[i],STime);
long long_time=STime.hour*3600+STime.min*60+STime.sec;
if(open_start<=long_time && long_time<=open_end)
{
Color_HistogramBuffer[i]=1.0;
Color_HistogramColors[i]=0;
}
if(open_end<long_time && long_time<close_start)
{
Color_HistogramBuffer[i]=0.0;
Color_HistogramColors[i]=1;
}
if(close_start<=long_time && long_time<=close_end)
{
Color_HistogramBuffer[i]=-1.0;
Color_HistogramColors[i]=2;
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+