Updated for ver. 3.18 - added new indicators

This commit is contained in:
Artur
2021-07-28 21:42:13 +02:00
parent 419ea51fca
commit ee4a0d0cec
76 changed files with 347 additions and 32 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -15,6 +15,7 @@
double InpBarSize = 180; // Range bar size
ENUM_BAR_SIZE_CALC_MODE InpBarSizeCalcMode = BAR_SIZE_ABSOLUTE_TICKS; // Bar size calculation
int InpShowNumberOfDays = 7; // Show history for number of days
datetime InpShowFromDate = 0; // Show history starting from
ENUM_TIMEFRAMES InpAtrTimeFrame = PERIOD_D1; // ATR timeframe setting
int InpAtrPeriod = 14; // ATR period setting
ENUM_BOOL InpResetOpenOnNewTradingDay = true; // Synchronize first bar's open on new day
@@ -24,6 +25,7 @@
input double InpBarSize = 100; // Range bar size
input ENUM_BAR_SIZE_CALC_MODE InpBarSizeCalcMode = BAR_SIZE_ABSOLUTE_TICKS;// Bar size calculation
input int InpShowNumberOfDays = 5; // Show history for number of days
input datetime InpShowFromDate = 0; // Show history starting from
input group "### ATR bar size calculation settings"
input ENUM_TIMEFRAMES InpAtrTimeFrame = PERIOD_D1; // ATR timeframe setting
input int InpAtrPeriod = 14; // ATR period setting
@@ -35,6 +37,7 @@
double InpBarSize = 180; // Range bar size
ENUM_BAR_SIZE_CALC_MODE InpBarSizeCalcMode = BAR_SIZE_ABSOLUTE_TICKS;// Bar size calculation
int InpShowNumberOfDays = 7; // Show history for number of days
datetime InpShowFromDate = 0; // Show history starting from
ENUM_TIMEFRAMES InpAtrTimeFrame = PERIOD_D1; // ATR timeframe setting
int InpAtrPeriod = 14; // ATR period setting
ENUM_BOOL InpResetOpenOnNewTradingDay = true; // Synchronize first bar's open on new day
@@ -57,6 +60,7 @@ struct RANGEBAR_SETTINGS
ENUM_TIMEFRAMES atrTimeFrame;
int atrPeriod;
int showNumberOfDays;
datetime showFromDate;
ENUM_BOOL resetOpenOnNewTradingDay;
};
@@ -109,6 +113,7 @@ void CRangeBarCustomChartSettigns::SetCustomChartSettings()
settings.barSize = InpBarSize;
settings.barSizeCalcMode = InpBarSizeCalcMode;
settings.showNumberOfDays = InpShowNumberOfDays;
settings.showFromDate = InpShowFromDate;
settings.atrTimeFrame = InpAtrTimeFrame;
settings.atrPeriod = InpAtrPeriod;
settings.resetOpenOnNewTradingDay = InpResetOpenOnNewTradingDay;
+2 -2
View File
@@ -199,6 +199,7 @@ int RangeBars::Init()
s.barSize,
s.barSizeCalcMode,
s.showNumberOfDays,
s.showFromDate,
"=",
s.atrTimeFrame,
s.atrPeriod,
@@ -242,8 +243,7 @@ int RangeBars::Init()
cis.ChannelAppliedPrice,
cis.ChannelMultiplier,
cis.ChannelBandsDeviations,
cis.ChannelPriceLabel,
cis.ChannelMidPriceLabel,
cis.ChannelPriceLabels,
"=",
true); // used in EA
// TopBottomPaddingPercentage,
+125 -8
View File
@@ -1,5 +1,6 @@
//
// Copyright 2018-19, Artur Zas
// Copyright 2018-2021, Artur Zas
// GNU General Public License v3.0 -> https://github.com/9nix6/Median-and-Turbo-Renko-indicator-bundle/blob/master/LICENSE
// https://www.az-invest.eu
// https://www.mql5.com/en/users/arturz
//
@@ -8,46 +9,100 @@ class CTimeControl
{
private:
int scheduleID;
int startHH;
int startMM;
string start;
datetime startOfSession;
int endHH;
int endMM;
string end;
datetime endOfSession;
bool scheduleEnabled;
public:
CTimeControl(int id = 0) { scheduleID = id; };
void SetValidTraingHours(string _from = "0:00", string _to = "0:00");
void SetValidTraingHours(bool _unused, string _timeSpan = "0:00-0:00");
bool IsTradingTimeValid();
bool IsScheduleEnabled() { return scheduleEnabled; };
void UpdateSessionDateTime(int addSecods = 0);
datetime GetSessionStartTime() { return startOfSession; };
datetime GetSessionEndTime() { return endOfSession; };
void MoveSessionStartToNow();
string ToString();
private:
void StringToHHMM(string value, int &HH, int &MM);
bool StringToHHMMRange(string value, int &startHH, int &startMM, string& _start, int &endHH, int &endMM, string& _end);
void SetScheduleState();
};
void CTimeControl::SetValidTraingHours(string _from,string _to)
void CTimeControl::SetValidTraingHours(string _from, string _to)
{
this.start = _from;
this.end = _to;
StringToHHMM(this.start, this.startHH, this.startMM);
StringToHHMM(this.end, this.endHH, this.endMM);
UpdateSessionDateTime();
if(this.startHH == 0 && this.startMM == 0 && this.endHH == 0 && this.endMM == 0)
SetScheduleState();
}
void CTimeControl::MoveSessionStartToNow()
{
datetime now = TimeCurrent();
MqlDateTime temp;
TimeToStruct(now,temp);
startHH = temp.hour;
startMM = temp.min;
start = StringFormat("%02d:%02d", startHH, startMM);
UpdateSessionDateTime(temp.sec + 1);
}
void CTimeControl::UpdateSessionDateTime(int addSecods = 0)
{
datetime now = TimeCurrent();
MqlDateTime temp;
TimeToStruct(now,temp);
if(addSecods > 0)
{
scheduleEnabled = false;
string startTimeTemp = StringFormat("%s:%02d", this.start, addSecods);
startOfSession = StringToTime((string)temp.year+"."+(string)temp.mon+"."+(string)temp.day+" "+startTimeTemp);
}
else
{
scheduleEnabled = true;
startOfSession = StringToTime((string)temp.year+"."+(string)temp.mon+"."+(string)temp.day+" "+this.start);
}
endOfSession = StringToTime((string)temp.year+"."+(string)temp.mon+"."+(string)temp.day+" "+this.end);
}
void CTimeControl::SetValidTraingHours(bool _unused, string _timeSpan = "0:00-0:00")
{
if(!StringToHHMMRange(_timeSpan, this.startHH, this.startMM, this.start, this.endHH, this.endMM, this.end))
return;
UpdateSessionDateTime();
SetScheduleState();
}
bool CTimeControl::IsTradingTimeValid()
{
if(scheduleEnabled == false)
return true;
return true;
datetime now = TimeCurrent();
@@ -57,12 +112,32 @@ bool CTimeControl::IsTradingTimeValid()
datetime _start = StringToTime((string)temp.year+"."+(string)temp.mon+"."+(string)temp.day+" "+this.start);
datetime _end = StringToTime((string)temp.year+"."+(string)temp.mon+"."+(string)temp.day+" "+this.end);
if((now >= _start) && (now <= _end))
if(_start <= now && now <= _end)
return true;
else
return false;
}
string CTimeControl::ToString()
{
string tradingScheduleName = "Trading schedule ";
tradingScheduleName += (scheduleID != 0)
? (string)scheduleID+" "
: "";
if(IsScheduleEnabled())
{
return tradingScheduleName+"ON ("+this.start+" to "+this.end+") | trading "+(IsTradingTimeValid()
? "enabled"
: "disabled");
}
else
{
return tradingScheduleName+"NOT USED";
}
}
void CTimeControl::StringToHHMM(string value, int &HH, int &MM)
{
MqlDateTime temp;
@@ -73,4 +148,46 @@ void CTimeControl::StringToHHMM(string value, int &HH, int &MM)
HH = temp.hour;
MM = temp.min;
}
}
bool CTimeControl::StringToHHMMRange(string value, int &_startHH, int &_startMM, string& _start, int &_endHH, int &_endMM, string& _end)
{
string result[];
int count = StringSplit(value, '-', result);
if(count != 2)
return false;
MqlDateTime temp;
TimeToStruct(TimeCurrent(),temp);
// Start time
_start = result[0];
datetime fullDateTime = StringToTime((string)temp.year+"."+(string)temp.mon+"."+(string)temp.day+" "+_start);
TimeToStruct(fullDateTime,temp);
startHH = temp.hour;
startMM = temp.min;
// End time
TimeToStruct(TimeCurrent(),temp);
_end = result[1];
fullDateTime = StringToTime((string)temp.year+"."+(string)temp.mon+"."+(string)temp.day+" "+_end);
TimeToStruct(fullDateTime,temp);
endHH = temp.hour;
endMM = temp.min;
return true;
}
void CTimeControl::SetScheduleState()
{
if(this.startHH == 0 && this.startMM == 0 && this.endHH == 0 && this.endMM == 0)
{
scheduleEnabled = false;
}
else
{
scheduleEnabled = true;
}
}
+1
View File
@@ -1,5 +1,6 @@
//
// Copyright 2017-2021, Artur Zas
// GNU General Public License v3.0 -> https://github.com/9nix6/Median-and-Turbo-Renko-indicator-bundle/blob/master/LICENSE
// https://www.az-invest.eu
// https://www.mql5.com/en/users/arturz
//
+1
View File
@@ -1,5 +1,6 @@
//
// Copyright 2018-2021, Artur Zas
// GNU General Public License v3.0 -> https://github.com/9nix6/Median-and-Turbo-Renko-indicator-bundle/blob/master/LICENSE
// https://www.az-invest.eu
// https://www.mql5.com/en/users/arturz
//
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -45,7 +45,7 @@ void OnInit()
//---
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpAtrPeriod);
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,Inp_AtrPeriod);
//--- name for DataWindow and indicator subwindow label
string short_name="ATR("+string(ExtPeriodATR)+")";
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+169
View File
@@ -0,0 +1,169 @@
//+------------------------------------------------------------------+
//| BB.mq5 |
//| Copyright 2009-2020, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2020, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Bollinger Bands"
#include <MovingAverages.mqh>
#include <AZ-INVEST/CustomBarConfig.mqh>
//---
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots 3
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
#property indicator_type2 DRAW_LINE
#property indicator_color2 LightSeaGreen
#property indicator_type3 DRAW_LINE
#property indicator_color3 LightSeaGreen
#property indicator_label1 "Bands middle"
#property indicator_label2 "Bands upper"
#property indicator_label3 "Bands lower"
//--- input parametrs
input int InpBandsPeriod=20; // Period
input int InpBandsShift=0; // Shift
input double InpBandsDeviations=2.0; // Deviation
input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE; // Applied price
//--- global variables
int ExtBandsPeriod,ExtBandsShift;
double ExtBandsDeviations;
int ExtPlotBegin=0;
//--- indicator buffer
double ExtMLBuffer[];
double ExtTLBuffer[];
double ExtBLBuffer[];
double ExtStdDevBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input values
if(InpBandsPeriod<2)
{
ExtBandsPeriod=20;
PrintFormat("Incorrect value for input variable InpBandsPeriod=%d. Indicator will use value=%d for calculations.",InpBandsPeriod,ExtBandsPeriod);
}
else
ExtBandsPeriod=InpBandsPeriod;
if(InpBandsShift<0)
{
ExtBandsShift=0;
PrintFormat("Incorrect value for input variable InpBandsShift=%d. Indicator will use value=%d for calculations.",InpBandsShift,ExtBandsShift);
}
else
ExtBandsShift=InpBandsShift;
if(InpBandsDeviations==0.0)
{
ExtBandsDeviations=2.0;
PrintFormat("Incorrect value for input variable InpBandsDeviations=%f. Indicator will use value=%f for calculations.",InpBandsDeviations,ExtBandsDeviations);
}
else
ExtBandsDeviations=InpBandsDeviations;
//--- define buffers
SetIndexBuffer(0,ExtMLBuffer);
SetIndexBuffer(1,ExtTLBuffer);
SetIndexBuffer(2,ExtBLBuffer);
SetIndexBuffer(3,ExtStdDevBuffer,INDICATOR_CALCULATIONS);
//--- set index labels
PlotIndexSetString(0,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Middle");
PlotIndexSetString(1,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Upper");
PlotIndexSetString(2,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Lower");
//--- indicator name
IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands");
//--- indexes draw begin settings
ExtPlotBegin=ExtBandsPeriod-1;
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod);
//--- indexes shift settings
PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift);
PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift);
PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift);
//--- number of digits of indicator value
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
customChartIndicator.SetUseAppliedPriceFlag(InpAppliedPrice);
}
//+------------------------------------------------------------------+
//| Bollinger Bands |
//+------------------------------------------------------------------+
/*
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
*/
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[])
{
static int begin = 0;
if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close))
return(0);
if(!customChartIndicator.BufferSynchronizationCheck(close))
return(0);
int _prev_calculated = customChartIndicator.GetPrevCalculated();
int _rates_total = ArraySize(customChartIndicator.Close);
if(_rates_total<ExtPlotBegin)
return(0);
//--- indexes draw begin settings, when we've recieved previous begin
if(ExtPlotBegin!=ExtBandsPeriod+begin)
{
ExtPlotBegin=ExtBandsPeriod+begin;
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPlotBegin);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtPlotBegin);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtPlotBegin);
}
//--- starting calculation
int pos;
if(_prev_calculated>1)
pos=_prev_calculated-1;
else
pos=0;
//--- main cycle
for(int i=pos; i<_rates_total && !IsStopped(); i++)
{
//--- middle line
ExtMLBuffer[i]=SimpleMA(i,ExtBandsPeriod,customChartIndicator.Price);
//--- calculate and write down StdDev
ExtStdDevBuffer[i]=StdDev_Func(i,customChartIndicator.Price,ExtMLBuffer,ExtBandsPeriod);
//--- upper line
ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i];
//--- lower line
ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i];
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| Calculate Standard Deviation |
//+------------------------------------------------------------------+
double StdDev_Func(const int position,const double &price[],const double &ma_price[],const int period)
{
double std_dev=0.0;
//--- calcualte StdDev
if(position>=period)
{
for(int i=0; i<period; i++)
std_dev+=MathPow(price[position-i]-ma_price[position],2.0);
std_dev=MathSqrt(std_dev/period);
}
//--- return calculated value
return(std_dev);
}
//+------------------------------------------------------------------+
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -16,10 +16,10 @@
#property indicator_color1 clrDodgerBlue, clrOrangeRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
#property indicator_label1 "GHL (13, SMMA)"
#property indicator_label1 "GHL_SSL"
//--- input parameters
input uint InpPeriod=13; // Period
input ENUM_MA_METHOD InpMethod=MODE_SMMA;// Method
input uint InpPeriod=10; // Period
input ENUM_MA_METHOD InpMethod=MODE_SMA;// Method
//--- buffers
double GannBuffer[];
double ColorBuffer[];
@@ -27,12 +27,12 @@ double MaHighBuffer[];
double MaLowBuffer[];
double TrendBuffer[];
//--- global vars
int ma_high_handle;
int ma_low_handle;
int period;
//int ma_high_handle;
//int ma_low_handle;
int _period;
//
#include <MovingAverages.mqh>
#include <AZ-INVEST/CustomBarConfig.mqh>
//
@@ -43,7 +43,7 @@ int period;
int OnInit()
{
//--- check period
period=(int)fmax(InpPeriod,2);
_period=(int)fmax(InpPeriod,2);
//--- set buffers
SetIndexBuffer(0,GannBuffer);
SetIndexBuffer(1,ColorBuffer,INDICATOR_COLOR_INDEX);
@@ -57,19 +57,19 @@ int OnInit()
ArraySetAsSeries(MaLowBuffer,true);
ArraySetAsSeries(TrendBuffer,true);
//--- get handles
ma_high_handle=iMA(NULL,0,period,0,InpMethod,PRICE_HIGH);
ma_low_handle =iMA(NULL,0,period,0,InpMethod,PRICE_LOW);
if(ma_high_handle==INVALID_HANDLE || ma_low_handle==INVALID_HANDLE)
{
Print("Unable to create handle for iMA");
return(INIT_FAILED);
}
//ma_high_handle=iMA(NULL,0,_period,0,InpMethod,PRICE_HIGH);
//ma_low_handle =iMA(NULL,0,_period,0,InpMethod,PRICE_LOW);
//if(ma_high_handle==INVALID_HANDLE || ma_low_handle==INVALID_HANDLE)
// {
// Print("Unable to create handle for iMA");
// return(INIT_FAILED);
// }
//--- set indicator properties
string short_name=StringFormat("Gann High-Low Activator SSL (%u, %s)",period,StringSubstr(EnumToString(InpMethod),5));
string short_name=StringFormat("Gann High-Low Activator SSL (%u, %s)",_period,StringSubstr(EnumToString(InpMethod),5));
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- set label
short_name=StringFormat("GHL (%u, %s)",period,StringSubstr(EnumToString(InpMethod),5));
short_name=StringFormat("GHL (%u, %s)",_period,StringSubstr(EnumToString(InpMethod),5));
PlotIndexSetString(0,PLOT_LABEL,short_name);
//--- done
return(INIT_SUCCEEDED);
@@ -89,7 +89,7 @@ int OnCalculate(const int rates_total,
const int &spread[])
{
if(rates_total<period+1)return(0);
//if(rates_total<_period+1)return(0);
//
// Process data through MedianRenko indicator
@@ -135,7 +135,7 @@ int OnCalculate(const int rates_total,
int limit;
if(rates_total<_prev_calculated || _prev_calculated<=0)
{
limit=rates_total-period-1;
limit=rates_total-_period-1;
ArrayInitialize(GannBuffer,EMPTY_VALUE);
ArrayInitialize(ColorBuffer,0);
ArrayInitialize(MaHighBuffer,0);
@@ -145,8 +145,30 @@ int OnCalculate(const int rates_total,
else
limit=rates_total-_prev_calculated;
//--- get MA
if(CopyBuffer(ma_high_handle,0,0,limit+1,MaHighBuffer)!=limit+1)return(0);
if(CopyBuffer(ma_low_handle,0,0,limit+1,MaLowBuffer)!=limit+1)return(0);
//if(CopyBuffer(ma_high_handle,0,0,limit+1,MaHighBuffer)!=limit+1)return(0);
//if(CopyBuffer(ma_low_handle,0,0,limit+1,MaLowBuffer)!=limit+1)return(0);
switch(InpMethod)
{
case MODE_SMA:
SimpleMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.High, MaHighBuffer);
SimpleMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.Low, MaLowBuffer);
break;
case MODE_EMA:
ExponentialMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.High, MaHighBuffer);
ExponentialMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.Low, MaLowBuffer);
break;
case MODE_SMMA:
SmoothedMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.High, MaHighBuffer);
SmoothedMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.Low, MaLowBuffer);
break;
case MODE_LWMA:
LinearWeightedMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.High, MaHighBuffer);
LinearWeightedMAOnBuffer(rates_total, _prev_calculated, 0, _period, customChartIndicator.Low, MaLowBuffer);
break;
}
//--- main cycle
for(int i=limit; i>=0 && !_StopFlag; i--)
{
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.