backup all works even x121 ...
This commit is contained in:
@@ -0,0 +1,194 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom.mqh |
|
||||
//| Copyright 2000-2024, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#include "Indicator.mqh"
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class CiCustom. |
|
||||
//| Purpose: Class of custom indicators. |
|
||||
//| Derives from class CIndicator. |
|
||||
//+------------------------------------------------------------------+
|
||||
class CiCustom : public CIndicator
|
||||
{
|
||||
protected:
|
||||
int m_num_params; // number of creation parameters
|
||||
MqlParam m_params[]; // creation parameters
|
||||
|
||||
public:
|
||||
CiCustom(void);
|
||||
~CiCustom(void);
|
||||
//--- methods of access to protected data
|
||||
bool NumBuffers(const int buffers);
|
||||
int NumParams(void) const { return(m_num_params); }
|
||||
ENUM_DATATYPE ParamType(const int ind) const;
|
||||
long ParamLong(const int ind) const;
|
||||
double ParamDouble(const int ind) const;
|
||||
string ParamString(const int ind) const;
|
||||
//--- method of identifying
|
||||
virtual int Type(void) const { return(IND_CUSTOM); }
|
||||
|
||||
protected:
|
||||
//--- methods of tuning
|
||||
virtual bool Initialize(const string symbol,const ENUM_TIMEFRAMES period,const int num_params,const MqlParam ¶ms[]);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CiCustom::CiCustom(void) : m_num_params(0)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CiCustom::~CiCustom(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Set number of buffers of indicator |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CiCustom::NumBuffers(const int buffers)
|
||||
{
|
||||
bool result=true;
|
||||
//---
|
||||
if(m_buffers_total==0)
|
||||
{
|
||||
m_buffers_total=buffers;
|
||||
return(true);
|
||||
}
|
||||
if(m_buffers_total!=buffers)
|
||||
{
|
||||
Shutdown();
|
||||
result=CreateBuffers(m_symbol,m_period,buffers);
|
||||
if(result)
|
||||
{
|
||||
//--- create buffers
|
||||
for(int i=0;i<m_buffers_total;i++)
|
||||
((CIndicatorBuffer*)At(i)).Name("LINE "+IntegerToString(i));
|
||||
}
|
||||
}
|
||||
//---
|
||||
return(result);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Get type of specified parameter of creation |
|
||||
//+------------------------------------------------------------------+
|
||||
ENUM_DATATYPE CiCustom::ParamType(const int ind) const
|
||||
{
|
||||
if(ind>=m_num_params)
|
||||
return(WRONG_VALUE);
|
||||
//---
|
||||
return(m_params[ind].type);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Get specified parameter of creatiob as a long value |
|
||||
//+------------------------------------------------------------------+
|
||||
long CiCustom::ParamLong(const int ind) const
|
||||
{
|
||||
if(ind>=m_num_params)
|
||||
return(0);
|
||||
switch(m_params[ind].type)
|
||||
{
|
||||
case TYPE_DOUBLE:
|
||||
case TYPE_FLOAT:
|
||||
case TYPE_STRING:
|
||||
return(0);
|
||||
}
|
||||
//---
|
||||
return(m_params[ind].integer_value);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Get specified parameter of creation as a double value |
|
||||
//+------------------------------------------------------------------+
|
||||
double CiCustom::ParamDouble(const int ind) const
|
||||
{
|
||||
if(ind>=m_num_params)
|
||||
return(EMPTY_VALUE);
|
||||
switch(m_params[ind].type)
|
||||
{
|
||||
case TYPE_DOUBLE:
|
||||
case TYPE_FLOAT:
|
||||
break;
|
||||
default:
|
||||
return(EMPTY_VALUE);
|
||||
}
|
||||
//---
|
||||
return(m_params[ind].double_value);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Get specified parameter of creation as a string value |
|
||||
//+------------------------------------------------------------------+
|
||||
string CiCustom::ParamString(const int ind) const
|
||||
{
|
||||
if(ind>=m_num_params || m_params[ind].type!=TYPE_STRING)
|
||||
return("");
|
||||
//---
|
||||
return(m_params[ind].string_value);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Initialize the indicator with universal parameters |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CiCustom::Initialize(const string symbol,const ENUM_TIMEFRAMES period,const int num_params,const MqlParam ¶ms[])
|
||||
{
|
||||
int i;
|
||||
//--- tune
|
||||
if(m_buffers_total==0)
|
||||
m_buffers_total=256;
|
||||
if(CreateBuffers(symbol,period,m_buffers_total))
|
||||
{
|
||||
//--- string of status of drawing
|
||||
m_name ="Custom "+params[0].string_value;
|
||||
m_status="("+symbol+","+PeriodDescription();
|
||||
for(i=1;i<num_params;i++)
|
||||
{
|
||||
switch(params[i].type)
|
||||
{
|
||||
case TYPE_BOOL:
|
||||
m_status=m_status+","+((params[i].integer_value)?"true":"false");
|
||||
break;
|
||||
case TYPE_CHAR:
|
||||
case TYPE_UCHAR:
|
||||
case TYPE_SHORT:
|
||||
case TYPE_USHORT:
|
||||
case TYPE_INT:
|
||||
case TYPE_UINT:
|
||||
case TYPE_LONG:
|
||||
case TYPE_ULONG:
|
||||
m_status=m_status+","+IntegerToString(params[i].integer_value);
|
||||
break;
|
||||
case TYPE_COLOR:
|
||||
m_status=m_status+","+ColorToString((color)params[i].integer_value);
|
||||
break;
|
||||
case TYPE_DATETIME:
|
||||
m_status=m_status+","+TimeToString(params[i].integer_value);
|
||||
break;
|
||||
case TYPE_FLOAT:
|
||||
case TYPE_DOUBLE:
|
||||
m_status=m_status+","+DoubleToString(params[i].double_value);
|
||||
break;
|
||||
case TYPE_STRING:
|
||||
m_status=m_status+",'"+params[i].string_value+"'";
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_status=m_status+") H="+IntegerToString(m_handle);
|
||||
//--- save settings
|
||||
ArrayResize(m_params,num_params);
|
||||
for(i=0;i<num_params;i++)
|
||||
{
|
||||
m_params[i].type =params[i].type;
|
||||
m_params[i].integer_value=params[i].integer_value;
|
||||
m_params[i].double_value =params[i].double_value;
|
||||
m_params[i].string_value =params[i].string_value;
|
||||
}
|
||||
m_num_params=num_params;
|
||||
//--- create buffers
|
||||
for(i=0;i<m_buffers_total;i++)
|
||||
((CIndicatorBuffer*)At(i)).Name("LINE "+IntegerToString(i));
|
||||
//--- ok
|
||||
return(true);
|
||||
}
|
||||
//--- error
|
||||
return(false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,136 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Trend.mqh |
|
||||
//| Copyright 2000-2024, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#include "Indicator.mqh"
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class CiADX. |
|
||||
//| Purpose: Class of the "Average Directional Index" indicator. |
|
||||
//| Derives from class CIndicator. |
|
||||
//+------------------------------------------------------------------+
|
||||
class CiADX : public CIndicator
|
||||
{
|
||||
protected:
|
||||
int m_ma_period;
|
||||
|
||||
public:
|
||||
CiADX(void);
|
||||
~CiADX(void);
|
||||
//--- methods of access to protected data
|
||||
int MaPeriod(void) const { return (m_ma_period); }
|
||||
//--- method of creation
|
||||
bool Create(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period);
|
||||
//--- methods of access to indicator data
|
||||
double Main(const int index) const;
|
||||
double Plus(const int index) const;
|
||||
double Minus(const int index) const;
|
||||
//--- method of identifying
|
||||
virtual int Type(void) const { return (IND_ADX); }
|
||||
|
||||
protected:
|
||||
//--- methods of tuning
|
||||
virtual bool Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int num_params, const MqlParam ¶ms[]);
|
||||
bool Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CiADX::CiADX(void) : m_ma_period(-1)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CiADX::~CiADX(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create the "Average Directional Index" indicator |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CiADX::Create(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period)
|
||||
{
|
||||
//--- check history
|
||||
if (!SetSymbolPeriod(symbol, period))
|
||||
return (false);
|
||||
//--- create
|
||||
m_handle = iADX(symbol, period, ma_period);
|
||||
//--- check result
|
||||
if (m_handle == INVALID_HANDLE)
|
||||
return (false);
|
||||
//--- indicator successfully created
|
||||
if (!Initialize(symbol, period, ma_period))
|
||||
{
|
||||
//--- initialization failed
|
||||
IndicatorRelease(m_handle);
|
||||
m_handle = INVALID_HANDLE;
|
||||
return (false);
|
||||
}
|
||||
//--- ok
|
||||
return (true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Initialize the indicator with universal parameters |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CiADX::Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int num_params, const MqlParam ¶ms[])
|
||||
{
|
||||
return (Initialize(symbol, period, (int)params[0].integer_value));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Initialize indicator with the special parameters |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CiADX::Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period)
|
||||
{
|
||||
if (CreateBuffers(symbol, period, 3))
|
||||
{
|
||||
//--- string of status of drawing
|
||||
m_name = "ADX";
|
||||
m_status = "(" + symbol + "," + PeriodDescription() + "," + IntegerToString(ma_period) + ") H=" + IntegerToString(m_handle);
|
||||
//--- save settings
|
||||
m_ma_period = ma_period;
|
||||
//--- create buffers
|
||||
((CIndicatorBuffer *)At(0)).Name("MAIN_LINE");
|
||||
((CIndicatorBuffer *)At(1)).Name("PLUS_LINE");
|
||||
((CIndicatorBuffer *)At(2)).Name("MINUS_LINE");
|
||||
//--- ok
|
||||
return (true);
|
||||
}
|
||||
//--- error
|
||||
return (false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Access to Main buffer of "Average Directional Index" |
|
||||
//+------------------------------------------------------------------+
|
||||
double CiADX::Main(const int index) const
|
||||
{
|
||||
CIndicatorBuffer *buffer = At(0);
|
||||
//--- check
|
||||
if (buffer == NULL)
|
||||
return (EMPTY_VALUE);
|
||||
//---
|
||||
return (buffer.At(index));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Access to Plus buffer of "Average Directional Index" |
|
||||
//+------------------------------------------------------------------+
|
||||
double CiADX::Plus(const int index) const
|
||||
{
|
||||
CIndicatorBuffer *buffer = At(1);
|
||||
//--- check
|
||||
if (buffer == NULL)
|
||||
return (EMPTY_VALUE);
|
||||
//---
|
||||
return (buffer.At(index));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Access to Minus buffer of "Average Directional Index" |
|
||||
//+------------------------------------------------------------------+
|
||||
double CiADX::Minus(const int index) const
|
||||
{
|
||||
CIndicatorBuffer *buffer = At(2);
|
||||
//--- check
|
||||
if (buffer == NULL)
|
||||
return (EMPTY_VALUE);
|
||||
//---
|
||||
return (buffer.At(index));
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Class CiIchimoku. |
|
||||
//| Purpose: Class of the "Ichimoku Kinko Hyo" indicator. |
|
||||
//| Derives from class CIndicator. |
|
||||
//+------------------------------------------------------------------+
|
||||
class CiIchimoku : public CIndicator
|
||||
{
|
||||
protected:
|
||||
int m_tenkan_sen;
|
||||
int m_kijun_sen;
|
||||
int m_senkou_span_b;
|
||||
|
||||
public:
|
||||
CiIchimoku(void);
|
||||
~CiIchimoku(void);
|
||||
//--- methods of access to protected data
|
||||
int TenkanSenPeriod(void) const { return (m_tenkan_sen); }
|
||||
int KijunSenPeriod(void) const { return (m_kijun_sen); }
|
||||
int SenkouSpanBPeriod(void) const { return (m_senkou_span_b); }
|
||||
//--- method of creation
|
||||
bool Create(const string symbol, const ENUM_TIMEFRAMES period,
|
||||
const int tenkan_sen, const int kijun_sen, const int senkou_span_b);
|
||||
//--- methods of access to indicator data
|
||||
double TenkanSen(const int index) const;
|
||||
double KijunSen(const int index) const;
|
||||
double SenkouSpanA(const int index) const;
|
||||
double SenkouSpanB(const int index) const;
|
||||
double ChinkouSpan(const int index) const;
|
||||
//--- method of identifying
|
||||
virtual int Type(void) const { return (IND_ICHIMOKU); }
|
||||
|
||||
protected:
|
||||
//--- methods of tuning
|
||||
virtual bool Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int num_params, const MqlParam ¶ms[]);
|
||||
bool Initialize(const string symbol, const ENUM_TIMEFRAMES period,
|
||||
const int tenkan_sen, const int kijun_sen, const int senkou_span_b);
|
||||
};
|
||||
//+------------------------------------------------------------------+
|
||||
//| Constructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CiIchimoku::CiIchimoku(void) : m_tenkan_sen(-1),
|
||||
m_kijun_sen(-1),
|
||||
m_senkou_span_b(-1)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Destructor |
|
||||
//+------------------------------------------------------------------+
|
||||
CiIchimoku::~CiIchimoku(void)
|
||||
{
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Create indicator "Ichimoku Kinko Hyo" |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CiIchimoku::Create(const string symbol, const ENUM_TIMEFRAMES period,
|
||||
const int tenkan_sen, const int kijun_sen, const int senkou_span_b)
|
||||
{
|
||||
//--- check history
|
||||
if (!SetSymbolPeriod(symbol, period))
|
||||
return (false);
|
||||
//--- create
|
||||
m_handle = iIchimoku(symbol, period, tenkan_sen, kijun_sen, senkou_span_b);
|
||||
//--- check result
|
||||
if (m_handle == INVALID_HANDLE)
|
||||
return (false);
|
||||
//--- indicator successfully created
|
||||
if (!Initialize(symbol, period, tenkan_sen, kijun_sen, senkou_span_b))
|
||||
{
|
||||
//--- initialization failed
|
||||
IndicatorRelease(m_handle);
|
||||
m_handle = INVALID_HANDLE;
|
||||
return (false);
|
||||
}
|
||||
//--- ok
|
||||
return (true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Initialize the indicator with universal parameters |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CiIchimoku::Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int num_params, const MqlParam ¶ms[])
|
||||
{
|
||||
return (Initialize(symbol, period, (int)params[0].integer_value, (int)params[1].integer_value, (int)params[2].integer_value));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Initialize indicator with the special parameters |
|
||||
//+------------------------------------------------------------------+
|
||||
bool CiIchimoku::Initialize(const string symbol, const ENUM_TIMEFRAMES period,
|
||||
const int tenkan_sen, const int kijun_sen, const int senkou_span_b)
|
||||
{
|
||||
if (CreateBuffers(symbol, period, 5))
|
||||
{
|
||||
//--- string of status of drawing
|
||||
m_name = "Ichimoku";
|
||||
m_status = "(" + symbol + "," + PeriodDescription() + "," +
|
||||
IntegerToString(tenkan_sen) + "," + IntegerToString(kijun_sen) + "," +
|
||||
IntegerToString(senkou_span_b) + ") H=" + IntegerToString(m_handle);
|
||||
//--- save settings
|
||||
m_tenkan_sen = tenkan_sen;
|
||||
m_kijun_sen = kijun_sen;
|
||||
m_senkou_span_b = senkou_span_b;
|
||||
//--- create buffers
|
||||
((CIndicatorBuffer *)At(0)).Name("TENKANSEN_LINE");
|
||||
((CIndicatorBuffer *)At(1)).Name("KIJUNSEN_LINE");
|
||||
((CIndicatorBuffer *)At(2)).Name("SENKOUSPANA_LINE");
|
||||
((CIndicatorBuffer *)At(2)).Offset(kijun_sen);
|
||||
((CIndicatorBuffer *)At(3)).Name("SENKOUSPANB_LINE");
|
||||
((CIndicatorBuffer *)At(3)).Offset(kijun_sen);
|
||||
((CIndicatorBuffer *)At(4)).Name("CHIKOUSPAN_LINE");
|
||||
((CIndicatorBuffer *)At(4)).Offset(-kijun_sen);
|
||||
//--- ok
|
||||
return (true);
|
||||
}
|
||||
//--- error
|
||||
return (false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Access to TenkanSen buffer of "Ichimoku Kinko Hyo" |
|
||||
//+------------------------------------------------------------------+
|
||||
double CiIchimoku::TenkanSen(const int index) const
|
||||
{
|
||||
CIndicatorBuffer *buffer = At(0);
|
||||
//--- check
|
||||
if (buffer == NULL)
|
||||
return (EMPTY_VALUE);
|
||||
//---
|
||||
return (buffer.At(index));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Access to KijunSen buffer of "Ichimoku Kinko Hyo" |
|
||||
//+------------------------------------------------------------------+
|
||||
double CiIchimoku::KijunSen(const int index) const
|
||||
{
|
||||
CIndicatorBuffer *buffer = At(1);
|
||||
//--- check
|
||||
if (buffer == NULL)
|
||||
return (EMPTY_VALUE);
|
||||
//---
|
||||
return (buffer.At(index));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Access to SenkouSpanA buffer of "Ichimoku Kinko Hyo" |
|
||||
//+------------------------------------------------------------------+
|
||||
double CiIchimoku::SenkouSpanA(const int index) const
|
||||
{
|
||||
CIndicatorBuffer *buffer = At(2);
|
||||
//--- check
|
||||
if (buffer == NULL)
|
||||
return (EMPTY_VALUE);
|
||||
//---
|
||||
return (buffer.At(index));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Access to SenkouSpanB buffer of "Ichimoku Kinko Hyo" |
|
||||
//+------------------------------------------------------------------+
|
||||
double CiIchimoku::SenkouSpanB(const int index) const
|
||||
{
|
||||
CIndicatorBuffer *buffer = At(3);
|
||||
//--- check
|
||||
if (buffer == NULL)
|
||||
return (EMPTY_VALUE);
|
||||
//---
|
||||
return (buffer.At(index));
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Access to ChikouSpan buffer of "Ichimoku Kinko Hyo" |
|
||||
//+------------------------------------------------------------------+
|
||||
double CiIchimoku::ChinkouSpan(const int index) const
|
||||
{
|
||||
CIndicatorBuffer *buffer = At(4);
|
||||
//--- check
|
||||
if (buffer == NULL)
|
||||
return (EMPTY_VALUE);
|
||||
//---
|
||||
return (buffer.At(index));
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,115 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| DCC_Piercing.mq5 |
|
||||
//| Rajesh Nait, Copyright 2023 |
|
||||
//| https://www.mql5.com/en/users/rajeshnait/seller |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Rajesh Nait, Copyright 2023"
|
||||
#property link "https://www.mql5.com/en/users/rajeshnait/seller"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
|
||||
//--- plot Bullish Marubozu
|
||||
#property indicator_label1 "+DCCP"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrSnow
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//--- plot Bearish Marubozu
|
||||
#property indicator_label2 "-DCCP"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 clrSnow
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
|
||||
//--- input parameters
|
||||
input group "Bearish"
|
||||
input uchar InpBullishDCCPCode = 217; // BullishDCCP: code for style DRAW_ARROW (font Wingdings)
|
||||
input int InpBullishDCCPShift = 10; // BullishDCCP: vertical shift of arrows in pixels
|
||||
input group "Bullish"
|
||||
input uchar InpBearishDCCPCode = 218; // BearishDCCP: code for style DRAW_ARROW (font Wingdings)
|
||||
input int InpBearishDCCPShift =10; // BearishDCCP: vertical shift of arrows in pixels
|
||||
//--- indicator buffers
|
||||
double BullishDCCPBuffer[];
|
||||
double BearishDCCPBuffer[];
|
||||
int min_rates_total;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit() {
|
||||
min_rates_total=2;
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,BullishDCCPBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,BearishDCCPBuffer,INDICATOR_DATA);
|
||||
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,Digits());
|
||||
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
|
||||
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);
|
||||
|
||||
PlotIndexSetInteger(0,PLOT_ARROW,InpBullishDCCPCode);
|
||||
PlotIndexSetInteger(1,PLOT_ARROW,InpBearishDCCPCode);
|
||||
|
||||
ArraySetAsSeries(BullishDCCPBuffer,true);
|
||||
ArraySetAsSeries(BearishDCCPBuffer,true);
|
||||
|
||||
//--- set the vertical shift of arrows in pixels
|
||||
PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,InpBullishDCCPShift);
|
||||
PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-InpBearishDCCPShift);
|
||||
//--- set as an empty value 0.0
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
|
||||
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.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[]) {
|
||||
//---
|
||||
if(rates_total<min_rates_total)
|
||||
return(0);
|
||||
|
||||
int limit;
|
||||
|
||||
if(prev_calculated>rates_total || prev_calculated<=0) {
|
||||
limit=rates_total-min_rates_total;
|
||||
} else {
|
||||
limit=rates_total-prev_calculated;
|
||||
}
|
||||
ArraySetAsSeries(open,true);
|
||||
ArraySetAsSeries(high,true);
|
||||
ArraySetAsSeries(low,true);
|
||||
ArraySetAsSeries(close,true);
|
||||
|
||||
//---
|
||||
|
||||
for(int i=limit; i>=0 && !IsStopped(); i--) {
|
||||
BullishDCCPBuffer[i]=0.0;
|
||||
BearishDCCPBuffer[i]=0.0;
|
||||
|
||||
|
||||
BearishDCCPBuffer[0]=0.0;
|
||||
if(open[i]>close[i] && open[i+1]<close[i+1] && open[i]>close[i+1])
|
||||
BearishDCCPBuffer[i]=high[i];
|
||||
|
||||
BullishDCCPBuffer[0]=0.0;
|
||||
if(open[i]<close[i] && open[i+1]>close[i+1] && open[i]<close[i+1])
|
||||
BullishDCCPBuffer[i]=low[i];
|
||||
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,99 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Dominant.mq5 |
|
||||
//| Copyright 2024, Rajesh Kumar Nait |
|
||||
//| https://www.mql5.com/en/users/rajeshnait/seller |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2024, Rajesh Kumar Nait"
|
||||
#property link "https://www.mql5.com/en/users/rajeshnait/seller"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_plots 0
|
||||
string prefix="c_";
|
||||
input int total = 1000; // Number of Bars
|
||||
input color clr = clrSnow; // Adjust color as required
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit() {
|
||||
//--- indicator buffers mapping
|
||||
|
||||
//---
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason) {
|
||||
ObjectsDeleteAll(0,prefix);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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[]) {
|
||||
//---
|
||||
ArraySetAsSeries(open,true);
|
||||
ArraySetAsSeries(high,true);
|
||||
ArraySetAsSeries(low,true);
|
||||
ArraySetAsSeries(close,true);
|
||||
ArraySetAsSeries(time,true);
|
||||
|
||||
if(rates_total<total) {
|
||||
Print("Required Bars not available");
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
for(int i=1; i<total; i++) {
|
||||
//bullish
|
||||
if(open[i]<close[i] && open[i+1]<close[i+1] && open[i]>=close[i+1] && low[i]<close[i+1] && high[i+1]>open[i])
|
||||
crearFlecha(prefix+"Bull_Dominanat"+IntegerToString(i),time[i],low[i+1],clr,225,ANCHOR_TOP);
|
||||
|
||||
if(open[i]>close[i] && open[i+1]>close[i+1] && open[i]<=close[i+1] && high[i]>close[i+1] && low[i+1]<open[i])
|
||||
crearFlecha(prefix+"Bear_Dominanat"+IntegerToString(i),time[i],high[i+1],clr,226,ANCHOR_BOTTOM);
|
||||
}
|
||||
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| CREATE ARROWS
|
||||
//+------------------------------------------------------------------+
|
||||
bool crearFlecha(string nameAux, datetime timeAux, double priceAux, color clrAux, int code, ENUM_ARROW_ANCHOR anchorAux) {
|
||||
const long chart_ID=0; // chart's ID
|
||||
const string name=nameAux; // arrow name
|
||||
const int sub_window=0; // subwindow index
|
||||
datetime time=timeAux; // anchor point time
|
||||
double price=priceAux; // anchor point price
|
||||
const int arrow_code=code; // arrow code
|
||||
const ENUM_ARROW_ANCHOR anchor=anchorAux; // anchor point position
|
||||
const color clr_=clrAux; // arrow color
|
||||
const ENUM_LINE_STYLE style=STYLE_SOLID; // border line style
|
||||
const int width=1; // arrow size
|
||||
const bool back=true; // in the background
|
||||
const bool selection=false; // highlight to move
|
||||
const bool hidden=true; // hidden in the object list
|
||||
const long z_order=0; // priority for mouse click
|
||||
|
||||
ObjectCreate(chart_ID,name,OBJ_ARROW,sub_window,time,price);
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_ARROWCODE,arrow_code);
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchorAux);
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr_);
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
|
||||
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
|
||||
return(true);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,105 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Fair_Value_Gap.mq5 |
|
||||
//| Copyright 2024, Rajesh Kumar Nait |
|
||||
//| https://www.mql5.com/en/users/rajeshnait/seller |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2024, Rajesh Kumar Nait"
|
||||
#property link "https://www.mql5.com/en/users/rajeshnait/seller"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_plots 0
|
||||
|
||||
|
||||
//--- input parameters
|
||||
input color InpColorToUP = clrLime; // Color of the gap up
|
||||
input color InpColorToDN = clrDeepPink; // Color of the gap down
|
||||
input int maxbars = 300;// how many bars to Look back
|
||||
|
||||
string prefix;
|
||||
double price;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit() {
|
||||
//--- indicator buffers mapping
|
||||
prefix=MQLInfoString(MQL_PROGRAM_NAME)+"_";
|
||||
//---
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason) {
|
||||
ObjectsDeleteAll(0,prefix);
|
||||
ChartRedraw();
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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[]) {
|
||||
//---
|
||||
if(rates_total<4) return 0;
|
||||
price = close[0];
|
||||
ArraySetAsSeries(open,true);
|
||||
ArraySetAsSeries(high,true);
|
||||
ArraySetAsSeries(low,true);
|
||||
ArraySetAsSeries(close,true);
|
||||
ArraySetAsSeries(time,true);
|
||||
int limit=rates_total-prev_calculated;
|
||||
if(limit>1) {
|
||||
limit=rates_total-5;
|
||||
}
|
||||
for(int i=maxbars; i>=0 && !IsStopped(); i--) {
|
||||
if(low[i]-high[i+2]>=Point()) {
|
||||
|
||||
double up=fmin(high[i],low[i]);
|
||||
double dn=fmax(high[i+2],low[i+2]);
|
||||
|
||||
DrawArea(i,up,dn,time,InpColorToUP,1);
|
||||
|
||||
}
|
||||
if(low[i+2]-high[i]>=Point()) {
|
||||
|
||||
double up=fmin(high[i+2],low[i+2]);
|
||||
double dn=fmax(high[i],low[i]);
|
||||
DrawArea(i,up,dn,time,InpColorToDN,0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
void DrawArea(const int index, const double price_up,const double price_dn,const datetime &time[],const color color_area,const char dir) {
|
||||
string name=prefix+(dir>0 ? "up_" : "dn_")+TimeToString(time[index]);
|
||||
|
||||
if(ObjectFind(0,name)<0 )
|
||||
ObjectCreate(0,name,OBJ_RECTANGLE,0,0,0,0);
|
||||
ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
|
||||
ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
|
||||
ObjectSetInteger(0,name,OBJPROP_FILL,true);
|
||||
ObjectSetInteger(0,name,OBJPROP_BACK,true);
|
||||
ObjectSetString(0,name,OBJPROP_TOOLTIP,"\n");
|
||||
//---
|
||||
ObjectSetInteger(0,name,OBJPROP_COLOR,color_area);
|
||||
ObjectSetInteger(0,name,OBJPROP_TIME,0,time[index+2]);
|
||||
ObjectSetInteger(0,name,OBJPROP_TIME,1,time[index]);
|
||||
ObjectSetDouble(0,name,OBJPROP_PRICE,0,price_up);
|
||||
ObjectSetDouble(0,name,OBJPROP_PRICE,1,price_dn);
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,111 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Geometric Moving Average.mq5 |
|
||||
//| Copyright 2024, Rosh Jardine |
|
||||
//| https://www.mql5.com/en/users/roshjardine |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2024, Lyn Astara"
|
||||
#property link "https://www.mql5.com/en/users/roshjardine"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
//--- plot GeoMALine
|
||||
#property indicator_label1 "GeoMALine"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
input int InputGeoMAPeriod = 7;
|
||||
input int InputGeoMAShift = 0;
|
||||
input ENUM_APPLIED_PRICE InputAppliedPriceEnum = PRICE_CLOSE;
|
||||
//--- indicator buffers
|
||||
double GeoMALineBuffer[];
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,GeoMALineBuffer,INDICATOR_DATA);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
/*** setting values of the indicator that won't be visible on a chart ***/
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InputGeoMAPeriod);
|
||||
//--- line shifts when drawing
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,InputGeoMAShift);
|
||||
string short_name = "GeoMA-"+EnumToString(InputAppliedPriceEnum)+"("+IntegerToString(InputGeoMAPeriod)+")";
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
/*const double x = double(1)/double(4);
|
||||
double t = MathPow(90,x);
|
||||
Print("t=",DoubleToString(t,4));*/
|
||||
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[])
|
||||
{
|
||||
double p_t = 0.0; double p_0 = 0.0; static const double x = double(1)/double(InputGeoMAPeriod);
|
||||
if (rates_total<=0) { return(0); }
|
||||
|
||||
if (prev_calculated<=0)
|
||||
{
|
||||
p_t = GET_APPLIED_PRICE(open[0],low[0],high[0],close[0]);
|
||||
GeoMALineBuffer[0] = EMPTY_VALUE;
|
||||
for (int i=1; i<InputGeoMAPeriod; i++)
|
||||
{
|
||||
p_t *= GET_APPLIED_PRICE(open[i],low[i],high[i],close[i]);
|
||||
}
|
||||
GeoMALineBuffer[InputGeoMAPeriod-1] = MathPow(p_t,x);
|
||||
for (int i=InputGeoMAPeriod; i<rates_total; i++)
|
||||
{
|
||||
p_0 = p_t/GET_APPLIED_PRICE(open[i-InputGeoMAPeriod],low[i-InputGeoMAPeriod],high[i-InputGeoMAPeriod],close[i-InputGeoMAPeriod]);
|
||||
p_t = p_0*GET_APPLIED_PRICE(open[i],low[i],high[i],close[i]);
|
||||
GeoMALineBuffer[i] = MathPow(p_t,x);
|
||||
}
|
||||
return(rates_total);
|
||||
}
|
||||
for (int i=prev_calculated; i<=rates_total-1; i++)
|
||||
{
|
||||
p_0 = p_t/GET_APPLIED_PRICE(open[i-InputGeoMAPeriod],low[i-InputGeoMAPeriod],high[i-InputGeoMAPeriod],close[i-InputGeoMAPeriod]);
|
||||
p_t = p_0*GET_APPLIED_PRICE(open[i],low[i],high[i],close[i]);
|
||||
GeoMALineBuffer[i] = MathPow(p_t,x);
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
double GET_APPLIED_PRICE(const double ParamOpenPriceDouble,const double ParamLowPriceDouble,
|
||||
const double ParamHighPriceDouble,const double ParamClosePriceDouble)
|
||||
{
|
||||
//+----------------------------------------------------------------------------------------------------------------------------------------+
|
||||
/*** close price as the default ***/
|
||||
double PriceResultDouble = ParamClosePriceDouble;
|
||||
int AppliedPriceInt = int(InputAppliedPriceEnum);
|
||||
//+----------------------------------------------------------------------------------------------------------------------------------------+
|
||||
switch(AppliedPriceInt)
|
||||
{
|
||||
case 1 : PriceResultDouble = ParamOpenPriceDouble; break;
|
||||
case 2 : PriceResultDouble = ParamLowPriceDouble; break;
|
||||
case 3 : PriceResultDouble = ParamHighPriceDouble; break;
|
||||
case 4 : PriceResultDouble = ParamClosePriceDouble; break;
|
||||
/*** Median price ***/
|
||||
case 5 : PriceResultDouble = (ParamHighPriceDouble + ParamLowPriceDouble)/2; break;
|
||||
/*** Typical price ***/
|
||||
case 6 : PriceResultDouble = (ParamHighPriceDouble + ParamLowPriceDouble + ParamClosePriceDouble)/3; break;
|
||||
/*** Weighted price ***/
|
||||
default : PriceResultDouble = (ParamHighPriceDouble + ParamLowPriceDouble + ParamClosePriceDouble + ParamClosePriceDouble)/4; break;
|
||||
}
|
||||
return(PriceResultDouble);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,110 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Harmonic Moving Average.mq5 |
|
||||
//| Copyright 2024, Rosh Jardine |
|
||||
//| https://www.mql5.com/en/users/roshjardine |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2024, Rosh Jardine"
|
||||
#property link "https://www.mql5.com/en/users/roshjardine"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
//--- plot HMALine
|
||||
#property indicator_label1 "HMALine"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
input int InputHMAPeriod = 7;
|
||||
input int InputHMAShift = 0;
|
||||
input ENUM_APPLIED_PRICE InputAppliedPriceEnum = PRICE_CLOSE;
|
||||
//--- indicator buffers
|
||||
double HMALineBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,HMALineBuffer,INDICATOR_DATA);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
|
||||
/*** setting values of the indicator that won't be visible on a chart ***/
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE);
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InputHMAShift);
|
||||
//--- line shifts when drawing
|
||||
PlotIndexSetInteger(0,PLOT_SHIFT,InputHMAShift);
|
||||
string short_name = "HMA-"+EnumToString(InputAppliedPriceEnum)+"("+IntegerToString(InputHMAPeriod)+")";
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name);
|
||||
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[])
|
||||
{
|
||||
if (rates_total<=0) { return(0); }
|
||||
|
||||
if (prev_calculated<=0)
|
||||
{
|
||||
double rsd = 0.0;
|
||||
for (int i=0; i<InputHMAPeriod; i++)
|
||||
{
|
||||
rsd += double(1/GET_APPLIED_PRICE(open[i],low[i],high[i],close[i]));
|
||||
HMALineBuffer[i] = 0.0;
|
||||
}
|
||||
HMALineBuffer[InputHMAPeriod-1] = InputHMAPeriod/rsd;
|
||||
|
||||
for (int i=InputHMAPeriod; i<rates_total; i++)
|
||||
{
|
||||
double lrs = InputHMAPeriod/HMALineBuffer[i-1];
|
||||
double vlfr = 1/GET_APPLIED_PRICE(open[i-InputHMAPeriod],low[i-InputHMAPeriod],high[i-InputHMAPeriod],close[i-InputHMAPeriod]);
|
||||
HMALineBuffer[i] = InputHMAPeriod/(lrs-vlfr+(1/GET_APPLIED_PRICE(open[i],low[i],high[i],close[i])));
|
||||
}
|
||||
return(rates_total);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=prev_calculated; i<=rates_total-1; i++)
|
||||
{
|
||||
double lrs = double(InputHMAPeriod)/HMALineBuffer[i-1];
|
||||
double vlfr = 1/GET_APPLIED_PRICE(open[i-InputHMAPeriod],low[i-InputHMAPeriod],high[i-InputHMAPeriod],close[i-InputHMAPeriod]);
|
||||
HMALineBuffer[i] = InputHMAPeriod/(lrs-vlfr+(1/GET_APPLIED_PRICE(open[i],low[i],high[i],close[i])));
|
||||
}
|
||||
return(rates_total);
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
double GET_APPLIED_PRICE(const double ParamOpenPriceDouble,const double ParamLowPriceDouble,
|
||||
const double ParamHighPriceDouble,const double ParamClosePriceDouble)
|
||||
{
|
||||
//+----------------------------------------------------------------------------------------------------------------------------------------+
|
||||
/*** close price as the default ***/
|
||||
double PriceResultDouble = ParamClosePriceDouble;
|
||||
int AppliedPriceInt = int(InputAppliedPriceEnum);
|
||||
//+----------------------------------------------------------------------------------------------------------------------------------------+
|
||||
switch(AppliedPriceInt)
|
||||
{
|
||||
case 1 : PriceResultDouble = ParamOpenPriceDouble; break;
|
||||
case 2 : PriceResultDouble = ParamLowPriceDouble; break;
|
||||
case 3 : PriceResultDouble = ParamHighPriceDouble; break;
|
||||
case 4 : PriceResultDouble = ParamClosePriceDouble; break;
|
||||
/*** Median price ***/
|
||||
case 5 : PriceResultDouble = (ParamHighPriceDouble + ParamLowPriceDouble)/2; break;
|
||||
/*** Typical price ***/
|
||||
case 6 : PriceResultDouble = (ParamHighPriceDouble + ParamLowPriceDouble + ParamClosePriceDouble)/3; break;
|
||||
/*** Weighted price ***/
|
||||
default : PriceResultDouble = (ParamHighPriceDouble + ParamLowPriceDouble + ParamClosePriceDouble + ParamClosePriceDouble)/4; break;
|
||||
}
|
||||
return(PriceResultDouble);
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,96 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Marubozu.mq5 |
|
||||
//| Rajesh Nait, Copyright 2023 |
|
||||
//| https://www.mql5.com/en/users/rajeshnait/seller |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Rajesh Nait, Copyright 2023"
|
||||
#property link "https://www.mql5.com/en/users/rajeshnait/seller"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
|
||||
//--- plot Bullish Marubozu
|
||||
#property indicator_label1 "+M"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrLimeGreen
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//--- plot Bearish Marubozu
|
||||
#property indicator_label2 "-M"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 clrDeepPink
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//--- input parameters
|
||||
input group "Bullish Marubozu"
|
||||
sinput uchar InpBullishMarubozuCode = 167; // Bullish Marubozu: code for style DRAW_ARROW (font Wingdings)
|
||||
sinput int InpBullishMarubozuShift = 10; // Bullish Marubozu: vertical shift of arrows in pixels
|
||||
input group "Bearish Marubozu"
|
||||
sinput uchar InpBearishMarubozuCode = 167; // Bearish Marubozu: code for style DRAW_ARROW (font Wingdings)
|
||||
sinput int InpBearishMarubozuShift = 10; // Bearish Marubozu: vertical shift of arrows in pixels
|
||||
//--- indicator buffers
|
||||
double BullishMarubozuBuffer[];
|
||||
double BearishMarubozuBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit() {
|
||||
//--- indicator buffers mapping
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,BullishMarubozuBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,BearishMarubozuBuffer,INDICATOR_DATA);
|
||||
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
|
||||
PlotIndexSetInteger(0,PLOT_ARROW,InpBullishMarubozuCode);
|
||||
PlotIndexSetInteger(1,PLOT_ARROW,InpBearishMarubozuCode);
|
||||
//--- set the vertical shift of arrows in pixels
|
||||
PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,InpBullishMarubozuShift);
|
||||
PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-InpBearishMarubozuShift);
|
||||
//--- set as an empty value 0.0
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
|
||||
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.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[]) {
|
||||
//---
|
||||
if(rates_total<3)
|
||||
return(0);
|
||||
//---
|
||||
int limit=prev_calculated-1;
|
||||
if(prev_calculated==0) {
|
||||
limit=1;
|
||||
BullishMarubozuBuffer[0]=0.0;
|
||||
BearishMarubozuBuffer[0]=0.0;
|
||||
}
|
||||
for(int i=limit; i<rates_total; i++) {
|
||||
BullishMarubozuBuffer[i]=0.0;
|
||||
BearishMarubozuBuffer[i]=0.0;
|
||||
if(i>0) {
|
||||
|
||||
if(open[i]==high[i] && close[i]==low[i]) {
|
||||
BearishMarubozuBuffer[i]=high[i];
|
||||
}
|
||||
|
||||
if(close[i]==high[i] && open[i]==low[i]) {
|
||||
BullishMarubozuBuffer[i]=low[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,133 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| MinChangeSignal.mq5 |
|
||||
//| Copyright 2013, Rone. |
|
||||
//| rone.sergey@gmail.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2013, Rone."
|
||||
#property link "rone.sergey@gmail.com"
|
||||
#property version "1.00"
|
||||
#property description "The signal is formed if the changes sum calculated on the last bar "
|
||||
#property description "is less, than the smallest of sums calculated on the specified number of previous bars."
|
||||
//---
|
||||
#property indicator_separate_window
|
||||
#property indicator_buffers 3
|
||||
#property indicator_plots 3
|
||||
//--- plot CurrentChange
|
||||
#property indicator_label1 "Current Change Sum"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrBlue
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
//--- plot MinChange
|
||||
#property indicator_label2 "Min Change Sum"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 2
|
||||
//--- plot Signal
|
||||
#property indicator_label3 "Signal"
|
||||
#property indicator_type3 DRAW_ARROW
|
||||
#property indicator_color3 clrLime
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 3
|
||||
//--- input parameters
|
||||
input int InpChangesPeriod = 4; // Changes Period
|
||||
input int InpCheckPeriod = 10; // Check Period
|
||||
input bool InpAbsChange = false; // Abs Change
|
||||
//--- indicator buffers
|
||||
double CurrentSumBuffer[];
|
||||
double MinSumBuffer[];
|
||||
double SignalBuffer[];
|
||||
//---
|
||||
int changes_period;
|
||||
int check_period;
|
||||
int min_required_bars;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit() {
|
||||
//---
|
||||
if ( InpChangesPeriod < 1 || InpCheckPeriod < 2 ) {
|
||||
changes_period = 3;
|
||||
check_period = 10;
|
||||
printf("Incorrect input value InpChangesPeriod = %d or/and InpCheckPeriod =%d. "
|
||||
"Indicator will use values %d and %d respectively.", InpChangesPeriod, InpCheckPeriod,
|
||||
changes_period, check_period);
|
||||
} else {
|
||||
changes_period = InpChangesPeriod;
|
||||
check_period = InpCheckPeriod;
|
||||
}
|
||||
min_required_bars = changes_period + check_period + 1;
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0, CurrentSumBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(1, MinSumBuffer, INDICATOR_DATA);
|
||||
SetIndexBuffer(2, SignalBuffer, INDICATOR_DATA);
|
||||
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
|
||||
PlotIndexSetInteger(2, PLOT_ARROW, 159);
|
||||
//---
|
||||
for ( int plot = 0; plot < 3; plot++ ) {
|
||||
PlotIndexSetInteger(plot, PLOT_DRAW_BEGIN, min_required_bars - 1);
|
||||
PlotIndexSetInteger(plot, PLOT_SHIFT, 0);
|
||||
PlotIndexSetDouble(plot, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
}
|
||||
//---
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, "Min Price Change ("+(string)changes_period
|
||||
+", "+(string)check_period+")");
|
||||
//---
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator iteration function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const int begin,
|
||||
const double &price[])
|
||||
{
|
||||
//---
|
||||
int change_start_bar, check_start_bar, signal_start_bar;
|
||||
//---
|
||||
if ( rates_total < min_required_bars ) {
|
||||
Print("Not enough bars for calculations.");
|
||||
return(0);
|
||||
}
|
||||
//---
|
||||
if ( prev_calculated > rates_total || prev_calculated <= 0 ) {
|
||||
change_start_bar = changes_period;
|
||||
check_start_bar = change_start_bar + check_period;
|
||||
signal_start_bar = check_start_bar + 1;
|
||||
} else {
|
||||
change_start_bar = prev_calculated - 1;
|
||||
check_start_bar = change_start_bar;
|
||||
signal_start_bar = change_start_bar;
|
||||
}
|
||||
//---
|
||||
for ( int bar = change_start_bar; bar < rates_total; bar++ ) {
|
||||
double sum = 0.0;
|
||||
|
||||
for ( int shift = bar - changes_period + 1; shift <= bar; shift++ ) {
|
||||
if ( InpAbsChange ) {
|
||||
sum += MathAbs(price[shift] - price[shift-1]);
|
||||
} else {
|
||||
sum += price[shift] - price[shift-1];
|
||||
}
|
||||
}
|
||||
CurrentSumBuffer[bar] = MathAbs(sum);
|
||||
}
|
||||
for ( int bar = check_start_bar; bar < rates_total; bar++ ) {
|
||||
MinSumBuffer[bar] = CurrentSumBuffer[ArrayMinimum(CurrentSumBuffer,
|
||||
bar-check_period, check_period)];
|
||||
}
|
||||
for ( int bar = signal_start_bar; bar < rates_total; bar++ ) {
|
||||
SignalBuffer[bar] = EMPTY_VALUE;
|
||||
if ( CurrentSumBuffer[bar] < MinSumBuffer[bar]
|
||||
&& CurrentSumBuffer[bar-1] >= MinSumBuffer[bar-1] )
|
||||
{
|
||||
SignalBuffer[bar] = MinSumBuffer[bar];
|
||||
}
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,208 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Round price DOC.mq5 |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "mladen"
|
||||
#property link "mladenfx@gmail.com"
|
||||
#property version "1.00"
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 7
|
||||
#property indicator_plots 7
|
||||
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 Gold
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 DeepSkyBlue
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 DeepSkyBlue
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 DeepSkyBlue
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 PaleVioletRed
|
||||
#property indicator_type6 DRAW_LINE
|
||||
#property indicator_color6 PaleVioletRed
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 PaleVioletRed
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
input int T3Period = 89; // T3 Calculation period
|
||||
input double T3Hot = 0.7; // T3 hot value
|
||||
input bool T3Original = false; // T3 original Tillson calculation?
|
||||
input ENUM_APPLIED_PRICE T3Price = PRICE_CLOSE; // T3 price to use
|
||||
input int Delta1 = 89; // Distance in points for first band
|
||||
input int Delta2 = 144; // Distance in points for second band
|
||||
input int Delta3 = 233; // Distance in points for third band
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double t3[];
|
||||
double t3Up1[];
|
||||
double t3Up2[];
|
||||
double t3Up3[];
|
||||
double t3Dn1[];
|
||||
double t3Dn2[];
|
||||
double t3Dn3[];
|
||||
|
||||
double c1,c2,c3,c4,t3Alpha;
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
int OnInit()
|
||||
{
|
||||
SetIndexBuffer( 0,t3 ,INDICATOR_DATA);
|
||||
SetIndexBuffer( 1,t3Up1,INDICATOR_DATA);
|
||||
SetIndexBuffer( 2,t3Up2,INDICATOR_DATA);
|
||||
SetIndexBuffer( 3,t3Up3,INDICATOR_DATA);
|
||||
SetIndexBuffer( 4,t3Dn1,INDICATOR_DATA);
|
||||
SetIndexBuffer( 5,t3Dn2,INDICATOR_DATA);
|
||||
SetIndexBuffer( 6,t3Dn3,INDICATOR_DATA);
|
||||
|
||||
PlotIndexSetString(0,PLOT_LABEL,"T3");
|
||||
for (int i=1; i<4; i++)
|
||||
{
|
||||
PlotIndexSetString(i ,PLOT_LABEL,"T3 upper band "+(string)i);
|
||||
PlotIndexSetString(i+3,PLOT_LABEL,"T3 lower band "+(string)i);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double a = MathMax(MathMin(T3Hot,1),0.0001);;
|
||||
c1 = -a*a*a;
|
||||
c2 = 3*(a*a+a*a*a);
|
||||
c3 = -3*(2*a*a+a+a*a*a);
|
||||
c4 = 1+3*a+a*a*a+3*a*a;
|
||||
double t3period = T3Period;
|
||||
if (!T3Original) t3period = 1.0 + (t3period-1.0)/2.0;
|
||||
t3Alpha = 2.0/(1.0 + t3period);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
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 &TickVolume[],
|
||||
const long &Volume[],
|
||||
const int &Spread[])
|
||||
{
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
for (int i=(int)MathMax(prev_calculated-1,0); i<rates_total; i++)
|
||||
{
|
||||
double price;
|
||||
switch (T3Price)
|
||||
{
|
||||
case PRICE_CLOSE : price = Close[i]; break;
|
||||
case PRICE_OPEN : price = Open[i]; break;
|
||||
case PRICE_HIGH : price = High[i]; break;
|
||||
case PRICE_LOW : price = Low[i]; break;
|
||||
case PRICE_MEDIAN : price = (High[i]+Low[i])/2.0; break;
|
||||
case PRICE_TYPICAL : price = (High[i]+Low[i]+Close[i])/3.0; break;
|
||||
case PRICE_WEIGHTED : price = (High[i]+Low[i]+Close[i]+Close[i])/4.0; break;
|
||||
default : price = 0;
|
||||
}
|
||||
|
||||
t3[i] = calcT3(price,i,rates_total);
|
||||
t3Up1[i] = t3[i]+Delta1*_Point;
|
||||
t3Up2[i] = t3[i]+Delta2*_Point;
|
||||
t3Up3[i] = t3[i]+Delta3*_Point;
|
||||
t3Dn1[i] = t3[i]-Delta1*_Point;
|
||||
t3Dn2[i] = t3[i]-Delta2*_Point;
|
||||
t3Dn3[i] = t3[i]-Delta3*_Point;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double t3Values[][6];
|
||||
double calcT3(double price, int r, int bars, int s=0)
|
||||
{
|
||||
if (ArrayRange(t3Values,0)!=bars) ArrayResize(t3Values,bars);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
if (r < 2)
|
||||
{
|
||||
t3Values[r][s+0] = price;
|
||||
t3Values[r][s+1] = price;
|
||||
t3Values[r][s+2] = price;
|
||||
t3Values[r][s+3] = price;
|
||||
t3Values[r][s+4] = price;
|
||||
t3Values[r][s+5] = price;
|
||||
}
|
||||
else
|
||||
{
|
||||
t3Values[r][s+0] = t3Values[r-1][s+0]+t3Alpha*(price -t3Values[r-1][s+0]);
|
||||
t3Values[r][s+1] = t3Values[r-1][s+1]+t3Alpha*(t3Values[r][s+0]-t3Values[r-1][s+1]);
|
||||
t3Values[r][s+2] = t3Values[r-1][s+2]+t3Alpha*(t3Values[r][s+1]-t3Values[r-1][s+2]);
|
||||
t3Values[r][s+3] = t3Values[r-1][s+3]+t3Alpha*(t3Values[r][s+2]-t3Values[r-1][s+3]);
|
||||
t3Values[r][s+4] = t3Values[r-1][s+4]+t3Alpha*(t3Values[r][s+3]-t3Values[r-1][s+4]);
|
||||
t3Values[r][s+5] = t3Values[r-1][s+5]+t3Alpha*(t3Values[r][s+4]-t3Values[r-1][s+5]);
|
||||
}
|
||||
return(c1*t3Values[r][s+5] + c2*t3Values[r][s+4] + c3*t3Values[r][s+3] + c4*t3Values[r][s+2]);
|
||||
}
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,451 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Strong_Levels_V0.mq5 |
|
||||
//| Copyright 2023, MetaQuotes Ltd. |
|
||||
//| https://www.pipcrop.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2023, MetaQuotes Ltd."
|
||||
#property link "https://www.pipcrop.com"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
#property version "1.00"
|
||||
|
||||
#property description "Rule 1(bull candle on sup. level): if close - low > Jump Factor"
|
||||
#property description "Rule 2(bull candle on res. level): if close - low > Jump Factor & (close-low)/(high-low)>ratio"
|
||||
|
||||
#include <..\include\Math\Alglib\dataanalysis.mqh>
|
||||
CKMeans *Cclustering;
|
||||
|
||||
enum filterrules {
|
||||
rule1, // Rule 1
|
||||
rule12, // Rule 1+2
|
||||
rule2 // Rule 2
|
||||
};
|
||||
|
||||
input filterrules myfilters = 1; // Rule(s) for data gather
|
||||
input int LNo = 15; // Number of Levels to extract
|
||||
input ENUM_TIMEFRAMES tf0 = PERIOD_M1; // Analysing TF
|
||||
input double Jumpmulti = 100.0; // Min. Jump after touch (Percent of ATR)
|
||||
input double ratio = 0.6667; // Ratio
|
||||
input int ATRPer = 55; // ATR Period
|
||||
input color ResColor = clrPink; // Resistance color for Panel
|
||||
input color SupColor = clrPowderBlue; // Support color for Panel
|
||||
input color BGColor = C'23,27,38'; // Back-ground
|
||||
input color ResColor0 = clrRed; // Resistance Levels color
|
||||
input color SupColor0 = clrBlue; // Support Levels color
|
||||
input int LevelsInt = 2; // Levels Width
|
||||
|
||||
int ATRHndler, size0, xini=5, yini=20, maxbar, minbar=10, Ysize = 30, dyy=5, xdis = 0, lastbars = 0, LastLNo=0, minLN=3;
|
||||
int sup_xyz[], res_xyz[];
|
||||
long NextChart;
|
||||
string ToolName = "SH_Levels_", OBJName;
|
||||
double atr[], Jmulti;
|
||||
CMatrixDouble res_mat, sup_mat, supclusters, resclusters;
|
||||
bool startCluster = false;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
ObjectsDeleteAll(0, ToolName);
|
||||
Jmulti = Jumpmulti/100.0;
|
||||
|
||||
ATRHndler = iATR(Symbol(), tf0, ATRPer);
|
||||
SetScreen();
|
||||
|
||||
maxbar = 100000;
|
||||
|
||||
OBJName = ToolName + "Analyse"; xdis = xini;
|
||||
ObjectCreate(0, OBJName, OBJ_BUTTON, 0, 0, 0);
|
||||
OBJSet(OBJName, "Analyse Sup./Res.", xini, yini, 180, 2*Ysize+dyy,12, C'240,240,240', clrNONE, clrBlack, ALIGN_CENTER, CORNER_LEFT_UPPER, true);
|
||||
|
||||
OBJName = ToolName + " Loadbar"; xdis+= (int)ObjectGetInteger(ChartID(), ToolName + "Analyse", OBJPROP_XSIZE) + dyy;
|
||||
ObjectCreate(0, OBJName, OBJ_EDIT, 0, 0, 0);
|
||||
OBJSet(OBJName, "0.0 %", xdis, yini, 50, Ysize, 10, clrGold, clrGold, BGColor, ALIGN_LEFT, CORNER_LEFT_UPPER, true);
|
||||
|
||||
OBJName = ToolName + "clusterLoadbar"; xdis = xini+(int)ObjectGetInteger(ChartID(), ToolName + "Analyse", OBJPROP_XSIZE) + dyy; yini += Ysize + dyy;
|
||||
ObjectCreate(0, OBJName, OBJ_EDIT, 0, 0, 0);
|
||||
OBJSet(OBJName, "0.0 %", xdis, yini, 50, Ysize, 10, clrGold, clrGold, BGColor, ALIGN_LEFT, CORNER_LEFT_UPPER, true);
|
||||
|
||||
OBJName = ToolName + " LN"; yini+=Ysize+dyy;
|
||||
ObjectCreate(0, OBJName, OBJ_EDIT, 0, 0, 0);
|
||||
OBJSet(OBJName, "Level No.", xini, yini, 80, Ysize, 10, clrGold, clrGold, BGColor, ALIGN_LEFT, CORNER_LEFT_UPPER, true);
|
||||
|
||||
OBJName = ToolName + " LN.e"; xdis=xini+80+dyy;
|
||||
ObjectCreate(0, OBJName, OBJ_EDIT, 0, 0, 0);
|
||||
OBJSet(OBJName, IntegerToString(LNo), xdis, yini, 100-dyy, Ysize, 10, BGColor, clrGold, clrGold, ALIGN_RIGHT, CORNER_LEFT_UPPER, false);
|
||||
LastLNo = LNo;
|
||||
|
||||
OBJName = ToolName + " bars"; xdis=xini; yini+=Ysize+dyy;
|
||||
ObjectCreate(0, OBJName, OBJ_EDIT, 0, 0, 0);
|
||||
OBJSet(OBJName, "Bar count", xdis, yini, 80, Ysize, 10, clrGold, clrGold, BGColor, ALIGN_LEFT, CORNER_LEFT_UPPER, true);
|
||||
|
||||
OBJName = ToolName + " bars.e"; xdis+=80+dyy;
|
||||
ObjectCreate(0, OBJName, OBJ_EDIT, 0, 0, 0);
|
||||
OBJSet(OBJName, IntegerToString(maxbar), xdis, yini, 100-dyy, Ysize, 10, BGColor, clrGold, clrGold, ALIGN_RIGHT, CORNER_LEFT_UPPER, false);
|
||||
lastbars = maxbar;
|
||||
|
||||
OBJName = ToolName + " TotalRes"; yini+=Ysize+3*dyy;
|
||||
ObjectCreate(0, OBJName, OBJ_EDIT, 0, 0, 0);
|
||||
OBJSet(OBJName, "Res. Count: ", xini, yini, 180, Ysize, 12, ResColor, ResColor, BGColor, ALIGN_LEFT, CORNER_LEFT_UPPER, true);
|
||||
|
||||
OBJName = ToolName + " TotalSup"; yini+=Ysize+dyy;
|
||||
ObjectCreate(0, OBJName, OBJ_EDIT, 0, 0, 0);
|
||||
OBJSet(OBJName, "Sup. Count: ", xini, yini, 180, Ysize, 12, SupColor, SupColor, BGColor, ALIGN_LEFT, CORNER_LEFT_UPPER, true);
|
||||
|
||||
EventSetMillisecondTimer(5);
|
||||
|
||||
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[])
|
||||
{
|
||||
//---
|
||||
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Expert deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
if (reason==1 || reason==4)
|
||||
{
|
||||
ObjectsDeleteAll(0, ToolName);
|
||||
EventKillTimer();
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
void Analyse()
|
||||
{
|
||||
// Reset Graphics
|
||||
OBJName = ToolName + "Zone_";
|
||||
ObjectsDeleteAll(ChartID(), OBJName); ChartRedraw();
|
||||
|
||||
OBJName = ToolName + " Loadbar";
|
||||
ObjectSetString(0, OBJName, OBJPROP_TEXT, "0.0 %");
|
||||
ObjectSetInteger(0, OBJName, OBJPROP_XSIZE, 50);
|
||||
|
||||
OBJName = ToolName + "clusterLoadbar";
|
||||
ObjectSetInteger(0, OBJName, OBJPROP_XSIZE, 50);
|
||||
ObjectSetString(0, OBJName, OBJPROP_TEXT, "0.0 %");
|
||||
|
||||
Ysize = 30;
|
||||
|
||||
// Set data limits from screen
|
||||
int bars = lastbars, ctype[];
|
||||
double low[], high[], close[], open[], total[];
|
||||
ArrayResize(ctype, bars); ArrayInitialize(ctype, 0);
|
||||
|
||||
int resi = (int) (bars / 1000.0)-1;
|
||||
if (resi<=0) resi=2;
|
||||
|
||||
// Copy bars data
|
||||
if (CopyBuffer(ATRHndler, 0, 0, bars, atr)<=0) return;
|
||||
if (CopyLow(Symbol(), tf0, 0, bars, low)<=0) return;
|
||||
if (CopyHigh(Symbol(), tf0, 0, bars, high)<=0) return;
|
||||
if (CopyClose(Symbol(), tf0, 0, bars, close)<=0) return;
|
||||
if (CopyOpen(Symbol(), tf0, 0, bars, open)<=0) return;
|
||||
|
||||
bars = (int) MathMin(ArraySize(open), MathMin((double) bars, ArraySize(close)));
|
||||
|
||||
// Fill candle type (Bull? Bear?)
|
||||
for (int i=bars-ATRPer-1; i>=0; i--)
|
||||
{
|
||||
Print(i," ",ArraySize(close));
|
||||
if (close[i]>open[i]) ctype[i] = +1;
|
||||
else if (close[i]<open[i]) ctype[i] = -1;
|
||||
}
|
||||
|
||||
// Fill S/R matrixes base on selected time-frame candels OHLC data
|
||||
// Implementing Jump rules and candle type limits
|
||||
sup_mat.Resize(0, 0); supclusters.Resize(0, 0);
|
||||
res_mat.Resize(0, 0); resclusters.Resize(0,0);
|
||||
|
||||
for (int i=bars-ATRPer-1; i>=0; i--)
|
||||
{
|
||||
if (myfilters<=1 && ctype[i]==+1 && close[i]-low[i]>=atr[i]*Jmulti) Addsup(low[i]);
|
||||
if (myfilters>=1 && ctype[i]==-1 && close[i]-low[i]>=atr[i]*Jmulti && (close[i]-low[i])/(high[i]-low[i])>=ratio) Addsup(low[i]);
|
||||
|
||||
if (myfilters<=1 && ctype[i]==-1 && high[i]-close[i]>=atr[i]*Jmulti) Addres(high[i]);
|
||||
if (myfilters>=1 && ctype[i]==+1 && high[i]-close[i]>=atr[i]*Jmulti && (high[i]-close[i])/(high[i]-low[i])>=ratio) Addres(high[i]);
|
||||
|
||||
if (MathMod((double) i, resi) == 0)
|
||||
{
|
||||
ObjectSetString(0, ToolName + " Loadbar", OBJPROP_TEXT, DoubleToString(100*(double) (bars-ATRPer-1-i)/(bars-ATRPer-1),1) + " %");
|
||||
ObjectSetInteger(0, ToolName + " Loadbar", OBJPROP_XSIZE, 50 + (int) (300 * ((double) (bars-ATRPer-i+1)/(bars-ATRPer-1))));
|
||||
ObjectSetString(0, ToolName + " TotalRes", OBJPROP_TEXT, "Res. Count: " + IntegerToString(res_mat.Rows()));
|
||||
ObjectSetString(0, ToolName + " TotalSup", OBJPROP_TEXT, "Sup. Count: " + IntegerToString(sup_mat.Rows()));
|
||||
|
||||
ChartRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
startCluster = true;
|
||||
OBJName = ToolName + "clusterLoadbar";
|
||||
ObjectSetInteger(0, OBJName, OBJPROP_XSIZE, 350);
|
||||
ObjectSetString(0, OBJName, OBJPROP_TEXT, "Wait for Cluster Calculation...");
|
||||
|
||||
int supinfo, resinfo, Restarts=5;
|
||||
Cclustering.KMeansGenerate(sup_mat, sup_mat.Rows(), sup_mat.Cols(), LastLNo, Restarts, supinfo, supclusters, sup_xyz);
|
||||
Cclustering.KMeansGenerate(res_mat, res_mat.Rows(), res_mat.Cols(), LastLNo, Restarts, resinfo, resclusters, res_xyz);
|
||||
|
||||
startCluster = false;
|
||||
ObjectSetString(0, OBJName, OBJPROP_TEXT, "Cluster Calculation done!");
|
||||
|
||||
double LevelRes[], LevelSup[], LevelTotal[];
|
||||
ArrayResize(LevelRes, LastLNo); ArrayResize(LevelSup, LastLNo); ArrayResize(LevelTotal, LastLNo);
|
||||
|
||||
OBJName = ToolName + "clusterLoadbar";
|
||||
int stat_x = (int) ObjectGetInteger(ChartID(), OBJName, OBJPROP_XDISTANCE);
|
||||
OBJName = ToolName + " Loadbar";;
|
||||
stat_x += (int) ObjectGetInteger(ChartID(), OBJName, OBJPROP_XSIZE) + dyy;
|
||||
OBJName = ToolName + "Analyse";
|
||||
int stat_y = (int) ObjectGetInteger(ChartID(), OBJName, OBJPROP_YDISTANCE);
|
||||
|
||||
// Closters Graphical
|
||||
OBJName = ToolName + "Zone_Res_Header";
|
||||
ObjectCreate(0, OBJName, OBJ_EDIT, 0, 0, 0);
|
||||
OBJSet(OBJName, "Res. Levels", stat_x, stat_y, 135, Ysize, 12, ResColor, ResColor, BGColor, ALIGN_CENTER, CORNER_LEFT_UPPER, true);
|
||||
|
||||
OBJName = ToolName + "Zone_Sup_Header";
|
||||
ObjectCreate(0, OBJName, OBJ_EDIT, 0, 0, 0); stat_x+=135+dyy;
|
||||
OBJSet(OBJName, "Sup. Levels", stat_x, stat_y, 135, Ysize, 12, SupColor, SupColor, BGColor, ALIGN_CENTER, CORNER_LEFT_UPPER, true);
|
||||
|
||||
stat_y+=Ysize+dyy;
|
||||
Ysize/=2;
|
||||
|
||||
for (int i=0; i<LastLNo; i++)
|
||||
{
|
||||
stat_x -=135+dyy;
|
||||
OBJName = ToolName + "Zone_Res_" + IntegerToString(i);
|
||||
ObjectCreate(0, OBJName, OBJ_EDIT, 0, 0, 0);
|
||||
OBJSet(OBJName, DoubleToString(resclusters.Get(0, i), Digits()), stat_x, stat_y, 135, Ysize, 12, ResColor, ResColor, BGColor, ALIGN_CENTER, CORNER_LEFT_UPPER, true);
|
||||
|
||||
stat_x +=135+dyy;
|
||||
OBJName = ToolName + "Zone_Sup_" + IntegerToString(i);
|
||||
ObjectCreate(0, OBJName, OBJ_EDIT, 0, 0, 0);
|
||||
OBJSet(OBJName, DoubleToString(supclusters.Get(0, i), Digits()), stat_x, stat_y, 135, Ysize, 12, SupColor, SupColor, BGColor, ALIGN_CENTER, CORNER_LEFT_UPPER, true);
|
||||
stat_y+=Ysize+dyy;
|
||||
}
|
||||
|
||||
|
||||
NextChart = ChartOpen(Symbol(), Period());
|
||||
datetime future = TimeCurrent()+ PeriodSeconds(PERIOD_MN1) * 100;
|
||||
double price;
|
||||
|
||||
for (int i=0; i<LastLNo; i++)
|
||||
{
|
||||
price = NormalizeDouble(resclusters.Get(0, i), Digits());
|
||||
OBJName = ToolName + "Zone_Res_" + IntegerToString(i+LastLNo+1);
|
||||
ObjectCreate(NextChart, OBJName, OBJ_HLINE, 0, 0, 0);
|
||||
TrendSet(OBJName, 0, NextChart, price, price, ResColor0, LevelsInt, STYLE_SOLID, true);
|
||||
|
||||
price = NormalizeDouble(supclusters.Get(0, i), Digits());
|
||||
OBJName = ToolName + "Zone_Sup_" + IntegerToString(i+LastLNo+1);
|
||||
ObjectCreate(NextChart, OBJName, OBJ_HLINE, 0, 0, 0);
|
||||
TrendSet(OBJName, 0, NextChart, price, price, SupColor0, LevelsInt, STYLE_SOLID, true);
|
||||
}
|
||||
|
||||
ChartRedraw(NextChart);
|
||||
delete Cclustering;
|
||||
ArrayFree(sup_xyz); ArrayFree(res_xyz);
|
||||
ArrayFree(atr);
|
||||
|
||||
Ysize = 30;
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| Timer function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnTimer()
|
||||
{
|
||||
if (startCluster)
|
||||
{
|
||||
OBJName = ToolName + "clusterLoadbar";
|
||||
|
||||
if (ObjectGetString(0, OBJName, OBJPROP_TEXT)=="Wait for Cluster Calculation")
|
||||
ObjectSetString(0, OBJName, OBJPROP_TEXT, "Wait for Cluster Calculation.");
|
||||
else if (ObjectGetString(0, OBJName, OBJPROP_TEXT)=="Wait for Cluster Calculation.")
|
||||
ObjectSetString(0, OBJName, OBJPROP_TEXT, "Wait for Cluster Calculation..");
|
||||
else if (ObjectGetString(0, OBJName, OBJPROP_TEXT)=="Wait for Cluster Calculation..")
|
||||
ObjectSetString(0, OBJName, OBJPROP_TEXT, "Wait for Cluster Calculation...");
|
||||
else if (ObjectGetString(0, OBJName, OBJPROP_TEXT)=="Wait for Cluster Calculation..")
|
||||
ObjectSetString(0, OBJName, OBJPROP_TEXT, "Wait for Cluster Calculation");
|
||||
|
||||
ChartRedraw();
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
void MeanNormalization(matrix &mat)
|
||||
{
|
||||
vector v = {};
|
||||
|
||||
for(ulong i=0; i<mat.Cols(); i++)
|
||||
{
|
||||
v = mat.Col(i);
|
||||
MeanNormalization(v);
|
||||
mat.Col(v, i);
|
||||
}
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
void MeanNormalization(vector &v)
|
||||
{
|
||||
double mean = v.Mean(),
|
||||
max = v.Max(),
|
||||
min = v.Min();
|
||||
|
||||
for(ulong i=0; i<v.Size(); i++)
|
||||
v[i] = (v[i] - mean) / (max - min);
|
||||
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
void Addsup(double price)
|
||||
{
|
||||
int msize = sup_mat.Rows();
|
||||
sup_mat.Resize(msize+1, 1);
|
||||
sup_mat.Set(msize, 0, price);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
void Addres(double price)
|
||||
{
|
||||
int msize = res_mat.Rows();
|
||||
res_mat.Resize(msize+1, 1);
|
||||
res_mat.Set(msize, 0, price);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| ChartEvent function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnChartEvent(const int id,
|
||||
const long &lparam,
|
||||
const double &dparam,
|
||||
const string &sparam)
|
||||
{
|
||||
if (id == CHARTEVENT_OBJECT_CLICK && sparam==ToolName + "Analyse")
|
||||
{
|
||||
Sleep(100);
|
||||
ObjectSetInteger(ChartID(), sparam, OBJPROP_STATE, false);
|
||||
ChartRedraw();
|
||||
Analyse();
|
||||
}
|
||||
|
||||
if (id == CHARTEVENT_OBJECT_ENDEDIT && sparam==ToolName + " bars.e")
|
||||
{
|
||||
OBJName = sparam;
|
||||
int bar = (int) StringToInteger(ObjectGetString(ChartID(), OBJName, OBJPROP_TEXT));
|
||||
if (bar<0) bar=iBars(Symbol(), tf0)+1;
|
||||
|
||||
if (bar<minbar)
|
||||
{
|
||||
MessageBox("Min. bar to analyse is " + IntegerToString(minbar) + "!", "Min. bar limit", 0);
|
||||
ObjectSetString(0, OBJName, OBJPROP_TEXT, IntegerToString(minbar));
|
||||
}
|
||||
else if (bar>iBars(Symbol(), tf0))
|
||||
{
|
||||
MessageBox("Max. bar to analyse is " + IntegerToString(iBars(Symbol(), tf0)) + "!","Max. bar limit", 0);
|
||||
ObjectSetString(0, OBJName, OBJPROP_TEXT, IntegerToString(iBars(Symbol(), tf0)));
|
||||
}
|
||||
else if (bar>900000)
|
||||
{
|
||||
int mes = MessageBox(IntegerToString(bar) + " bars to analyse is so much and will take time more than 1 minute! Are you sure?", "Max. bar warning", 1);
|
||||
if (mes==2) ObjectSetString(0, OBJName, OBJPROP_TEXT, IntegerToString(lastbars));
|
||||
}
|
||||
|
||||
lastbars = (int) StringToInteger(ObjectGetString(ChartID(), OBJName, OBJPROP_TEXT));
|
||||
}
|
||||
|
||||
|
||||
if (id == CHARTEVENT_OBJECT_ENDEDIT && sparam==ToolName + " LN.e")
|
||||
{
|
||||
OBJName = sparam;
|
||||
int bar = (int) StringToInteger(ObjectGetString(ChartID(), OBJName, OBJPROP_TEXT));
|
||||
if (bar<0) bar=LNo;
|
||||
|
||||
if (bar<minLN)
|
||||
{
|
||||
MessageBox("Min. Level No. to analyse is " + IntegerToString(minLN) + "!", "Min. Level No. limit", 0);
|
||||
ObjectSetString(0, OBJName, OBJPROP_TEXT, IntegerToString(minLN));
|
||||
}
|
||||
else if (bar>500)
|
||||
{
|
||||
MessageBox("Max. Level No. to analyse is 500" + "!","Max. bar limit", 0);
|
||||
ObjectSetString(0, OBJName, OBJPROP_TEXT, IntegerToString(500));
|
||||
}
|
||||
else if (bar>100)
|
||||
{
|
||||
int mes = MessageBox(IntegerToString(bar) + " Level No. analyse is so much and will take time more than 1 minute! Are you sure?", "Max. Level No. warning", 1);
|
||||
if (mes==2) ObjectSetString(0, OBJName, OBJPROP_TEXT, IntegerToString(LastLNo));
|
||||
}
|
||||
|
||||
LastLNo = (int) StringToInteger(ObjectGetString(ChartID(), OBJName, OBJPROP_TEXT));
|
||||
}
|
||||
|
||||
ChartRedraw();
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
void SetScreen()
|
||||
{
|
||||
ChartSetInteger(ChartID(), CHART_FOREGROUND, false);
|
||||
ChartSetInteger(0, CHART_COLOR_CANDLE_BEAR, BGColor);
|
||||
ChartSetInteger(0, CHART_COLOR_CANDLE_BULL, BGColor);
|
||||
ChartSetInteger(0, CHART_COLOR_CHART_LINE, BGColor);
|
||||
ChartSetInteger(0, CHART_COLOR_CHART_DOWN, BGColor);
|
||||
ChartSetInteger(0, CHART_COLOR_CHART_UP, BGColor);
|
||||
ChartSetInteger(0, CHART_COLOR_ASK, BGColor);
|
||||
ChartSetInteger(0, CHART_COLOR_BID, BGColor);
|
||||
ChartSetInteger(0, CHART_COLOR_GRID, BGColor);
|
||||
ChartSetInteger(0, CHART_COLOR_BACKGROUND, BGColor);
|
||||
ChartSetInteger(0, CHART_COLOR_FOREGROUND, BGColor);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
void OBJSet(string OBJNameSet, string txt, int XDis, int YDis, int XSize, int YSize, int FSize, color Fill, color Border, color TColor, ENUM_ALIGN_MODE myAlign, ENUM_BASE_CORNER mycorner, bool myread)
|
||||
{
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_CORNER, mycorner);
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER);
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_XDISTANCE, XDis);
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_YDISTANCE, YDis);
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_XSIZE, XSize);
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_YSIZE, YSize);
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_FONTSIZE, FSize);
|
||||
ObjectSetString(ChartID(), OBJNameSet, OBJPROP_TEXT,txt);
|
||||
ObjectSetString(ChartID(), OBJNameSet, OBJPROP_FONT,"Calibri");
|
||||
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_BGCOLOR, Fill);
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_BORDER_COLOR, Border);
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_COLOR, TColor);
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_ALIGN, myAlign);
|
||||
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_BACK, false);
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_ZORDER,5);
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_HIDDEN, true);
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_READONLY, myread);
|
||||
ObjectSetInteger(ChartID(), OBJNameSet, OBJPROP_SELECTABLE, false);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
void TrendSet(string TrendName, datetime time0, datetime time1, double price1, double price2, color Tcolor, int Twidth, ENUM_LINE_STYLE Tstyle, int b)
|
||||
{
|
||||
ObjectSetInteger(NextChart, TrendName, OBJPROP_TIME, 0, time0);
|
||||
ObjectSetInteger(NextChart, TrendName, OBJPROP_TIME, 1, time1);
|
||||
ObjectSetInteger(NextChart, TrendName, OBJPROP_COLOR, Tcolor);
|
||||
ObjectSetInteger(NextChart, TrendName, OBJPROP_RAY, false);
|
||||
ObjectSetInteger(NextChart, TrendName, OBJPROP_WIDTH, Twidth);
|
||||
ObjectSetInteger(NextChart, TrendName, OBJPROP_STYLE, Tstyle);
|
||||
ObjectSetInteger(NextChart, TrendName, OBJPROP_BACK, true);
|
||||
ObjectSetInteger(NextChart, TrendName, OBJPROP_SELECTABLE, false);
|
||||
ObjectSetInteger(NextChart, TrendName, OBJPROP_TIMEFRAMES, b?OBJ_ALL_PERIODS:OBJ_NO_PERIODS);
|
||||
ObjectSetDouble(NextChart, TrendName, OBJPROP_PRICE, 0, price1);
|
||||
ObjectSetDouble(NextChart, TrendName, OBJPROP_PRICE, 1, price2);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
//------------------------------------------------------------------
|
||||
#property copyright "www.forex-tsd.com"
|
||||
#property link "www.forex-tsd.com"
|
||||
//------------------------------------------------------------------
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
#property indicator_label1 "Super trend hull"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLimeGreen,clrPaleVioletRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
enum enPrices
|
||||
{
|
||||
pr_close, // Close
|
||||
pr_open, // Open
|
||||
pr_high, // High
|
||||
pr_low, // Low
|
||||
pr_median, // Median
|
||||
pr_typical, // Typical
|
||||
pr_weighted, // Weighted
|
||||
pr_average // Average (high+low+oprn+close)/4
|
||||
};
|
||||
|
||||
input int hullPeriod = 12; // Hull period
|
||||
input enPrices Price = pr_median; // Price
|
||||
input int atrPeriod = 12; // ATR period
|
||||
input double atrMultiplier = 0.66; // ATR multiplier
|
||||
|
||||
double st[];
|
||||
double colorBuffer[];
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
int OnInit()
|
||||
{
|
||||
SetIndexBuffer(0,st,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,colorBuffer,INDICATOR_COLOR_INDEX);
|
||||
return(0);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double Up[];
|
||||
double Dn[];
|
||||
double Direction[];
|
||||
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[])
|
||||
{
|
||||
if (ArraySize(Direction)!=rates_total)
|
||||
{
|
||||
ArrayResize(Up,rates_total);
|
||||
ArrayResize(Dn,rates_total);
|
||||
ArrayResize(Direction,rates_total);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
for (int i=(int)MathMax(prev_calculated-1,1); i<rates_total; i++)
|
||||
{
|
||||
double atr = 0;
|
||||
for (int k=0;k<atrPeriod && (i-k-1)>=0; k++)
|
||||
atr += MathMax(high[i-k],close[i-k-1])-MathMin(low[i-k],close[i-k-1]);
|
||||
atr /= atrPeriod;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double cprice = close[i];
|
||||
double mprice = iHull(getPrice(Price,open,close,high,low,i,rates_total),hullPeriod,i,rates_total);
|
||||
Up[i] = mprice+atrMultiplier*atr;
|
||||
Dn[i] = mprice-atrMultiplier*atr;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
colorBuffer[i] = colorBuffer[i-1];
|
||||
Direction[i] = Direction[i-1];
|
||||
if (cprice > Up[i-1]) Direction[i] = 1;
|
||||
if (cprice < Dn[i-1]) Direction[i] = -1;
|
||||
if (Direction[i] > 0)
|
||||
{ Dn[i] = MathMax(Dn[i],Dn[i-1]); st[i] = Dn[i]; }
|
||||
else { Up[i] = MathMin(Up[i],Up[i-1]); st[i] = Up[i]; }
|
||||
if (Direction[i]== 1) colorBuffer[i] = 0;
|
||||
if (Direction[i]==-1) colorBuffer[i] = 1;
|
||||
}
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double workHull[][2];
|
||||
double iHull(double price, double period, int r, int bars, int instanceNo=0)
|
||||
{
|
||||
if (ArrayRange(workHull,0)!= bars) ArrayResize(workHull,bars);
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
int HmaPeriod = (int)MathMax(period,2);
|
||||
int HalfPeriod = (int)MathFloor(HmaPeriod/2);
|
||||
int HullPeriod = (int)MathFloor(MathSqrt(HmaPeriod));
|
||||
double hma,hmw,weight; instanceNo *= 2;
|
||||
|
||||
workHull[r][instanceNo] = price;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
hmw = HalfPeriod; hma = hmw*price;
|
||||
for(int k=1; k<HalfPeriod && (r-k)>=0; k++)
|
||||
{
|
||||
weight = HalfPeriod-k;
|
||||
hmw += weight;
|
||||
hma += weight*workHull[r-k][instanceNo];
|
||||
}
|
||||
workHull[r][instanceNo+1] = 2.0*hma/hmw;
|
||||
|
||||
hmw = HmaPeriod; hma = hmw*price;
|
||||
for(int k=1; k<period && (r-k)>=0; k++)
|
||||
{
|
||||
weight = HmaPeriod-k;
|
||||
hmw += weight;
|
||||
hma += weight*workHull[r-k][instanceNo];
|
||||
}
|
||||
workHull[r][instanceNo+1] -= hma/hmw;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
hmw = HullPeriod; hma = hmw*workHull[r][instanceNo+1];
|
||||
for(int k=1; k<HullPeriod && (r-k)>=0; k++)
|
||||
{
|
||||
weight = HullPeriod-k;
|
||||
hmw += weight;
|
||||
hma += weight*workHull[r-k][1+instanceNo];
|
||||
}
|
||||
return(hma/hmw);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,192 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| SuperTrend.mq5 |
|
||||
//| Copyright 2011, FxGeek |
|
||||
//| http://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2011, FxGeek"
|
||||
#property link " http://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 9
|
||||
#property indicator_plots 2
|
||||
|
||||
#property indicator_label1 "Filling"
|
||||
#property indicator_type1 DRAW_FILLING
|
||||
#property indicator_color1 clrBisque, clrPaleGreen
|
||||
|
||||
#property indicator_label2 "SuperTrend"
|
||||
#property indicator_type2 DRAW_COLOR_LINE
|
||||
#property indicator_color2 clrGreen, clrRed
|
||||
|
||||
input int Periode=10;
|
||||
input double Multiplier=3;
|
||||
input bool Show_Filling=true; // Show as DRAW_FILLING
|
||||
|
||||
double Filled_a[];
|
||||
double Filled_b[];
|
||||
double SuperTrend[];
|
||||
double ColorBuffer[];
|
||||
double Atr[];
|
||||
double Up[];
|
||||
double Down[];
|
||||
double Middle[];
|
||||
double trend[];
|
||||
|
||||
int atrHandle;
|
||||
int changeOfTrend;
|
||||
int flag;
|
||||
int flagh;
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,Filled_a,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,Filled_b,INDICATOR_DATA);
|
||||
SetIndexBuffer(2,SuperTrend,INDICATOR_DATA);
|
||||
SetIndexBuffer(3,ColorBuffer,INDICATOR_COLOR_INDEX);
|
||||
SetIndexBuffer(4,Atr,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(5,Up,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(6,Down,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(7,Middle,INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(8,trend,INDICATOR_CALCULATIONS);
|
||||
|
||||
atrHandle=iATR(_Symbol,_Period,Periode);
|
||||
//---
|
||||
return(0);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
//| 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 to_copy;
|
||||
if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
|
||||
else
|
||||
{
|
||||
to_copy=rates_total-prev_calculated;
|
||||
if(prev_calculated>0) to_copy++;
|
||||
}
|
||||
|
||||
if(IsStopped()) return(0); //Checking for stop flag
|
||||
if(CopyBuffer(atrHandle,0,0,to_copy,Atr)<=0)
|
||||
{
|
||||
Print("Getting Atr is failed! Error",GetLastError());
|
||||
return(0);
|
||||
}
|
||||
|
||||
int first;
|
||||
if(prev_calculated>rates_total || prev_calculated<=0) // checking for the first start of calculation of an indicator
|
||||
{
|
||||
first=Periode; // starting index for calculation of all bars
|
||||
}
|
||||
else
|
||||
{
|
||||
first=prev_calculated-1; // starting number for calculation of new bars
|
||||
}
|
||||
for(int i=first; i<rates_total && !IsStopped(); i++)
|
||||
{
|
||||
Middle[i]=(high[i]+low[i])/2;
|
||||
Up[i] = Middle[i] +(Multiplier*Atr[i]);
|
||||
Down[i]= Middle[i] -(Multiplier*Atr[i]);
|
||||
|
||||
if(close[i]>Up[i-1])
|
||||
{
|
||||
trend[i]=1;
|
||||
if(trend[i-1]==-1) changeOfTrend=1;
|
||||
|
||||
}
|
||||
else if(close[i]<Down[i-1])
|
||||
{
|
||||
trend[i]=-1;
|
||||
if(trend[i-1]==1) changeOfTrend=1;
|
||||
}
|
||||
else if(trend[i-1]==1)
|
||||
{
|
||||
trend[i]=1;
|
||||
changeOfTrend=0;
|
||||
}
|
||||
else if(trend[i-1]==-1)
|
||||
{
|
||||
trend[i]=-1;
|
||||
changeOfTrend=0;
|
||||
}
|
||||
|
||||
if(trend[i]<0 && trend[i-1]>0)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
flag=0;
|
||||
}
|
||||
|
||||
if(trend[i]>0 && trend[i-1]<0)
|
||||
{
|
||||
flagh=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
flagh=0;
|
||||
}
|
||||
|
||||
if(trend[i]>0 && Down[i]<Down[i-1])
|
||||
Down[i]=Down[i-1];
|
||||
|
||||
if(trend[i]<0 && Up[i]>Up[i-1])
|
||||
Up[i]=Up[i-1];
|
||||
|
||||
if(flag==1)
|
||||
Up[i]=Middle[i]+(Multiplier*Atr[i]);
|
||||
|
||||
if(flagh==1)
|
||||
Down[i]=Middle[i]-(Multiplier*Atr[i]);
|
||||
|
||||
//-- Draw the indicator
|
||||
if(trend[i]==1)
|
||||
{
|
||||
SuperTrend[i]=Down[i];
|
||||
if(changeOfTrend==1)
|
||||
{
|
||||
SuperTrend[i-1]=SuperTrend[i-2];
|
||||
changeOfTrend=0;
|
||||
}
|
||||
ColorBuffer[i]=0.0;
|
||||
}
|
||||
else if(trend[i]==-1)
|
||||
{
|
||||
SuperTrend[i]=Up[i];
|
||||
if(changeOfTrend==1)
|
||||
{
|
||||
SuperTrend[i-1]= SuperTrend[i-2];
|
||||
changeOfTrend = 0;
|
||||
}
|
||||
ColorBuffer[i]=1.0;
|
||||
}
|
||||
|
||||
if(Show_Filling)
|
||||
{
|
||||
Filled_a[i]= SuperTrend[i];
|
||||
Filled_b[i]= close[i];
|
||||
}else{
|
||||
Filled_a[i]= EMPTY_VALUE;
|
||||
Filled_b[i]= EMPTY_VALUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,117 @@
|
||||
//------------------------------------------------------------------
|
||||
#property copyright "www.forex-tsd.com"
|
||||
#property link "www.forex-tsd.com"
|
||||
//------------------------------------------------------------------
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 1
|
||||
#property indicator_label1 "Swing line"
|
||||
#property indicator_type1 DRAW_COLOR_LINE
|
||||
#property indicator_color1 clrLimeGreen,clrPaleVioletRed
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 3
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
double swli[];
|
||||
double colorBuffer[];
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
int OnInit()
|
||||
{
|
||||
SetIndexBuffer(0,swli,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,colorBuffer,INDICATOR_COLOR_INDEX);
|
||||
return(0);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| |
|
||||
//+------------------------------------------------------------------+
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
double work[][5];
|
||||
#define hHi 0
|
||||
#define hLo 1
|
||||
#define lHi 2
|
||||
#define lLo 3
|
||||
#define trend 4
|
||||
|
||||
|
||||
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[])
|
||||
{
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
if (ArrayRange(work,0)!=rates_total) ArrayResize(work,rates_total);
|
||||
for (int i=(int)MathMax(prev_calculated-1,0); i<rates_total; i++)
|
||||
{
|
||||
if (i==0)
|
||||
{
|
||||
work[i][hHi] = high[i]; work[i][hLo] = low[i];
|
||||
work[i][lHi] = high[i]; work[i][lLo] = low[i];
|
||||
work[i][trend] = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
work[i][trend] = work[i-1][trend];
|
||||
work[i][hHi] = work[i-1][hHi]; work[i][hLo] = work[i-1][hLo];
|
||||
work[i][lHi] = work[i-1][lHi]; work[i][lLo] = work[i-1][lLo];
|
||||
|
||||
if (work[i-1][trend] == 1)
|
||||
{
|
||||
work[i][hHi] = MathMax(work[i-1][hHi],high[i]);
|
||||
work[i][hLo] = MathMax(work[i-1][hLo],low[i]);
|
||||
if (high[i]<work[i][hLo]) { work[i][trend] = -1; work[i][lHi] = high[i]; work[i][lLo] = low[i]; }
|
||||
}
|
||||
if (work[i-1][trend] == -1)
|
||||
{
|
||||
work[i][lHi] = MathMin(work[i-1][lHi],high[i]);
|
||||
work[i][lLo] = MathMin(work[i-1][lLo],low[i]);
|
||||
if (low[i]>work[i][lHi]) { work[i][trend] = 1; work[i][hHi] = high[i]; work[i][hLo] = low[i]; }
|
||||
}
|
||||
|
||||
if (work[i][trend]==1)
|
||||
swli[i] = work[i][hLo];
|
||||
else swli[i] = work[i][lHi];
|
||||
colorBuffer[i] = colorBuffer[i-1];
|
||||
if (work[i][trend]== 1) colorBuffer[i]= 0;
|
||||
if (work[i][trend]==-1) colorBuffer[i]= 1;
|
||||
}
|
||||
return(rates_total);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,97 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Swings.mq5 |
|
||||
//| Rajesh Nait, Copyright 2023 |
|
||||
//| https://www.mql5.com/en/users/rajeshnait/seller |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Rajesh Nait, Copyright 2023"
|
||||
#property link "https://www.mql5.com/en/users/rajeshnait/seller"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
|
||||
//--- plot Bullish Marubozu
|
||||
#property indicator_label1 "+S"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrSnow
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
//--- plot Bearish Marubozu
|
||||
#property indicator_label2 "-S"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 clrSnow
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
//--- input parameters
|
||||
input group "Swing Low"
|
||||
uchar InpSwingLowCode = 110; // Swing Low: code for style DRAW_ARROW (font Wingdings)
|
||||
int InpSwingLowShift = 10; // Swing Low: vertical shift of arrows in pixels
|
||||
input group "Swing High"
|
||||
uchar InpSwingHighCode = 110; // SwingHigh: code for style DRAW_ARROW (font Wingdings)
|
||||
int InpSwingHighShift =10; // SwingHigh: vertical shift of arrows in pixels
|
||||
//--- indicator buffers
|
||||
double SwingLowBuffer[];
|
||||
double SwingHighBuffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit() {
|
||||
//--- indicator buffers mapping
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,SwingLowBuffer,INDICATOR_DATA);
|
||||
SetIndexBuffer(1,SwingHighBuffer,INDICATOR_DATA);
|
||||
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,Digits());
|
||||
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
|
||||
PlotIndexSetInteger(0,PLOT_ARROW,InpSwingLowCode);
|
||||
PlotIndexSetInteger(1,PLOT_ARROW,InpSwingHighCode);
|
||||
//--- set the vertical shift of arrows in pixels
|
||||
PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,InpSwingLowShift);
|
||||
PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-InpSwingHighShift);
|
||||
//--- set as an empty value 0.0
|
||||
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
|
||||
PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.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[]) {
|
||||
//---
|
||||
if(rates_total<3)
|
||||
return(0);
|
||||
//---
|
||||
int limit=prev_calculated-1;
|
||||
if(prev_calculated==0)
|
||||
limit=2;
|
||||
|
||||
for(int i=limit; i<rates_total-2; i++) {
|
||||
SwingLowBuffer[i]=0.0;
|
||||
SwingHighBuffer[i]=0.0;
|
||||
if(i>0) {
|
||||
SwingHighBuffer[0]=EMPTY_VALUE;
|
||||
if(high[i+2]<high[i+1] && high[i+1]<high[i])
|
||||
if(high[i]>high[i-1] && high[i-1]>high[i-2])
|
||||
SwingHighBuffer[i]=high[i];
|
||||
|
||||
SwingLowBuffer[0]=EMPTY_VALUE;
|
||||
if(low[i+2]>low[i+1] && low[i+1]>low[i])
|
||||
if(low[i]<low[i-1] && low[i-1]<low[i-2])
|
||||
SwingLowBuffer[i]=low[i];
|
||||
}
|
||||
}
|
||||
//--- return value of prev_calculated for next call
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
@@ -0,0 +1,289 @@
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
#define MName "Time Segmented Volume (TSV)"
|
||||
#define MVersion "1.01"
|
||||
#define MBuild "2023-03-27 21:02 WET"
|
||||
#define MCopyright "Copyright \x00A9 2023, Fernando M. I. Carreiro, All rights reserved"
|
||||
#define MProfile "https://www.mql5.com/en/users/FMIC"
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
#property strict
|
||||
#property version MVersion
|
||||
#property description MName
|
||||
#property description "MetaTrader Indicator (Build "MBuild")"
|
||||
#property copyright MCopyright
|
||||
#property link MProfile
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//--- Setup
|
||||
|
||||
#property indicator_separate_window
|
||||
|
||||
// Define number of buffers and plots
|
||||
#define MPlots 3
|
||||
#define MBuffers 7
|
||||
#ifdef __MQL4__
|
||||
#property indicator_buffers ( MPlots + 1 )
|
||||
#else
|
||||
#property indicator_buffers MBuffers
|
||||
#property indicator_plots MPlots
|
||||
#endif
|
||||
|
||||
// Define plot colours and respective indices
|
||||
#define MClrCandleNone C'239,166,117'
|
||||
#define MClrCandleUp C'38,166,154'
|
||||
#define MClrCandleDown C'239,83,80'
|
||||
|
||||
// Display properties for plots
|
||||
#ifdef __MQL4__
|
||||
// Summation plots
|
||||
#property indicator_label1 "Summation (positive)"
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 3
|
||||
#property indicator_color1 MClrCandleUp
|
||||
#property indicator_label2 "Summation (negative)"
|
||||
#property indicator_type2 DRAW_HISTOGRAM
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 3
|
||||
#property indicator_color2 MClrCandleDown
|
||||
// Simple averaging plot
|
||||
#property indicator_label3 "Averaging (simple)"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 2
|
||||
#property indicator_color3 MClrCandleNone
|
||||
// Exponential averaging plot
|
||||
#property indicator_label4 "Averaging (exponential)"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 1
|
||||
#property indicator_color4 MClrCandleNone
|
||||
#else
|
||||
// Define colour index for plots
|
||||
#define MIdxCandleNone 0.0
|
||||
#define MIdxCandleUp 1.0
|
||||
#define MIdxCandleDown 2.0
|
||||
// Summation plot
|
||||
#property indicator_label1 "Summation"
|
||||
#property indicator_type1 DRAW_COLOR_HISTOGRAM
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 5
|
||||
#property indicator_color1 MClrCandleNone, MClrCandleUp, MClrCandleDown
|
||||
// Simple averaging plot
|
||||
#property indicator_label2 "Averaging (simple)"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 2
|
||||
#property indicator_color2 MClrCandleNone
|
||||
// Exponential averaging plot
|
||||
#property indicator_label3 "Averaging (exponential)"
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
#property indicator_color3 MClrCandleNone
|
||||
#endif
|
||||
|
||||
//--- Enumarations
|
||||
|
||||
// Volume weight enumaraton
|
||||
enum EVolumeWeight
|
||||
{
|
||||
EVW_None = 0, // No volume weighting
|
||||
EVW_TickVolume, // Tick volume
|
||||
#ifndef __MQL4__
|
||||
EVW_RealVolume, // Real volume
|
||||
#endif
|
||||
EVW_PriceRange // True price range (pseudo volume)
|
||||
};
|
||||
|
||||
//--- Parameter settings
|
||||
|
||||
input uint i_nSummationPeriod = 13, // Summation period
|
||||
i_nAveragingPeriod = 7; // Averaging period
|
||||
input ENUM_APPLIED_PRICE i_ePriceApplied = PRICE_CLOSE; // Applied price
|
||||
input EVolumeWeight i_eVolumeWeight = EVW_TickVolume; // Applied volume
|
||||
|
||||
//--- Macro definitions
|
||||
|
||||
// Define OnCalculate loop sequencing macros
|
||||
#define MOnCalcPrevTest ( prev_calculated < 1 || prev_calculated > rates_total )
|
||||
#ifdef __MQL4__ // for MQL4 (as series)
|
||||
#define MOnCalcNext( _index ) ( _index-- )
|
||||
#define MOnCalcBack( _index, _offset ) ( _index + _offset )
|
||||
#define MOnCalcCheck( _index ) ( _index >= 0 )
|
||||
#define MOnCalcValid( _index ) ( _index < rates_total )
|
||||
#define MOnCalcStart \
|
||||
( rates_total - ( MOnCalcPrevTest ? 1 : prev_calculated ) )
|
||||
#else // for MQL5 (as non-series)
|
||||
#define MOnCalcNext( _index ) ( _index++ )
|
||||
#define MOnCalcBack( _index, _offset ) ( _index - _offset )
|
||||
#define MOnCalcCheck( _index ) ( _index < rates_total )
|
||||
#define MOnCalcValid( _index ) ( _index >= 0 )
|
||||
#define MOnCalcStart \
|
||||
( MOnCalcPrevTest ? 0 : prev_calculated - 1 )
|
||||
#endif
|
||||
|
||||
// Define applied price macro
|
||||
#define MSetAppliedPrice( _type, _where, _index ) { switch( _type ) { \
|
||||
case PRICE_WEIGHTED: _where = ( high[ _index ] + low[ _index ] + close[ _index ] \
|
||||
+ close[ _index ] ) * 0.25; break; \
|
||||
case PRICE_TYPICAL: _where = ( high[ _index ] + low[ _index ] + close[ _index ] ) / 3.0; break; \
|
||||
case PRICE_MEDIAN: _where = ( high[ _index ] + low[ _index ] ) * 0.5; break; \
|
||||
case PRICE_HIGH: _where = high[ _index ]; break; \
|
||||
case PRICE_LOW: _where = low[ _index ]; break; \
|
||||
case PRICE_OPEN: _where = open[ _index ]; break; \
|
||||
case PRICE_CLOSE: \
|
||||
default: _where = close[ _index ]; }; }
|
||||
|
||||
// Define macro for invalid parameter values
|
||||
#define MCheckParameter( _condition, _text ) if( _condition ) \
|
||||
{ Print( "Error: Invalid ", _text ); return INIT_PARAMETERS_INCORRECT; }
|
||||
|
||||
//--- Global variable declarations
|
||||
|
||||
// Indicator buffers
|
||||
double g_adbPriceApplied[], // Buffer for applied price
|
||||
g_adbVolumePriceDelta[], // Buffer for volume weight price delta change
|
||||
g_adbSummation[], // Buffer for summation of volume weighte price change
|
||||
g_adbSummationSimple[], // Buffer for summation of summation for simple averaging
|
||||
g_adbAveragingSimple[], // Buffer for simple averaging
|
||||
g_adbAveragingExponential[]; // Buffer for exponential averaging
|
||||
#ifdef __MQL4__
|
||||
double g_adbSummationPositive[], // Buffer for positive summation of volume weighte price change
|
||||
g_adbSummationNegative[]; // Buffer for negative summation of volume weighte price change
|
||||
#else
|
||||
double g_adbSummationColour[]; // Buffer for summation colourisation
|
||||
#endif
|
||||
|
||||
// Miscellaneous global variables
|
||||
double g_dbEmaWeight; // Weight to be used for exponential moving averages
|
||||
|
||||
//--- Event handling functions
|
||||
|
||||
// Initialisation event handler
|
||||
int OnInit(void) {
|
||||
// Validate input parameters
|
||||
MCheckParameter( i_nSummationPeriod < 1, "summation period" );
|
||||
MCheckParameter( i_nAveragingPeriod < 1 ||
|
||||
i_nAveragingPeriod > i_nSummationPeriod, "averaging period" );
|
||||
|
||||
// Calculate parameter variables
|
||||
g_dbEmaWeight = 2.0 / ( i_nAveragingPeriod + 1.0 );
|
||||
|
||||
// Set number of significant digits (precision)
|
||||
IndicatorSetInteger( INDICATOR_DIGITS, _Digits );
|
||||
|
||||
// Set buffers
|
||||
int iBuffer = 0;
|
||||
#ifdef __MQL4__
|
||||
IndicatorBuffers( MBuffers + 1 ); // Set total number of buffers (MQL4 Only)
|
||||
SetIndexBuffer( iBuffer++, g_adbSummationPositive, INDICATOR_DATA );
|
||||
SetIndexBuffer( iBuffer++, g_adbSummationNegative, INDICATOR_DATA );
|
||||
#else
|
||||
SetIndexBuffer( iBuffer++, g_adbSummation, INDICATOR_DATA );
|
||||
SetIndexBuffer( iBuffer++, g_adbSummationColour, INDICATOR_COLOR_INDEX );
|
||||
#endif
|
||||
SetIndexBuffer( iBuffer++, g_adbAveragingSimple, INDICATOR_DATA );
|
||||
SetIndexBuffer( iBuffer++, g_adbAveragingExponential, INDICATOR_DATA );
|
||||
SetIndexBuffer( iBuffer++, g_adbPriceApplied, INDICATOR_CALCULATIONS );
|
||||
SetIndexBuffer( iBuffer++, g_adbVolumePriceDelta, INDICATOR_CALCULATIONS );
|
||||
SetIndexBuffer( iBuffer++, g_adbSummationSimple, INDICATOR_CALCULATIONS );
|
||||
#ifdef __MQL4__
|
||||
SetIndexBuffer( iBuffer++, g_adbSummation, INDICATOR_CALCULATIONS );
|
||||
#endif
|
||||
|
||||
// Set indicator name
|
||||
IndicatorSetString( INDICATOR_SHORTNAME, StringFormat(
|
||||
MName " ( %d, %d )", i_nSummationPeriod, i_nAveragingPeriod ) );
|
||||
|
||||
return INIT_SUCCEEDED; // Successful initialisation of indicator
|
||||
};
|
||||
|
||||
// Calculation event handler
|
||||
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[]
|
||||
)
|
||||
{
|
||||
// Main loop — fill in the arrays with data values
|
||||
for( int iCur = MOnCalcStart,
|
||||
iPrev = MOnCalcBack( iCur, 1 ),
|
||||
iSumPrev = MOnCalcBack( iCur, (int) i_nSummationPeriod ),
|
||||
iAvgPrev = MOnCalcBack( iCur, (int) i_nAveragingPeriod );
|
||||
!IsStopped() && MOnCalcCheck( iCur );
|
||||
MOnCalcNext( iCur ), MOnCalcNext( iPrev ), MOnCalcNext( iSumPrev ), MOnCalcNext( iAvgPrev ) )
|
||||
{
|
||||
// Calculate volume to apply
|
||||
double dbVolume = 1.0;
|
||||
switch( i_eVolumeWeight ) {
|
||||
#ifndef __MQL4__
|
||||
case EVW_RealVolume: dbVolume = (double) volume[ iCur ]; break;
|
||||
#endif
|
||||
case EVW_TickVolume: dbVolume = (double) tick_volume[ iCur ]; break;
|
||||
case EVW_PriceRange: if( MOnCalcValid( iPrev ) ) {
|
||||
double dbClosePrev = close[ iPrev ];
|
||||
dbVolume = fmax( high[ iCur ], dbClosePrev )
|
||||
- fmin( low[ iCur ], dbClosePrev );
|
||||
} else dbVolume = high[ iCur ] - low[ iCur ];
|
||||
};
|
||||
|
||||
// Calculate price to apply
|
||||
double dbPriceCur;
|
||||
MSetAppliedPrice( i_ePriceApplied, dbPriceCur, iCur );
|
||||
|
||||
// Calculate volume weighted price delta and sum
|
||||
double dbPricePrev = MOnCalcValid( iPrev ) ? g_adbPriceApplied [ iPrev ] : open[ iCur ],
|
||||
dbPriceDelta = dbPriceCur - dbPricePrev,
|
||||
dbVolumePriceDelta = dbPriceDelta * dbVolume,
|
||||
dbSummation = dbVolumePriceDelta
|
||||
+ ( MOnCalcValid( iPrev ) ? g_adbSummation[ iPrev ] : 0.0 )
|
||||
- ( MOnCalcValid( iSumPrev ) ? g_adbVolumePriceDelta[ iSumPrev ] : 0.0 );
|
||||
// Define colourasation
|
||||
#ifdef __MQL4__
|
||||
double dbSummationPositive = dbSummation > 0.0 ? dbSummation : 0.0,
|
||||
dbSummationNegative = dbSummation < 0.0 ? dbSummation : 0.0;
|
||||
#else
|
||||
double dbSummationColour = dbSummation > 0.0 ? MIdxCandleUp
|
||||
: ( dbSummation < 0.0 ? MIdxCandleDown
|
||||
: MIdxCandleNone );
|
||||
#endif
|
||||
|
||||
// Calculate simple summation and averaging
|
||||
double dbSumSimpleCur = dbSummation
|
||||
+ ( MOnCalcValid( iPrev ) ? g_adbSummationSimple[ iPrev ] : 0.0 )
|
||||
- ( MOnCalcValid( iAvgPrev ) ? g_adbSummation[ iAvgPrev ] : 0.0 ),
|
||||
dbAverageSimpleCur = dbSumSimpleCur / i_nAveragingPeriod;
|
||||
|
||||
// Calculate exponential averaging
|
||||
double dbAverageExponentialPrev = MOnCalcValid( iPrev ) ? g_adbAveragingExponential[ iPrev ] : dbSummation,
|
||||
dbAverageExponentialCur = dbAverageExponentialPrev
|
||||
+ ( dbSummation - dbAverageExponentialPrev )
|
||||
* g_dbEmaWeight;
|
||||
|
||||
// Set buffer values
|
||||
g_adbPriceApplied[ iCur ] = dbPriceCur;
|
||||
g_adbVolumePriceDelta[ iCur ] = dbVolumePriceDelta;
|
||||
g_adbSummation[ iCur ] = dbSummation;
|
||||
g_adbSummationSimple[ iCur ] = dbSumSimpleCur;
|
||||
g_adbAveragingSimple[ iCur ] = dbAverageSimpleCur;
|
||||
g_adbAveragingExponential[ iCur ] = dbAverageExponentialCur;
|
||||
#ifdef __MQL4__
|
||||
g_adbSummationPositive[ iCur ] = dbSummationPositive;
|
||||
g_adbSummationNegative[ iCur ] = dbSummationNegative;
|
||||
#else
|
||||
g_adbSummationColour[ iCur ] = dbSummationColour;
|
||||
#endif
|
||||
};
|
||||
|
||||
return rates_total; // Return value for prev_calculated of next call
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
Binary file not shown.
@@ -0,0 +1,114 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| Timeframe Confluence Detector.mq5 |
|
||||
//| |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "phade"
|
||||
#property version "1.00"
|
||||
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 5
|
||||
#property indicator_plots 3
|
||||
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrBurlyWood
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrGray
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrDarkGray
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
#define offset 60
|
||||
|
||||
input ENUM_TIMEFRAMES timeframe_a = PERIOD_CURRENT; //Current period
|
||||
input ENUM_TIMEFRAMES timeframe_b = PERIOD_H2; // 1st timeframe deviation to current period
|
||||
input ENUM_TIMEFRAMES timeframe_c = PERIOD_H1; // 2nd timeframe deviation to current period
|
||||
|
||||
int bars;
|
||||
|
||||
double buf_a[];
|
||||
double buf_b[];
|
||||
double buf_c[];
|
||||
|
||||
double deviator_a[], deviator_b[];
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
IndicatorRelease(0);
|
||||
|
||||
SetIndexBuffer(0, buf_a, INDICATOR_DATA);
|
||||
SetIndexBuffer(1, deviator_a, INDICATOR_DATA);
|
||||
SetIndexBuffer(2, deviator_b, INDICATOR_DATA);
|
||||
SetIndexBuffer(3, buf_b, INDICATOR_CALCULATIONS);
|
||||
SetIndexBuffer(4, buf_c, INDICATOR_CALCULATIONS);
|
||||
|
||||
ArraySetAsSeries(buf_a,true);
|
||||
ArraySetAsSeries(buf_b,true);
|
||||
ArraySetAsSeries(buf_c,true);
|
||||
ArraySetAsSeries(deviator_a,true);
|
||||
ArraySetAsSeries(deviator_b,true);
|
||||
|
||||
PlotIndexSetString(0, PLOT_LABEL, TimeframeToString(timeframe_a));
|
||||
PlotIndexSetString(1, PLOT_LABEL, "Deviation from " + TimeframeToString(timeframe_b) + " to " + TimeframeToString(timeframe_a));
|
||||
PlotIndexSetString(2, PLOT_LABEL, "Deviation from " + TimeframeToString(timeframe_c) + " to " + TimeframeToString(timeframe_a));
|
||||
|
||||
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[])
|
||||
{
|
||||
CopySeries(Symbol(), timeframe_a, 0, rates_total, COPY_RATES_CLOSE, buf_a);
|
||||
CopySeries(Symbol(), timeframe_b, 0, rates_total, COPY_RATES_CLOSE, buf_b);
|
||||
CopySeries(Symbol(), timeframe_c, 0, rates_total, COPY_RATES_CLOSE, buf_c);
|
||||
|
||||
for(int i = rates_total - 1; i>=0; i--){
|
||||
|
||||
deviator_a[i] = MathAbs(buf_b[i] - buf_a[i]) + buf_b[i] - offset*_Point;
|
||||
deviator_b[i] = MathAbs(buf_c[i] - buf_a[i]) + buf_c[i] - (offset*2)*_Point;
|
||||
}
|
||||
|
||||
return(rates_total);
|
||||
}
|
||||
|
||||
|
||||
string TimeframeToString(const ENUM_TIMEFRAMES timeframe)
|
||||
{
|
||||
string result;
|
||||
switch (timeframe){
|
||||
|
||||
case PERIOD_M1: result = "M1"; break;
|
||||
case PERIOD_M5: result = "M5"; break;
|
||||
case PERIOD_M15: result = "M15"; break;
|
||||
case PERIOD_M30: result = "M30"; break;
|
||||
case PERIOD_H1: result = "H1"; break;
|
||||
case PERIOD_H2: result = "H2"; break;
|
||||
case PERIOD_H4: result = "H4"; break;
|
||||
case PERIOD_D1: result = "D1"; break;
|
||||
case PERIOD_W1: result = "W1"; break;
|
||||
case PERIOD_MN1: result = "MN1"; break;
|
||||
default: result = ""; break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| TrendLinearReg.mq5 |
|
||||
//| Copyright 2022, MetaQuotes Ltd. |
|
||||
//| https://www.mql5.com |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Copyright 2022, MetaQuotes Ltd."
|
||||
#property link "https://www.mql5.com"
|
||||
#property version "1.00"
|
||||
#property indicator_separate_window
|
||||
|
||||
#property indicator_buffers 2
|
||||
#property indicator_plots 2
|
||||
#property indicator_color1 LimeGreen
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
#property indicator_color2 Red
|
||||
#property indicator_type2 DRAW_HISTOGRAM
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
extern int barsToCount=34; // Bars to calculate
|
||||
|
||||
double buffer0[];
|
||||
double buffer1[];
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
//--- indicator buffers mapping
|
||||
SetIndexBuffer(0,buffer0);
|
||||
SetIndexBuffer(1,buffer1);
|
||||
//---
|
||||
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[])
|
||||
{
|
||||
//---
|
||||
|
||||
double b, c, sumy, sumx, sumxy, sumx2;
|
||||
double prev;
|
||||
double current;
|
||||
|
||||
if(rates_total <= barsToCount)
|
||||
return rates_total;
|
||||
|
||||
int start = prev_calculated;
|
||||
if(prev_calculated < barsToCount)
|
||||
start = barsToCount;
|
||||
|
||||
for(int index = start; index < rates_total; index++)
|
||||
{
|
||||
|
||||
sumy=0.0;
|
||||
sumx=0.0;
|
||||
sumxy=0.0;
|
||||
sumx2=0.0;
|
||||
for(int i=0; i < barsToCount ; i++)
|
||||
{
|
||||
sumy+=close[index-i];
|
||||
sumxy+=close[index-i]*(1+i);
|
||||
sumx+=(1+i);
|
||||
sumx2+=(1+i)*(1+i);
|
||||
}
|
||||
|
||||
c=sumx2*barsToCount-sumx*sumx;
|
||||
|
||||
if(c==0)
|
||||
c=0.1;
|
||||
|
||||
b=(sumxy*barsToCount-sumx*sumy)/c;
|
||||
|
||||
current=-1000*b;
|
||||
prev=current;
|
||||
|
||||
|
||||
if(buffer1[index-1] !=EMPTY_VALUE)
|
||||
prev=buffer1[index-1];
|
||||
else
|
||||
if(buffer0[index-1] !=EMPTY_VALUE)
|
||||
prev=buffer0[index-1];
|
||||
|
||||
if(current>=prev)
|
||||
{
|
||||
buffer0[index]= current;
|
||||
buffer1[index]= EMPTY_VALUE;
|
||||
}
|
||||
else
|
||||
if(current<prev)
|
||||
{
|
||||
buffer1[index]= current;
|
||||
buffer0[index]= EMPTY_VALUE;
|
||||
}
|
||||
/*
|
||||
*/
|
||||
}
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,67 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| YMA.mq5 |
|
||||
//| Yuriy Tokman |
|
||||
//| http://ytg.com.ua |
|
||||
//+------------------------------------------------------------------+
|
||||
#property copyright "Yuriy Tokman"
|
||||
#property link "http://ytg.com.ua"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
|
||||
#property indicator_buffers 1
|
||||
#property indicator_plots 1
|
||||
#property indicator_width1 2
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrDarkViolet
|
||||
//--- input parameters
|
||||
input int YMA_Period=21; // Period
|
||||
//--- indicator buffers
|
||||
double Buffer[];
|
||||
//+------------------------------------------------------------------+
|
||||
//| Custom indicator initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
SetIndexBuffer(0,Buffer);
|
||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
||||
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,YMA_Period);
|
||||
string short_name="YMA";
|
||||
IndicatorSetString(INDICATOR_SHORTNAME,short_name+"("+string(YMA_Period)+")");
|
||||
//---
|
||||
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 i,limit;
|
||||
//--- check for rates
|
||||
if(rates_total<YMA_Period) return(0);
|
||||
//--- preliminary calculations
|
||||
if(prev_calculated==0)limit=YMA_Period;
|
||||
else limit=prev_calculated-1;
|
||||
//--- the main loop of calculations
|
||||
for(i=limit;i<rates_total && !IsStopped();i++)
|
||||
{
|
||||
double res =0;
|
||||
for(int j=i;j>i-YMA_Period && j>0;j--)
|
||||
{
|
||||
res += (close[j]+open[j]+high[j]+low[j])/4;
|
||||
}
|
||||
Buffer[i]=res/YMA_Period;
|
||||
}
|
||||
//----
|
||||
return(rates_total);
|
||||
}
|
||||
//+------------------------------------------------------------------+
|
||||
Reference in New Issue
Block a user