cleanup backuped indicators ...
This commit is contained in:
@@ -1,552 +0,0 @@
|
|||||||
//+------------------------------------------------------------------+
|
|
||||||
//| VWAP.mq5 |
|
|
||||||
//| Copyright 2015, SOL Digital Consultoria LTDA |
|
|
||||||
//| http://www.soldigitalconsultoria.com.br |
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
#property copyright "Copyright 2015, SOL Digital Consultoria LTDA"
|
|
||||||
#property link "http://www.soldigitalconsultoria.com.br"
|
|
||||||
#property version "1.47"
|
|
||||||
|
|
||||||
#property indicator_chart_window
|
|
||||||
#property indicator_buffers 8
|
|
||||||
#property indicator_plots 8
|
|
||||||
|
|
||||||
//--- plot VWAP
|
|
||||||
#property indicator_label1 "VWAP Daily"
|
|
||||||
#property indicator_type1 DRAW_LINE
|
|
||||||
#property indicator_color1 clrRed
|
|
||||||
#property indicator_style1 STYLE_DASH
|
|
||||||
#property indicator_width1 2
|
|
||||||
|
|
||||||
#property indicator_label2 "VWAP Weekly"
|
|
||||||
#property indicator_type2 DRAW_LINE
|
|
||||||
#property indicator_color2 clrBlue
|
|
||||||
#property indicator_style2 STYLE_DASH
|
|
||||||
#property indicator_width2 2
|
|
||||||
|
|
||||||
#property indicator_label3 "VWAP Monthly"
|
|
||||||
#property indicator_type3 DRAW_LINE
|
|
||||||
#property indicator_color3 clrGreen
|
|
||||||
#property indicator_style3 STYLE_DASH
|
|
||||||
#property indicator_width3 2
|
|
||||||
|
|
||||||
#property indicator_label4 "VWAP Level 01"
|
|
||||||
#property indicator_type4 DRAW_LINE
|
|
||||||
#property indicator_color4 clrGray
|
|
||||||
#property indicator_style4 STYLE_DASH
|
|
||||||
#property indicator_width4 2
|
|
||||||
|
|
||||||
#property indicator_label5 "VWAP Level 02"
|
|
||||||
#property indicator_type5 DRAW_LINE
|
|
||||||
#property indicator_color5 clrYellow
|
|
||||||
#property indicator_style5 STYLE_DASH
|
|
||||||
#property indicator_width5 2
|
|
||||||
|
|
||||||
#property indicator_label6 "VWAP Level 03"
|
|
||||||
#property indicator_type6 DRAW_LINE
|
|
||||||
#property indicator_color6 clrGreen
|
|
||||||
#property indicator_style6 STYLE_DASH
|
|
||||||
#property indicator_width6 2
|
|
||||||
|
|
||||||
#property indicator_label7 "VWAP Level 04"
|
|
||||||
#property indicator_type7 DRAW_LINE
|
|
||||||
#property indicator_color7 clrBlack
|
|
||||||
#property indicator_style7 STYLE_DASH
|
|
||||||
#property indicator_width7 2
|
|
||||||
|
|
||||||
#property indicator_label8 "VWAP Level 05"
|
|
||||||
#property indicator_type8 DRAW_LINE
|
|
||||||
#property indicator_color8 clrBlue
|
|
||||||
#property indicator_style8 STYLE_DASH
|
|
||||||
#property indicator_width8 2
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
//| |
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
enum DATE_TYPE
|
|
||||||
{
|
|
||||||
DAILY,
|
|
||||||
WEEKLY,
|
|
||||||
MONTHLY
|
|
||||||
};
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
//| |
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
enum PRICE_TYPE
|
|
||||||
{
|
|
||||||
OPEN,
|
|
||||||
CLOSE,
|
|
||||||
HIGH,
|
|
||||||
LOW,
|
|
||||||
OPEN_CLOSE,
|
|
||||||
HIGH_LOW,
|
|
||||||
CLOSE_HIGH_LOW,
|
|
||||||
OPEN_CLOSE_HIGH_LOW
|
|
||||||
};
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
//| |
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
datetime CreateDateTime(DATE_TYPE nReturnType=DAILY,datetime dtDay=D'2000.01.01 00:00:00',int pHour=0,int pMinute=0,int pSecond=0)
|
|
||||||
{
|
|
||||||
datetime dtReturnDate;
|
|
||||||
MqlDateTime timeStruct;
|
|
||||||
|
|
||||||
TimeToStruct(dtDay,timeStruct);
|
|
||||||
timeStruct.hour = pHour;
|
|
||||||
timeStruct.min = pMinute;
|
|
||||||
timeStruct.sec = pSecond;
|
|
||||||
dtReturnDate=(StructToTime(timeStruct));
|
|
||||||
|
|
||||||
if(nReturnType==WEEKLY)
|
|
||||||
{
|
|
||||||
while(timeStruct.day_of_week!=0)
|
|
||||||
{
|
|
||||||
dtReturnDate=(dtReturnDate-86400);
|
|
||||||
TimeToStruct(dtReturnDate,timeStruct);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(nReturnType==MONTHLY)
|
|
||||||
{
|
|
||||||
timeStruct.day=1;
|
|
||||||
dtReturnDate=(StructToTime(timeStruct));
|
|
||||||
}
|
|
||||||
|
|
||||||
return dtReturnDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
sinput string Indicator_Name="Volume Weighted Average Price (VWAP)";
|
|
||||||
input PRICE_TYPE Price_Type = CLOSE_HIGH_LOW;
|
|
||||||
input bool Enable_Daily = true;
|
|
||||||
input bool Enable_Weekly = true;
|
|
||||||
input bool Enable_Monthly = true;
|
|
||||||
input bool Enable_Level_01 = false;
|
|
||||||
input int VWAP_Level_01_Period = 5;
|
|
||||||
input bool Enable_Level_02 = false;
|
|
||||||
input int VWAP_Level_02_Period = 13;
|
|
||||||
input bool Enable_Level_03 = false;
|
|
||||||
input int VWAP_Level_03_Period = 20;
|
|
||||||
input bool Enable_Level_04 = false;
|
|
||||||
input int VWAP_Level_04_Period = 30;
|
|
||||||
input bool Enable_Level_05 = false;
|
|
||||||
input int VWAP_Level_05_Period = 40;
|
|
||||||
|
|
||||||
bool Show_Daily_Value = true;
|
|
||||||
bool Show_Weekly_Value = true;
|
|
||||||
bool Show_Monthly_Value = true;
|
|
||||||
|
|
||||||
double VWAP_Buffer_Daily[];
|
|
||||||
double VWAP_Buffer_Weekly[];
|
|
||||||
double VWAP_Buffer_Monthly[];
|
|
||||||
double VWAP_Buffer_01[];
|
|
||||||
double VWAP_Buffer_02[];
|
|
||||||
double VWAP_Buffer_03[];
|
|
||||||
double VWAP_Buffer_04[];
|
|
||||||
double VWAP_Buffer_05[];
|
|
||||||
|
|
||||||
double nPriceArr[];
|
|
||||||
double nTotalTPV[];
|
|
||||||
double nTotalVol[];
|
|
||||||
double nSumDailyTPV = 0, nSumWeeklyTPV = 0, nSumMonthlyTPV = 0;
|
|
||||||
double nSumDailyVol = 0, nSumWeeklyVol = 0, nSumMonthlyVol = 0;
|
|
||||||
|
|
||||||
int nIdxDaily=0,nIdxWeekly=0,nIdxMonthly=0,nIdx=0;
|
|
||||||
|
|
||||||
bool bIsFirstRun=true;
|
|
||||||
|
|
||||||
ENUM_TIMEFRAMES LastTimePeriod=PERIOD_MN1;
|
|
||||||
|
|
||||||
string sDailyStr = "";
|
|
||||||
string sWeeklyStr = "";
|
|
||||||
string sMonthlyStr = "";
|
|
||||||
string sLevel01Str = "";
|
|
||||||
string sLevel02Str = "";
|
|
||||||
string sLevel03Str = "";
|
|
||||||
string sLevel04Str = "";
|
|
||||||
string sLevel05Str = "";
|
|
||||||
datetime dtLastDay=CreateDateTime(DAILY),dtLastWeek=CreateDateTime(WEEKLY),dtLastMonth=CreateDateTime(MONTHLY);
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
//| |
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
|
|
||||||
|
|
||||||
SetIndexBuffer(0,VWAP_Buffer_Daily,INDICATOR_DATA);
|
|
||||||
SetIndexBuffer(1,VWAP_Buffer_Weekly,INDICATOR_DATA);
|
|
||||||
SetIndexBuffer(2,VWAP_Buffer_Monthly,INDICATOR_DATA);
|
|
||||||
SetIndexBuffer(3,VWAP_Buffer_01,INDICATOR_DATA);
|
|
||||||
SetIndexBuffer(4,VWAP_Buffer_02,INDICATOR_DATA);
|
|
||||||
SetIndexBuffer(5,VWAP_Buffer_03,INDICATOR_DATA);
|
|
||||||
SetIndexBuffer(6,VWAP_Buffer_04,INDICATOR_DATA);
|
|
||||||
SetIndexBuffer(7,VWAP_Buffer_05,INDICATOR_DATA);
|
|
||||||
|
|
||||||
ObjectCreate(0,"VWAP_Daily",OBJ_LABEL,0,0,0);
|
|
||||||
ObjectSetInteger(0,"VWAP_Daily",OBJPROP_CORNER,3);
|
|
||||||
ObjectSetInteger(0,"VWAP_Daily",OBJPROP_XDISTANCE,180);
|
|
||||||
ObjectSetInteger(0,"VWAP_Daily",OBJPROP_YDISTANCE,40);
|
|
||||||
ObjectSetInteger(0,"VWAP_Daily",OBJPROP_COLOR,indicator_color1);
|
|
||||||
ObjectSetInteger(0,"VWAP_Daily",OBJPROP_FONTSIZE,7);
|
|
||||||
ObjectSetString(0,"VWAP_Daily",OBJPROP_FONT,"Verdana");
|
|
||||||
ObjectSetString(0,"VWAP_Daily",OBJPROP_TEXT," ");
|
|
||||||
|
|
||||||
ObjectCreate(0,"VWAP_Weekly",OBJ_LABEL,0,0,0);
|
|
||||||
ObjectSetInteger(0,"VWAP_Weekly",OBJPROP_CORNER,3);
|
|
||||||
ObjectSetInteger(0,"VWAP_Weekly",OBJPROP_XDISTANCE,180);
|
|
||||||
ObjectSetInteger(0,"VWAP_Weekly",OBJPROP_YDISTANCE,60);
|
|
||||||
ObjectSetInteger(0,"VWAP_Weekly",OBJPROP_COLOR,indicator_color2);
|
|
||||||
ObjectSetInteger(0,"VWAP_Weekly",OBJPROP_FONTSIZE,7);
|
|
||||||
ObjectSetString(0,"VWAP_Weekly",OBJPROP_FONT,"Verdana");
|
|
||||||
ObjectSetString(0,"VWAP_Weekly",OBJPROP_TEXT," ");
|
|
||||||
|
|
||||||
ObjectCreate(0,"VWAP_Monthly",OBJ_LABEL,0,0,0);
|
|
||||||
ObjectSetInteger(0,"VWAP_Monthly",OBJPROP_CORNER,3);
|
|
||||||
ObjectSetInteger(0,"VWAP_Monthly",OBJPROP_XDISTANCE,180);
|
|
||||||
ObjectSetInteger(0,"VWAP_Monthly",OBJPROP_YDISTANCE,80);
|
|
||||||
ObjectSetInteger(0,"VWAP_Monthly",OBJPROP_COLOR,indicator_color3);
|
|
||||||
ObjectSetInteger(0,"VWAP_Monthly",OBJPROP_FONTSIZE,7);
|
|
||||||
ObjectSetString(0,"VWAP_Monthly",OBJPROP_FONT,"Verdana");
|
|
||||||
ObjectSetString(0,"VWAP_Monthly",OBJPROP_TEXT," ");
|
|
||||||
|
|
||||||
ObjectCreate(0,"VWAP_Level_01",OBJ_LABEL,0,0,0);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_01",OBJPROP_CORNER,3);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_01",OBJPROP_XDISTANCE,180);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_01",OBJPROP_YDISTANCE,100);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_01",OBJPROP_COLOR,indicator_color4);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_01",OBJPROP_FONTSIZE,7);
|
|
||||||
ObjectSetString(0,"VWAP_Level_01",OBJPROP_FONT,"Verdana");
|
|
||||||
ObjectSetString(0,"VWAP_Level_01",OBJPROP_TEXT," ");
|
|
||||||
|
|
||||||
ObjectCreate(0,"VWAP_Level_02",OBJ_LABEL,0,0,0);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_02",OBJPROP_CORNER,3);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_02",OBJPROP_XDISTANCE,180);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_02",OBJPROP_YDISTANCE,120);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_02",OBJPROP_COLOR,indicator_color5);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_02",OBJPROP_FONTSIZE,7);
|
|
||||||
ObjectSetString(0,"VWAP_Level_02",OBJPROP_FONT,"Verdana");
|
|
||||||
ObjectSetString(0,"VWAP_Level_02",OBJPROP_TEXT," ");
|
|
||||||
|
|
||||||
ObjectCreate(0,"VWAP_Level_03",OBJ_LABEL,0,0,0);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_03",OBJPROP_CORNER,3);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_03",OBJPROP_XDISTANCE,180);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_03",OBJPROP_YDISTANCE,140);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_03",OBJPROP_COLOR,indicator_color6);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_03",OBJPROP_FONTSIZE,7);
|
|
||||||
ObjectSetString(0,"VWAP_Level_03",OBJPROP_FONT,"Verdana");
|
|
||||||
ObjectSetString(0,"VWAP_Level_03",OBJPROP_TEXT," ");
|
|
||||||
|
|
||||||
ObjectCreate(0,"VWAP_Level_04",OBJ_LABEL,0,0,0);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_04",OBJPROP_CORNER,3);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_04",OBJPROP_XDISTANCE,180);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_04",OBJPROP_YDISTANCE,160);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_04",OBJPROP_COLOR,indicator_color7);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_04",OBJPROP_FONTSIZE,7);
|
|
||||||
ObjectSetString(0,"VWAP_Level_04",OBJPROP_FONT,"Verdana");
|
|
||||||
ObjectSetString(0,"VWAP_Level_04",OBJPROP_TEXT," ");
|
|
||||||
|
|
||||||
ObjectCreate(0,"VWAP_Level_05",OBJ_LABEL,0,0,0);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_05",OBJPROP_CORNER,3);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_05",OBJPROP_XDISTANCE,180);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_05",OBJPROP_YDISTANCE,180);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_05",OBJPROP_COLOR,indicator_color8);
|
|
||||||
ObjectSetInteger(0,"VWAP_Level_05",OBJPROP_FONTSIZE,7);
|
|
||||||
ObjectSetString(0,"VWAP_Level_05",OBJPROP_FONT,"Verdana");
|
|
||||||
ObjectSetString(0,"VWAP_Level_05",OBJPROP_TEXT," ");
|
|
||||||
|
|
||||||
return(INIT_SUCCEEDED);
|
|
||||||
}
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
//| |
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
void OnDeinit(const int pReason)
|
|
||||||
{
|
|
||||||
ObjectDelete(0,"VWAP_Daily");
|
|
||||||
ObjectDelete(0,"VWAP_Weekly");
|
|
||||||
ObjectDelete(0,"VWAP_Monthly");
|
|
||||||
ObjectDelete(0,"VWAP_Level_01");
|
|
||||||
ObjectDelete(0,"VWAP_Level_02");
|
|
||||||
ObjectDelete(0,"VWAP_Level_03");
|
|
||||||
ObjectDelete(0,"VWAP_Level_04");
|
|
||||||
ObjectDelete(0,"VWAP_Level_05");
|
|
||||||
}
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
//| |
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
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(PERIOD_CURRENT!=LastTimePeriod)
|
|
||||||
{
|
|
||||||
bIsFirstRun=true;
|
|
||||||
LastTimePeriod=PERIOD_CURRENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(rates_total>prev_calculated || bIsFirstRun)
|
|
||||||
{
|
|
||||||
ArrayResize(nPriceArr,rates_total);
|
|
||||||
ArrayResize(nTotalTPV,rates_total);
|
|
||||||
ArrayResize(nTotalVol,rates_total);
|
|
||||||
|
|
||||||
if(Enable_Daily) {nIdx = nIdxDaily; nSumDailyTPV = 0; nSumDailyVol = 0;}
|
|
||||||
if(Enable_Weekly) {nIdx = nIdxWeekly; nSumWeeklyTPV = 0; nSumWeeklyVol = 0;}
|
|
||||||
if(Enable_Monthly) {nIdx = nIdxMonthly; nSumMonthlyTPV = 0; nSumMonthlyVol = 0;}
|
|
||||||
|
|
||||||
for(; nIdx<rates_total; nIdx++)
|
|
||||||
{
|
|
||||||
if(CreateDateTime(DAILY,time[nIdx])!=dtLastDay)
|
|
||||||
{
|
|
||||||
nIdxDaily=nIdx;
|
|
||||||
nSumDailyTPV = 0;
|
|
||||||
nSumDailyVol = 0;
|
|
||||||
}
|
|
||||||
if(CreateDateTime(WEEKLY,time[nIdx])!=dtLastWeek)
|
|
||||||
{
|
|
||||||
nIdxWeekly=nIdx;
|
|
||||||
nSumWeeklyTPV = 0;
|
|
||||||
nSumWeeklyVol = 0;
|
|
||||||
}
|
|
||||||
if(CreateDateTime(MONTHLY,time[nIdx])!=dtLastMonth)
|
|
||||||
{
|
|
||||||
nIdxMonthly=nIdx;
|
|
||||||
nSumMonthlyTPV = 0;
|
|
||||||
nSumMonthlyVol = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
nPriceArr[nIdx] = 0;
|
|
||||||
nTotalTPV[nIdx] = 0;
|
|
||||||
nTotalVol[nIdx] = 0;
|
|
||||||
|
|
||||||
switch(Price_Type)
|
|
||||||
{
|
|
||||||
case OPEN:
|
|
||||||
nPriceArr[nIdx]=open[nIdx];
|
|
||||||
break;
|
|
||||||
case CLOSE:
|
|
||||||
nPriceArr[nIdx]=close[nIdx];
|
|
||||||
break;
|
|
||||||
case HIGH:
|
|
||||||
nPriceArr[nIdx]=high[nIdx];
|
|
||||||
break;
|
|
||||||
case LOW:
|
|
||||||
nPriceArr[nIdx]=low[nIdx];
|
|
||||||
break;
|
|
||||||
case HIGH_LOW:
|
|
||||||
nPriceArr[nIdx]=(high[nIdx]+low[nIdx])/2;
|
|
||||||
break;
|
|
||||||
case OPEN_CLOSE:
|
|
||||||
nPriceArr[nIdx]=(open[nIdx]+close[nIdx])/2;
|
|
||||||
break;
|
|
||||||
case CLOSE_HIGH_LOW:
|
|
||||||
nPriceArr[nIdx]=(close[nIdx]+high[nIdx]+low[nIdx])/3;
|
|
||||||
break;
|
|
||||||
case OPEN_CLOSE_HIGH_LOW:
|
|
||||||
nPriceArr[nIdx]=(open[nIdx]+close[nIdx]+high[nIdx]+low[nIdx])/4;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
nPriceArr[nIdx]=(close[nIdx]+high[nIdx]+low[nIdx])/3;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(tick_volume[nIdx])
|
|
||||||
{
|
|
||||||
nTotalTPV[nIdx] = (nPriceArr[nIdx] * tick_volume[nIdx]);
|
|
||||||
nTotalVol[nIdx] = (double)tick_volume[nIdx];
|
|
||||||
} else if(volume[nIdx]) {
|
|
||||||
nTotalTPV[nIdx] = (nPriceArr[nIdx] * volume[nIdx]);
|
|
||||||
nTotalVol[nIdx] = (double)volume[nIdx];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Enable_Daily && (nIdx>=nIdxDaily))
|
|
||||||
{
|
|
||||||
nSumDailyTPV += nTotalTPV[nIdx];
|
|
||||||
nSumDailyVol += nTotalVol[nIdx];
|
|
||||||
|
|
||||||
if(nSumDailyVol)
|
|
||||||
VWAP_Buffer_Daily[nIdx]=(nSumDailyTPV/nSumDailyVol);
|
|
||||||
|
|
||||||
if((sDailyStr!="VWAP Daily: "+(string)NormalizeDouble(VWAP_Buffer_Daily[nIdx],_Digits)) && Show_Daily_Value)
|
|
||||||
{
|
|
||||||
sDailyStr="VWAP Daily: "+(string)NormalizeDouble(VWAP_Buffer_Daily[nIdx],_Digits);
|
|
||||||
ObjectSetString(0,"VWAP_Daily",OBJPROP_TEXT,sDailyStr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Enable_Weekly && (nIdx>=nIdxWeekly))
|
|
||||||
{
|
|
||||||
nSumWeeklyTPV += nTotalTPV[nIdx];
|
|
||||||
nSumWeeklyVol += nTotalVol[nIdx];
|
|
||||||
|
|
||||||
if(nSumWeeklyVol)
|
|
||||||
VWAP_Buffer_Weekly[nIdx]=(nSumWeeklyTPV/nSumWeeklyVol);
|
|
||||||
|
|
||||||
if((sWeeklyStr!="VWAP Weekly: "+(string)NormalizeDouble(VWAP_Buffer_Weekly[nIdx],_Digits)) && Show_Weekly_Value)
|
|
||||||
{
|
|
||||||
sWeeklyStr="VWAP Weekly: "+(string)NormalizeDouble(VWAP_Buffer_Weekly[nIdx],_Digits);
|
|
||||||
ObjectSetString(0,"VWAP_Weekly",OBJPROP_TEXT,sWeeklyStr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Enable_Monthly && (nIdx>=nIdxMonthly))
|
|
||||||
{
|
|
||||||
nSumMonthlyTPV += nTotalTPV[nIdx];
|
|
||||||
nSumMonthlyVol += nTotalVol[nIdx];
|
|
||||||
|
|
||||||
if(nSumMonthlyVol)
|
|
||||||
VWAP_Buffer_Monthly[nIdx]=(nSumMonthlyTPV/nSumMonthlyVol);
|
|
||||||
|
|
||||||
if((sMonthlyStr!="VWAP Monthly: "+(string)NormalizeDouble(VWAP_Buffer_Monthly[nIdx],_Digits)) && Show_Monthly_Value)
|
|
||||||
{
|
|
||||||
sMonthlyStr="VWAP Monthly: "+(string)NormalizeDouble(VWAP_Buffer_Monthly[nIdx],_Digits);
|
|
||||||
ObjectSetString(0,"VWAP_Monthly",OBJPROP_TEXT,sMonthlyStr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dtLastDay=CreateDateTime(DAILY,time[nIdx]);
|
|
||||||
dtLastWeek=CreateDateTime(WEEKLY,time[nIdx]);
|
|
||||||
dtLastMonth=CreateDateTime(MONTHLY,time[nIdx]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Enable_Level_01)
|
|
||||||
{
|
|
||||||
int nStartPos=(prev_calculated>VWAP_Level_01_Period) ?(prev_calculated-VWAP_Level_01_Period) : VWAP_Level_01_Period;
|
|
||||||
for(nIdx=nStartPos; nIdx<rates_total; nIdx++)
|
|
||||||
{
|
|
||||||
double nSumTotalTPV = 0;
|
|
||||||
double nSumTotalVol = 0;
|
|
||||||
VWAP_Buffer_01[nIdx] = EMPTY_VALUE;
|
|
||||||
|
|
||||||
for(int nSubIdx=1; nSubIdx<VWAP_Level_01_Period; nSubIdx++)
|
|
||||||
{
|
|
||||||
nSumTotalTPV += nTotalTPV[nIdx - nSubIdx];
|
|
||||||
nSumTotalVol += nTotalVol[nIdx - nSubIdx];
|
|
||||||
}
|
|
||||||
if(nSumTotalVol)
|
|
||||||
VWAP_Buffer_01[nIdx]=(nSumTotalTPV/nSumTotalVol);
|
|
||||||
else
|
|
||||||
VWAP_Buffer_01[nIdx]=0;
|
|
||||||
if(sLevel01Str!="VWAP Level 01 ("+(string)VWAP_Level_01_Period+"): "+(string)NormalizeDouble(VWAP_Buffer_01[nIdx],_Digits))
|
|
||||||
{
|
|
||||||
sLevel01Str = "VWAP Level 01 (" + (string)VWAP_Level_01_Period + "): " + (string)NormalizeDouble(VWAP_Buffer_01[nIdx], _Digits);
|
|
||||||
ObjectSetString(0,"VWAP_Level_01",OBJPROP_TEXT,sLevel01Str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Enable_Level_02)
|
|
||||||
{
|
|
||||||
int nStartPos=(prev_calculated>VWAP_Level_02_Period) ?(prev_calculated-VWAP_Level_02_Period) : VWAP_Level_02_Period;
|
|
||||||
for(nIdx=nStartPos; nIdx<rates_total; nIdx++)
|
|
||||||
{
|
|
||||||
double nSumTotalTPV = 0;
|
|
||||||
double nSumTotalVol = 0;
|
|
||||||
VWAP_Buffer_02[nIdx] = EMPTY_VALUE;
|
|
||||||
|
|
||||||
for(int nSubIdx=1; nSubIdx<VWAP_Level_02_Period; nSubIdx++)
|
|
||||||
{
|
|
||||||
nSumTotalTPV += nTotalTPV[nIdx - nSubIdx];
|
|
||||||
nSumTotalVol += nTotalVol[nIdx - nSubIdx];
|
|
||||||
}
|
|
||||||
if(nSumTotalVol)
|
|
||||||
VWAP_Buffer_02[nIdx]=(nSumTotalTPV/nSumTotalVol);
|
|
||||||
else
|
|
||||||
VWAP_Buffer_02[nIdx]=0;
|
|
||||||
if(sLevel02Str!="VWAP Level 02 ("+(string)VWAP_Level_02_Period+"): "+(string)NormalizeDouble(VWAP_Buffer_02[nIdx],_Digits))
|
|
||||||
{
|
|
||||||
sLevel02Str = "VWAP Level 02 (" + (string)VWAP_Level_02_Period + "): " + (string)NormalizeDouble(VWAP_Buffer_02[nIdx], _Digits);
|
|
||||||
ObjectSetString(0,"VWAP_Level_02",OBJPROP_TEXT,sLevel02Str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Enable_Level_03)
|
|
||||||
{
|
|
||||||
int nStartPos=(prev_calculated>VWAP_Level_03_Period) ?(prev_calculated-VWAP_Level_03_Period) : VWAP_Level_03_Period;
|
|
||||||
for(nIdx=nStartPos; nIdx<rates_total; nIdx++)
|
|
||||||
{
|
|
||||||
double nSumTotalTPV = 0;
|
|
||||||
double nSumTotalVol = 0;
|
|
||||||
VWAP_Buffer_03[nIdx] = EMPTY_VALUE;
|
|
||||||
|
|
||||||
for(int nSubIdx=1; nSubIdx<VWAP_Level_03_Period; nSubIdx++)
|
|
||||||
{
|
|
||||||
nSumTotalTPV += nTotalTPV[nIdx - nSubIdx];
|
|
||||||
nSumTotalVol += nTotalVol[nIdx - nSubIdx];
|
|
||||||
}
|
|
||||||
if(nSumTotalVol)
|
|
||||||
VWAP_Buffer_03[nIdx]=(nSumTotalTPV/nSumTotalVol);
|
|
||||||
else
|
|
||||||
VWAP_Buffer_03[nIdx]=0;
|
|
||||||
if(sLevel03Str!="VWAP Level 03 ("+(string)VWAP_Level_03_Period+"): "+(string)NormalizeDouble(VWAP_Buffer_03[nIdx],_Digits))
|
|
||||||
{
|
|
||||||
sLevel03Str = "VWAP Level 03 (" + (string)VWAP_Level_03_Period + "): " + (string)NormalizeDouble(VWAP_Buffer_03[nIdx], _Digits);
|
|
||||||
ObjectSetString(0,"VWAP_Level_03",OBJPROP_TEXT,sLevel03Str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Enable_Level_04)
|
|
||||||
{
|
|
||||||
int nStartPos=(prev_calculated>VWAP_Level_04_Period) ?(prev_calculated-VWAP_Level_04_Period) : VWAP_Level_04_Period;
|
|
||||||
for(nIdx=nStartPos; nIdx<rates_total; nIdx++)
|
|
||||||
{
|
|
||||||
double nSumTotalTPV = 0;
|
|
||||||
double nSumTotalVol = 0;
|
|
||||||
VWAP_Buffer_04[nIdx] = EMPTY_VALUE;
|
|
||||||
|
|
||||||
for(int nSubIdx=1; nSubIdx<VWAP_Level_04_Period; nSubIdx++)
|
|
||||||
{
|
|
||||||
nSumTotalTPV += nTotalTPV[nIdx - nSubIdx];
|
|
||||||
nSumTotalVol += nTotalVol[nIdx - nSubIdx];
|
|
||||||
}
|
|
||||||
if(nSumTotalVol)
|
|
||||||
VWAP_Buffer_04[nIdx]=(nSumTotalTPV/nSumTotalVol);
|
|
||||||
else
|
|
||||||
VWAP_Buffer_04[nIdx]=0;
|
|
||||||
if(sLevel04Str!="VWAP Level 04 ("+(string)VWAP_Level_04_Period+"): "+(string)NormalizeDouble(VWAP_Buffer_04[nIdx],_Digits))
|
|
||||||
{
|
|
||||||
sLevel04Str = "VWAP Level 04 (" + (string)VWAP_Level_04_Period + "): " + (string)NormalizeDouble(VWAP_Buffer_04[nIdx], _Digits);
|
|
||||||
ObjectSetString(0,"VWAP_Level_04",OBJPROP_TEXT,sLevel04Str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(Enable_Level_05)
|
|
||||||
{
|
|
||||||
int nStartPos=(prev_calculated>VWAP_Level_05_Period) ?(prev_calculated-VWAP_Level_05_Period) : VWAP_Level_05_Period;
|
|
||||||
for(nIdx=nStartPos; nIdx<rates_total; nIdx++)
|
|
||||||
{
|
|
||||||
double nSumTotalTPV = 0;
|
|
||||||
double nSumTotalVol = 0;
|
|
||||||
VWAP_Buffer_05[nIdx] = EMPTY_VALUE;
|
|
||||||
|
|
||||||
for(int nSubIdx=1; nSubIdx<VWAP_Level_05_Period; nSubIdx++)
|
|
||||||
{
|
|
||||||
nSumTotalTPV += nTotalTPV[nIdx - nSubIdx];
|
|
||||||
nSumTotalVol += nTotalVol[nIdx - nSubIdx];
|
|
||||||
}
|
|
||||||
if(nSumTotalVol)
|
|
||||||
VWAP_Buffer_05[nIdx]=(nSumTotalTPV/nSumTotalVol);
|
|
||||||
else
|
|
||||||
VWAP_Buffer_05[nIdx]=0;
|
|
||||||
if(sLevel05Str!="VWAP Level 05 ("+(string)VWAP_Level_05_Period+"): "+(string)NormalizeDouble(VWAP_Buffer_05[nIdx],_Digits))
|
|
||||||
{
|
|
||||||
sLevel05Str = "VWAP Level 05 (" + (string)VWAP_Level_05_Period + "): " + (string)NormalizeDouble(VWAP_Buffer_05[nIdx], _Digits);
|
|
||||||
ObjectSetString(0,"VWAP_Level_05",OBJPROP_TEXT,sLevel05Str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bIsFirstRun=false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return(rates_total);
|
|
||||||
}
|
|
||||||
//+------------------------------------------------------------------+
|
|
||||||
@@ -1,223 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// -------------------------------------------
|
|
||||||
// Name: XADXTD
|
|
||||||
// Description: ADX TD Channel ...
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XADXTD Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
#define ShortName "XADXTD"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Imports ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Inputs ...
|
|
||||||
input int length = 21; // Length
|
|
||||||
|
|
||||||
//
|
|
||||||
// BUFFERS ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 3
|
|
||||||
#property indicator_plots 0
|
|
||||||
|
|
||||||
//
|
|
||||||
#define strengthBufferIndex 0
|
|
||||||
double strengthBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define bullpBufferIndex 1
|
|
||||||
double bullpBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define bearpBufferIndex 2
|
|
||||||
double bearpBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
int maxLength = 0;
|
|
||||||
int mHandler = INVALID_HANDLE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Event Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// because in some cases we may have more than one input for
|
|
||||||
// calculation and we must prevent any calculation
|
|
||||||
// untill we pass the biggest input length, here we get max Input length
|
|
||||||
// and then wait until pass it ...
|
|
||||||
maxLength = ExtractMaxLengthOfInputs();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
mHandler = iADX(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
length //
|
|
||||||
);
|
|
||||||
if (mHandler == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
return INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
|
|
||||||
//
|
|
||||||
IndicatorRelease(mHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// this counts Available Bars ...
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Calculated Bars ...
|
|
||||||
int adxCalculatedBars = BarsCalculated(mHandler);
|
|
||||||
if (adxCalculatedBars < maxLength)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers Copy ...
|
|
||||||
int copiedADXStrength = CopyBuffer(mHandler, MAIN_LINE, 0, limit, strengthBuffer);
|
|
||||||
int copiedADXBullp = CopyBuffer(mHandler, PLUSDI_LINE, 0, limit, bullpBuffer);
|
|
||||||
int copiedADXBearP = CopyBuffer(mHandler, MINUSDI_LINE, 0, limit, bearpBuffer);
|
|
||||||
if (copiedADXBullp <= 0 ||
|
|
||||||
copiedADXBearP <= 0 ||
|
|
||||||
copiedADXStrength <= 0)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result =
|
|
||||||
//
|
|
||||||
(length > 0)
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve all Exists Input Max Length ...
|
|
||||||
// use for Start Of Drawing ...
|
|
||||||
int ExtractMaxLengthOfInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = MathMax(result, length);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(strengthBuffer, true);
|
|
||||||
SetIndexBuffer(strengthBufferIndex, strengthBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(bullpBuffer, true);
|
|
||||||
SetIndexBuffer(bullpBufferIndex, bullpBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(bearpBuffer, true);
|
|
||||||
SetIndexBuffer(bearpBufferIndex, bearpBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
}
|
|
||||||
@@ -1,329 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 XAMA Indicator
|
|
||||||
// ---------------------------------------------
|
|
||||||
// Name: XAMA
|
|
||||||
// Description: Trend Magic Indicator ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XAMA Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
// Constants ...
|
|
||||||
|
|
||||||
#define ShortName "XAMA"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Indicator States ...
|
|
||||||
enum ENUM_X_XAMA_STATES
|
|
||||||
{
|
|
||||||
X_XAMA_BULLISH = 1,
|
|
||||||
X_XAMA_BEARISH = -1,
|
|
||||||
X_XAMA_NEUTURAL = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// Inputs ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Market ...
|
|
||||||
input group "Market";
|
|
||||||
input int length = 18; // Period
|
|
||||||
input int fastEMA = 2; // Fast EMA Period
|
|
||||||
input int slowEMA = 30; // Slow EMA Period
|
|
||||||
input int maShift = 0; // Shift
|
|
||||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
// Presentation ...
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showLine = true; // Show Line
|
|
||||||
|
|
||||||
//
|
|
||||||
// Includes Common Library ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Buffers ...
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 3
|
|
||||||
#property indicator_plots 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// maBuffer ...
|
|
||||||
#define maBufferIndex 0
|
|
||||||
#define maColorBufferIndex 1
|
|
||||||
#define stateBufferIndex 2
|
|
||||||
|
|
||||||
double maBuffer[];
|
|
||||||
double maColorBuffer[];
|
|
||||||
double stateBuffer[];
|
|
||||||
|
|
||||||
#property indicator_label1 "XAMA"
|
|
||||||
#property indicator_type1 DRAW_COLOR_LINE
|
|
||||||
#property indicator_color1 clrLime, clrGray, clrRed, CLR_NONE
|
|
||||||
#property indicator_style1 STYLE_SOLID
|
|
||||||
#property indicator_width1 1
|
|
||||||
//
|
|
||||||
// END Buffers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
int maHandler = INVALID_HANDLE;
|
|
||||||
//
|
|
||||||
// END Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Event Handlers ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initializing MA Handler ...
|
|
||||||
maHandler = iAMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
length,
|
|
||||||
fastEMA,
|
|
||||||
slowEMA,
|
|
||||||
maShift,
|
|
||||||
appliedTo);
|
|
||||||
if (maHandler == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
|
|
||||||
//
|
|
||||||
// Here we can handle De Initialization Reasons ...
|
|
||||||
IndicatorRelease(maHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculations ...
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Prepare Buffers ...
|
|
||||||
ArraySetAsSeries(time, true);
|
|
||||||
ArraySetAsSeries(open, true);
|
|
||||||
ArraySetAsSeries(high, true);
|
|
||||||
ArraySetAsSeries(low, true);
|
|
||||||
ArraySetAsSeries(close, true);
|
|
||||||
ArraySetAsSeries(tick_volume, true);
|
|
||||||
ArraySetAsSeries(volume, true);
|
|
||||||
ArraySetAsSeries(spread, true);
|
|
||||||
|
|
||||||
//
|
|
||||||
// this counts Available Bars ...
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
//
|
|
||||||
// because in some cases we may have more than one input for
|
|
||||||
// calculation and we must prevent any calculation
|
|
||||||
// untill we pass the biggest input length, here we get max Input length
|
|
||||||
// and then wait until pass it ...
|
|
||||||
int maxLength = MathMax(fastEMA, slowEMA);
|
|
||||||
maxLength = MathMax(maxLength, length);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Calculated Bars ...
|
|
||||||
int maCalculatedBars = BarsCalculated(maHandler);
|
|
||||||
if (maCalculatedBars < maxLength)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers Copy ...
|
|
||||||
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
|
|
||||||
if (copiedMas <= 0)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main Loop ...
|
|
||||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Do Buffers Calculation ...
|
|
||||||
CalculateBuffers(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// END Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Functions ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Args ...
|
|
||||||
if (length >= 2)
|
|
||||||
{
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string maBufferLabel = "XAMA " + "(" + (string)length + ")";
|
|
||||||
|
|
||||||
//
|
|
||||||
// Ma Buffer ...
|
|
||||||
ArraySetAsSeries(maBuffer, true);
|
|
||||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetString(maBufferIndex, PLOT_LABEL, maBufferLabel);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Ma Color Buffer ...
|
|
||||||
ArraySetAsSeries(maColorBuffer, true);
|
|
||||||
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
|
|
||||||
|
|
||||||
//
|
|
||||||
// State Buffer ...
|
|
||||||
ArraySetAsSeries(stateBuffer, true);
|
|
||||||
SetIndexBuffer(stateBufferIndex, stateBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string indicatorShortName = "";
|
|
||||||
StringConcatenate(indicatorShortName, ShortName, " ", "(", length, ")");
|
|
||||||
|
|
||||||
//
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Buffers ...
|
|
||||||
void CalculateBuffers(int bar_index)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Requirements ...
|
|
||||||
XOHCL candle;
|
|
||||||
candle.Init(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
bar_index);
|
|
||||||
|
|
||||||
//
|
|
||||||
double maValue = maBuffer[bar_index];
|
|
||||||
|
|
||||||
//
|
|
||||||
double lineColorIndex =
|
|
||||||
maValue < candle.low ? 0 : maValue > candle.high ? 2
|
|
||||||
: 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define State Value ...
|
|
||||||
// lineColorIndex == 0 => Bullish => 1;
|
|
||||||
// lineColorIndex == 1 => Neutural => 0;
|
|
||||||
// lineColorIndex == 2 => Bearish => -1;
|
|
||||||
double stateValue =
|
|
||||||
lineColorIndex == 0 ? X_XAMA_BULLISH : lineColorIndex == 2 ? X_XAMA_BEARISH
|
|
||||||
: X_XAMA_NEUTURAL;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Ma Buffer Color Index ...
|
|
||||||
maColorBuffer[bar_index] = showLine ? lineColorIndex : 3;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set State Buffer Value ...
|
|
||||||
stateBuffer[bar_index] = stateValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Functions ...
|
|
||||||
//
|
|
||||||
@@ -1,442 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// -------------------------------------------
|
|
||||||
// Name: XASCT
|
|
||||||
// Description: XASCTrend Detector ...
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XASCT Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
#define ShortName "XASCT"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Inputs ...
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Market";
|
|
||||||
input int risk = 4; // Risk
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showLongs = true; // Show Long Arrows
|
|
||||||
input bool showShorts = true; // Show Short Arrows
|
|
||||||
input uchar longArrowCode = 233; // Long Arrow
|
|
||||||
input uchar shortArrowCode = 234; // Short Arrow
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 2
|
|
||||||
#property indicator_plots 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#define longBufferIndex 0
|
|
||||||
double longBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XASCT Long"
|
|
||||||
#property indicator_type1 DRAW_ARROW
|
|
||||||
#property indicator_color1 clrAqua
|
|
||||||
#property indicator_width1 3
|
|
||||||
|
|
||||||
//
|
|
||||||
#define shortBufferIndex 1
|
|
||||||
double shortBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label2 "XASCT Short"
|
|
||||||
#property indicator_type2 DRAW_ARROW
|
|
||||||
#property indicator_color2 clrMagenta
|
|
||||||
#property indicator_width2 3
|
|
||||||
|
|
||||||
//
|
|
||||||
// Variables ...
|
|
||||||
int maxLength = 0;
|
|
||||||
int wPRHandlers[3];
|
|
||||||
int x1, x2 = 0;
|
|
||||||
int value10, value11 = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
// EVENT Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
maxLength = ExtractMaxLengthOfInputs();
|
|
||||||
|
|
||||||
//
|
|
||||||
x1 = 67 + risk;
|
|
||||||
x2 = 33 - risk;
|
|
||||||
value10 = 2;
|
|
||||||
value11 = value10;
|
|
||||||
|
|
||||||
//
|
|
||||||
wPRHandlers[0] = iWPR(_Symbol, _Period, 3);
|
|
||||||
if (wPRHandlers[0] == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
return INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
wPRHandlers[1] = iWPR(_Symbol, _Period, 4);
|
|
||||||
if (wPRHandlers[1] == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
return INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
wPRHandlers[2] = iWPR(_Symbol, _Period, 3 + risk * 2);
|
|
||||||
if (wPRHandlers[2] == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
return INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Calculated Bars ...
|
|
||||||
bool isPassedRequiredCalculatedBars =
|
|
||||||
//
|
|
||||||
BarsCalculated(wPRHandlers[0]) == rates_total &&
|
|
||||||
BarsCalculated(wPRHandlers[1]) == rates_total &&
|
|
||||||
BarsCalculated(wPRHandlers[2]) == rates_total
|
|
||||||
//
|
|
||||||
;
|
|
||||||
if (!isPassedRequiredCalculatedBars)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Declare Some Local Variables for Use ...
|
|
||||||
int limit, bar, count, iii;
|
|
||||||
double value2, value3, vel = 0, wprs[];
|
|
||||||
double trueCount, range, avgRange, mrO1, mrO2;
|
|
||||||
|
|
||||||
//
|
|
||||||
// checking for the first start of the indicator calculation ...
|
|
||||||
if (prev_calculated > rates_total || prev_calculated <= 0)
|
|
||||||
{
|
|
||||||
limit = rates_total - maxLength;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// starting index for calculation of all bars
|
|
||||||
else
|
|
||||||
{
|
|
||||||
limit = rates_total - prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(wprs, true);
|
|
||||||
ArraySetAsSeries(open, true);
|
|
||||||
ArraySetAsSeries(high, true);
|
|
||||||
ArraySetAsSeries(low, true);
|
|
||||||
ArraySetAsSeries(close, true);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main Loop ...
|
|
||||||
for (bar = limit; bar >= 0 && !IsStopped(); bar--)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
range = 0.0;
|
|
||||||
avgRange = 0.0;
|
|
||||||
for (count = bar; count <= bar + 9; count++)
|
|
||||||
{
|
|
||||||
avgRange = avgRange + MathAbs(high[count] - low[count]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
count = bar;
|
|
||||||
trueCount = 0;
|
|
||||||
range = avgRange / 10;
|
|
||||||
|
|
||||||
//
|
|
||||||
while (count < bar + 9 && trueCount < 1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (MathAbs(open[count] - close[count + 1]) >= range * 2.0)
|
|
||||||
{
|
|
||||||
trueCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (trueCount >= 1)
|
|
||||||
{
|
|
||||||
mrO1 = count;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mrO1 = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
count = bar;
|
|
||||||
trueCount = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
while (count < bar + 6 && trueCount < 1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (MathAbs(close[count + 3] - close[count]) >= range * 4.6)
|
|
||||||
{
|
|
||||||
trueCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (trueCount >= 1)
|
|
||||||
{
|
|
||||||
mrO2 = count;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mrO2 = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (mrO1 > -1)
|
|
||||||
{
|
|
||||||
value11 = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
value11 = value10;
|
|
||||||
}
|
|
||||||
if (mrO2 > -1)
|
|
||||||
{
|
|
||||||
value11 = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
value11 = value10;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (CopyBuffer(wPRHandlers[value11], 0, bar, 1, wprs) <= 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
value2 = 100 - MathAbs(wprs[0]);
|
|
||||||
|
|
||||||
//
|
|
||||||
longBuffer[bar] = 0;
|
|
||||||
shortBuffer[bar] = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
value3 = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (value2 < x2)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
iii = 1;
|
|
||||||
while (bar + iii < rates_total)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (CopyBuffer(wPRHandlers[value11], 0, bar + iii, 1, wprs) <= 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
vel = 100 - MathAbs(wprs[0]);
|
|
||||||
if (vel >= x2 && vel <= x1)
|
|
||||||
{
|
|
||||||
iii++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (vel > x1)
|
|
||||||
{
|
|
||||||
value3 = high[bar] + range * 0.5;
|
|
||||||
shortBuffer[bar] = value3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (value2 > x1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
iii = 1;
|
|
||||||
while (bar + iii < rates_total)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (CopyBuffer(wPRHandlers[value11], 0, bar + iii, 1, wprs) <= 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
vel = 100 - MathAbs(wprs[0]);
|
|
||||||
if (vel >= x2 && vel <= x1)
|
|
||||||
{
|
|
||||||
iii++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (vel < x2)
|
|
||||||
{
|
|
||||||
value3 = low[bar] - range * 0.5;
|
|
||||||
longBuffer[bar] = value3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// CUSTOM Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = true;
|
|
||||||
|
|
||||||
//
|
|
||||||
result =
|
|
||||||
risk >= 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve all Exists Input Max Length ...
|
|
||||||
// use for Start Of Drawing ...
|
|
||||||
int ExtractMaxLengthOfInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = int(MathMax(3 + risk * 2, 4) + 1);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Longs Buffer ...
|
|
||||||
ENUM_DRAW_TYPE longsDrawType = showLongs ? DRAW_ARROW : DRAW_NONE;
|
|
||||||
ArraySetAsSeries(longBuffer, true);
|
|
||||||
SetIndexBuffer(longBufferIndex, longBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetDouble(longBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
||||||
PlotIndexSetInteger(longBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(longBufferIndex, PLOT_SHOW_DATA, showLongs);
|
|
||||||
PlotIndexSetInteger(longBufferIndex, PLOT_DRAW_TYPE, longsDrawType);
|
|
||||||
PlotIndexSetInteger(longBufferIndex, PLOT_ARROW, longArrowCode);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Short Buffer ...
|
|
||||||
ENUM_DRAW_TYPE shortsDrawType = showShorts ? DRAW_ARROW : DRAW_NONE;
|
|
||||||
ArraySetAsSeries(shortBuffer, true);
|
|
||||||
SetIndexBuffer(shortBufferIndex, shortBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetDouble(shortBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
||||||
PlotIndexSetInteger(shortBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(shortBufferIndex, PLOT_SHOW_DATA, showShorts);
|
|
||||||
PlotIndexSetInteger(shortBufferIndex, PLOT_DRAW_TYPE, shortsDrawType);
|
|
||||||
PlotIndexSetInteger(shortBufferIndex, PLOT_ARROW, shortArrowCode);
|
|
||||||
}
|
|
||||||
@@ -1,333 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// -------------------------------------------
|
|
||||||
// Name: XATSL
|
|
||||||
// Description: ATR SL ...
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XATSL Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
#define ShortName "XATSL"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Imports ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Inputs ...
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Market";
|
|
||||||
input int length = 14; // Length
|
|
||||||
input double coeff = 2.0; // Coefficient
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool show = true; // Show
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 7
|
|
||||||
#property indicator_plots 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#define mainBufferIndex 0
|
|
||||||
double mainBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define mainBufferColorIndex 1
|
|
||||||
double mainBufferColor[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define hideColorIDX 0
|
|
||||||
#define bullColorIDX 1
|
|
||||||
#define bearColorIDX 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XATSL"
|
|
||||||
#property indicator_type1 DRAW_COLOR_LINE
|
|
||||||
#property indicator_color1 CLR_NONE, clrGreen, clrDarkRed
|
|
||||||
#property indicator_style1 STYLE_DOT
|
|
||||||
#property indicator_width1 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define hlBufferIndex 2
|
|
||||||
double hlBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define wmaBufferIndex 3
|
|
||||||
double wmaBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define tmpBufferIndex 4
|
|
||||||
double tmpBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define diffBufferIndex 5
|
|
||||||
double diffBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// Variables ...
|
|
||||||
int maPeriod;
|
|
||||||
double mk;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Event Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
maPeriod = int(length < 1 ? 1 : length);
|
|
||||||
double n1 = 2.0 * double(maPeriod - 1);
|
|
||||||
mk = 2.0 / (n1 + 1);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(high, true);
|
|
||||||
ArraySetAsSeries(low, true);
|
|
||||||
ArraySetAsSeries(close, true);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (rates_total < maPeriod)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int limit = rates_total - prev_calculated;
|
|
||||||
if (limit > 1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
limit = rates_total - 2;
|
|
||||||
|
|
||||||
//
|
|
||||||
ArrayInitialize(mainBuffer, EMPTY_VALUE);
|
|
||||||
ArrayInitialize(hlBuffer, 0);
|
|
||||||
ArrayInitialize(diffBuffer, 0);
|
|
||||||
ArrayInitialize(wmaBuffer, 0);
|
|
||||||
ArrayInitialize(tmpBuffer, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
hlBuffer[i] = high[i] - low[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
double href = 0;
|
|
||||||
double lref = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
double sma = MAOnArray(hlBuffer, 0, maPeriod, 0, MODE_SMA, i);
|
|
||||||
double hiLo = fmin(hlBuffer[i], sma);
|
|
||||||
|
|
||||||
//
|
|
||||||
href = (low[i] <= high[i + 1] ? high[i] - close[i + 1] : (hlBuffer[i] - close[i + 1] + high[i + 1]) / 2);
|
|
||||||
lref = (high[i] >= low[i + 1] ? close[i + 1] - low[i] : (close[i + 1] - low[i + 1] + hlBuffer[i]) / 2);
|
|
||||||
|
|
||||||
//
|
|
||||||
diffBuffer[i] = fmax(hiLo, fmax(href, lref));
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (i == rates_total - 2)
|
|
||||||
{
|
|
||||||
wmaBuffer[i] = MAOnArray(diffBuffer, 0, maPeriod, 0, MODE_EMA, i);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wmaBuffer[i] = (diffBuffer[i] - wmaBuffer[i + 1]) * mk + wmaBuffer[i + 1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double loss = wmaBuffer[i] * coeff;
|
|
||||||
if (close[i] > tmpBuffer[i + 1] && close[i + 1] > tmpBuffer[i + 1])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
tmpBuffer[i] = fmax(tmpBuffer[i + 1], close[i] - loss);
|
|
||||||
|
|
||||||
//
|
|
||||||
mainBuffer[i] = tmpBuffer[i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (close[i] < tmpBuffer[i + 1] && close[i + 1] < tmpBuffer[i + 1])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
tmpBuffer[i] = fmin(tmpBuffer[i + 1], close[i] + loss);
|
|
||||||
|
|
||||||
//
|
|
||||||
mainBuffer[i] = tmpBuffer[i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (close[i] > tmpBuffer[i + 1])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
tmpBuffer[i] = close[i] - loss;
|
|
||||||
|
|
||||||
//
|
|
||||||
mainBuffer[i] = tmpBuffer[i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
tmpBuffer[i] = close[i] + loss;
|
|
||||||
|
|
||||||
//
|
|
||||||
mainBuffer[i] = tmpBuffer[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Color Buffer ...
|
|
||||||
double clrValue = !show
|
|
||||||
? hideColorIDX
|
|
||||||
: mainBuffer[i] > close[i]
|
|
||||||
? bearColorIDX
|
|
||||||
: bullColorIDX;
|
|
||||||
mainBufferColor[i] = clrValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Custom Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = length >= 2 &&
|
|
||||||
coeff > 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Main ...
|
|
||||||
ENUM_DRAW_TYPE mainDrawType = show ? DRAW_COLOR_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
ArraySetAsSeries(mainBuffer, true);
|
|
||||||
ArraySetAsSeries(mainBufferColor, true);
|
|
||||||
PlotIndexSetInteger(mainBufferIndex, PLOT_SHOW_DATA, true);
|
|
||||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(mainBufferIndex, PLOT_DRAW_TYPE, mainDrawType);
|
|
||||||
SetIndexBuffer(mainBufferColorIndex, mainBufferColor, INDICATOR_COLOR_INDEX);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(hlBuffer, true);
|
|
||||||
SetIndexBuffer(hlBufferIndex, hlBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(wmaBuffer, true);
|
|
||||||
SetIndexBuffer(wmaBufferIndex, wmaBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(tmpBuffer, true);
|
|
||||||
SetIndexBuffer(tmpBufferIndex, tmpBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(diffBuffer, true);
|
|
||||||
SetIndexBuffer(diffBufferIndex, diffBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
@@ -1,612 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// ---------------------------------------------
|
|
||||||
// Name: XCHE
|
|
||||||
// Description: Chandelier Exit Indicator ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XCHE Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
#define ShortName "XCHE"
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Market";
|
|
||||||
input int length = 35; // Length
|
|
||||||
input int loopback = 26; // Loopback
|
|
||||||
input double multiplier1 = 3.0; // 1st Multiplier
|
|
||||||
input double multiplier2 = 3.5; // 2nd Multiplier
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Calculation";
|
|
||||||
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Zone Applied to
|
|
||||||
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Zone Applied to
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showLongExit1Line = true; // Show 1st Long Exit
|
|
||||||
input bool showShortExit1Line = true; // Show 1st Short Exit
|
|
||||||
input bool showLongExit2Line = true; // Show 2st Long Exit
|
|
||||||
input bool showShortExit2Line = true; // Show 2st Short Exit
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Includes and Imports ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Includes Common Library ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Includes and Imports ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Buffers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 8
|
|
||||||
#property indicator_plots 8
|
|
||||||
|
|
||||||
//
|
|
||||||
// Long Exit 1 ...
|
|
||||||
#define longExit1BufferIndex 0
|
|
||||||
double longExit1Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XCHE LE 1"
|
|
||||||
#property indicator_type1 DRAW_LINE
|
|
||||||
#property indicator_color1 clrLime
|
|
||||||
#property indicator_style1 STYLE_DOT
|
|
||||||
|
|
||||||
//
|
|
||||||
// Short Exit 1 ...
|
|
||||||
#define shortExit1BufferIndex 1
|
|
||||||
double shortExit1Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label2 "XCHE SE 1"
|
|
||||||
#property indicator_type2 DRAW_LINE
|
|
||||||
#property indicator_style2 STYLE_DOT
|
|
||||||
#property indicator_color2 clrRed
|
|
||||||
|
|
||||||
//
|
|
||||||
// Long Exit 2 ...
|
|
||||||
#define longExit2BufferIndex 2
|
|
||||||
double longExit2Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label3 "XCHE LE 2"
|
|
||||||
#property indicator_type3 DRAW_LINE
|
|
||||||
#property indicator_style3 STYLE_DOT
|
|
||||||
#property indicator_color3 clrAqua
|
|
||||||
|
|
||||||
//
|
|
||||||
// Short Exit 2 ...
|
|
||||||
#define shortExit2BufferIndex 3
|
|
||||||
double shortExit2Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label4 "XCHE SE 2"
|
|
||||||
#property indicator_type4 DRAW_LINE
|
|
||||||
#property indicator_style4 STYLE_DOT
|
|
||||||
#property indicator_color4 clrMagenta
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Arrows ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Long Exit 1 Start ...
|
|
||||||
#define longExit1StartBufferIndex 4
|
|
||||||
double longExit1StartBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label5 "XCHE LES 1"
|
|
||||||
#property indicator_type5 DRAW_ARROW
|
|
||||||
#property indicator_color5 clrLime
|
|
||||||
|
|
||||||
//
|
|
||||||
// Short Exit 1 Start ...
|
|
||||||
#define shortExit1StartBufferIndex 5
|
|
||||||
double shortExit1StartBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label6 "XCHE SES 1"
|
|
||||||
#property indicator_type6 DRAW_ARROW
|
|
||||||
#property indicator_color6 clrRed
|
|
||||||
|
|
||||||
//
|
|
||||||
// Long Exit 2 Start ...
|
|
||||||
#define longExit2StartBufferIndex 6
|
|
||||||
double longExit2StartBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label7 "XCHE LES 2"
|
|
||||||
#property indicator_type7 DRAW_ARROW
|
|
||||||
#property indicator_color7 clrAqua
|
|
||||||
|
|
||||||
//
|
|
||||||
// Short Exit 2 Start ...
|
|
||||||
#define shortExit2StartBufferIndex 7
|
|
||||||
double shortExit2StartBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label8 "XCHE SES 2"
|
|
||||||
#property indicator_type8 DRAW_ARROW
|
|
||||||
#property indicator_color8 clrMagenta
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Buffers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
int maxLength;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Working Array ...
|
|
||||||
double work[][6];
|
|
||||||
#define hi1Idx 0
|
|
||||||
#define lo1Idx 1
|
|
||||||
#define hi2Idx 2
|
|
||||||
#define lo2Idx 3
|
|
||||||
#define trend1Idx 4
|
|
||||||
#define trend2Idx 5
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// because in some cases we may have more than one input for
|
|
||||||
// calculation and we must prevent any calculation
|
|
||||||
// untill we pass the biggest input length, here we get max Input length
|
|
||||||
// and then wait until pass it ...
|
|
||||||
maxLength = ExtractMaxLengthOfInputs();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart mPeriod is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (Bars(_Symbol, _Period) < rates_total)
|
|
||||||
{
|
|
||||||
return (prev_calculated);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (ArrayRange(work, 0) != rates_total)
|
|
||||||
{
|
|
||||||
ArrayResize(work, rates_total);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// this counts Available Bars ...
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
//
|
|
||||||
limit = prev_calculated - 1;
|
|
||||||
if (limit < 0)
|
|
||||||
{
|
|
||||||
limit = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main Loop ...
|
|
||||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
|
||||||
{
|
|
||||||
CalculateBuffers(
|
|
||||||
i,
|
|
||||||
prev_calculated,
|
|
||||||
rates_total,
|
|
||||||
//
|
|
||||||
open,
|
|
||||||
high,
|
|
||||||
low,
|
|
||||||
close);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// END Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Functions ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = true;
|
|
||||||
|
|
||||||
//
|
|
||||||
result =
|
|
||||||
length >= 9 &&
|
|
||||||
loopback >= 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve all Exists Input Max Length ...
|
|
||||||
// use for Start Of Drawing ...
|
|
||||||
int ExtractMaxLengthOfInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = MathMax(length, loopback);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
uint arrowCode = 159;
|
|
||||||
|
|
||||||
//
|
|
||||||
// LEVEL 1 ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Long Exit 1 ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Draw Type ...
|
|
||||||
ENUM_DRAW_TYPE longExit1DrawType = showLongExit1Line ? DRAW_LINE : DRAW_NONE;
|
|
||||||
ENUM_DRAW_TYPE longExit1StartDrawType = showLongExit1Line ? DRAW_ARROW : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffer ...
|
|
||||||
SetIndexBuffer(longExit1BufferIndex, longExit1Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(longExit1BufferIndex, PLOT_SHOW_DATA, showLongExit1Line);
|
|
||||||
PlotIndexSetInteger(longExit1BufferIndex, PLOT_DRAW_TYPE, longExit1DrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Start Buffer ...
|
|
||||||
SetIndexBuffer(longExit1StartBufferIndex, longExit1StartBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_ARROW, arrowCode);
|
|
||||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
PlotIndexSetInteger(longExit1StartBufferIndex, PLOT_DRAW_TYPE, longExit1StartDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Short Exit 1 ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Draw Type ...
|
|
||||||
ENUM_DRAW_TYPE shortExit1DrawType = showShortExit1Line ? DRAW_LINE : DRAW_NONE;
|
|
||||||
ENUM_DRAW_TYPE shortExit1StartDrawType = showShortExit1Line ? DRAW_ARROW : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffer ...
|
|
||||||
SetIndexBuffer(shortExit1BufferIndex, shortExit1Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(shortExit1BufferIndex, PLOT_SHOW_DATA, showShortExit1Line);
|
|
||||||
PlotIndexSetInteger(shortExit1BufferIndex, PLOT_DRAW_TYPE, shortExit1DrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Start Buffer ...
|
|
||||||
SetIndexBuffer(shortExit1StartBufferIndex, shortExit1StartBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_ARROW, arrowCode);
|
|
||||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
PlotIndexSetInteger(shortExit1StartBufferIndex, PLOT_DRAW_TYPE, shortExit1StartDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// LEVEL 2 ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Long Exit 2 ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Draw Type ...
|
|
||||||
ENUM_DRAW_TYPE longExit2DrawType = showLongExit2Line ? DRAW_LINE : DRAW_NONE;
|
|
||||||
ENUM_DRAW_TYPE longExit2StartDrawType = showLongExit2Line ? DRAW_ARROW : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffer ...
|
|
||||||
SetIndexBuffer(longExit2BufferIndex, longExit2Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(longExit2BufferIndex, PLOT_SHOW_DATA, showLongExit2Line);
|
|
||||||
PlotIndexSetInteger(longExit2BufferIndex, PLOT_DRAW_TYPE, longExit2DrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Start Buffer ...
|
|
||||||
SetIndexBuffer(longExit2StartBufferIndex, longExit2StartBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_ARROW, arrowCode);
|
|
||||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
PlotIndexSetInteger(longExit2StartBufferIndex, PLOT_DRAW_TYPE, longExit2StartDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Short Exit 2 ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Draw Type ...
|
|
||||||
ENUM_DRAW_TYPE shortExit2DrawType = showShortExit2Line ? DRAW_LINE : DRAW_NONE;
|
|
||||||
ENUM_DRAW_TYPE shortExit2StartDrawType = showShortExit2Line ? DRAW_ARROW : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffer ...
|
|
||||||
SetIndexBuffer(shortExit2BufferIndex, shortExit2Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(shortExit2BufferIndex, PLOT_SHOW_DATA, showShortExit2Line);
|
|
||||||
PlotIndexSetInteger(shortExit2BufferIndex, PLOT_DRAW_TYPE, shortExit2DrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Start Buffer ...
|
|
||||||
SetIndexBuffer(shortExit2StartBufferIndex, shortExit2StartBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_ARROW, arrowCode);
|
|
||||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
PlotIndexSetInteger(shortExit2StartBufferIndex, PLOT_DRAW_TYPE, shortExit2StartDrawType);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Buffers ...
|
|
||||||
void CalculateBuffers(
|
|
||||||
int bar_index, // Selected Bar Index
|
|
||||||
int prevCalculated, // Previous Calculated
|
|
||||||
int ratesTotal, // Total Rates
|
|
||||||
const double &open[], // Rates Open ...
|
|
||||||
const double &high[], // Rates High ...
|
|
||||||
const double &low[], // Rates Low ...
|
|
||||||
const double &close[] // Rates Close ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Cleanup Buffers ...
|
|
||||||
longExit1Buffer[bar_index] = longExit1StartBuffer[bar_index] = shortExit1Buffer[bar_index] = shortExit1StartBuffer[bar_index] = EMPTY_VALUE;
|
|
||||||
longExit2Buffer[bar_index] = longExit2StartBuffer[bar_index] = shortExit2Buffer[bar_index] = shortExit2StartBuffer[bar_index] = EMPTY_VALUE;
|
|
||||||
|
|
||||||
//
|
|
||||||
int start = MathMax(bar_index - loopback, 0);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate ATR Value ...
|
|
||||||
double atrValue = 0;
|
|
||||||
for (int k = 1; k <= length && (bar_index - k - 1) >= 0; k++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
atrValue += MathMax(high[bar_index - k], close[MathMax(bar_index - k - 1, 0)]) -
|
|
||||||
MathMin(low[bar_index - k], close[MathMax(bar_index - k - 1, 0)]);
|
|
||||||
}
|
|
||||||
atrValue /= (double)length;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Highest High and Lowest Lows ...
|
|
||||||
double loopbackMax = high[ArrayMaximum(high, start, loopback)];
|
|
||||||
double loopbackMin = low[ArrayMinimum(low, start, loopback)];
|
|
||||||
|
|
||||||
//
|
|
||||||
// Fill Multi Dimesional Working Array ...
|
|
||||||
work[bar_index][hi1Idx] = loopbackMax - multiplier1 * atrValue;
|
|
||||||
work[bar_index][lo1Idx] = loopbackMin + multiplier1 * atrValue;
|
|
||||||
work[bar_index][hi2Idx] = loopbackMax - multiplier2 * atrValue;
|
|
||||||
work[bar_index][lo2Idx] = loopbackMin + multiplier2 * atrValue;
|
|
||||||
work[bar_index][trend1Idx] = (bar_index > 0) ? work[bar_index - 1][trend1Idx] : 0;
|
|
||||||
work[bar_index][trend2Idx] = (bar_index > 0) ? work[bar_index - 1][trend2Idx] : 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (bar_index > 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Calculate Trends ...
|
|
||||||
if (close[bar_index] > work[bar_index - 1][lo1Idx])
|
|
||||||
{
|
|
||||||
work[bar_index][trend1Idx] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (close[bar_index] < work[bar_index - 1][hi1Idx])
|
|
||||||
{
|
|
||||||
work[bar_index][trend1Idx] = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (close[bar_index] > work[bar_index - 1][lo2Idx])
|
|
||||||
{
|
|
||||||
work[bar_index][trend2Idx] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (close[bar_index] < work[bar_index - 1][hi2Idx])
|
|
||||||
{
|
|
||||||
work[bar_index][trend2Idx] = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Exit Values ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Exit 1 ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Long ...
|
|
||||||
if (multiplier1 > 0 && work[bar_index][trend1Idx] == 1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (work[bar_index][hi1Idx] < work[bar_index - 1][hi1Idx])
|
|
||||||
{
|
|
||||||
work[bar_index][hi1Idx] = work[bar_index - 1][hi1Idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
longExit1Buffer[bar_index] = work[bar_index][hi1Idx];
|
|
||||||
|
|
||||||
//
|
|
||||||
if (longExit1Buffer[bar_index - 1] == EMPTY_VALUE)
|
|
||||||
{
|
|
||||||
longExit1StartBuffer[bar_index] = longExit1Buffer[bar_index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Short ...
|
|
||||||
if (multiplier1 > 0 && work[bar_index][trend1Idx] == -1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (work[bar_index][lo1Idx] > work[bar_index - 1][lo1Idx])
|
|
||||||
{
|
|
||||||
work[bar_index][lo1Idx] = work[bar_index - 1][lo1Idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
shortExit1Buffer[bar_index] = work[bar_index][lo1Idx];
|
|
||||||
|
|
||||||
//
|
|
||||||
if (shortExit1Buffer[bar_index - 1] == EMPTY_VALUE)
|
|
||||||
{
|
|
||||||
shortExit1StartBuffer[bar_index] = shortExit1Buffer[bar_index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Exit 2 ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Long ...
|
|
||||||
if (multiplier2 > 0 && work[bar_index][trend2Idx] == 1)
|
|
||||||
{
|
|
||||||
if (work[bar_index][hi2Idx] < work[bar_index - 1][hi2Idx])
|
|
||||||
{
|
|
||||||
work[bar_index][hi2Idx] = work[bar_index - 1][hi2Idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
longExit2Buffer[bar_index] = work[bar_index][hi2Idx];
|
|
||||||
|
|
||||||
//
|
|
||||||
if (longExit2Buffer[bar_index - 1] == EMPTY_VALUE)
|
|
||||||
{
|
|
||||||
longExit2StartBuffer[bar_index] = longExit2Buffer[bar_index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Short ...
|
|
||||||
if (multiplier2 > 0 && work[bar_index][trend2Idx] == -1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (work[bar_index][lo2Idx] > work[bar_index - 1][lo2Idx])
|
|
||||||
{
|
|
||||||
work[bar_index][lo2Idx] = work[bar_index - 1][lo2Idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
shortExit2Buffer[bar_index] = work[bar_index][lo2Idx];
|
|
||||||
|
|
||||||
//
|
|
||||||
if (shortExit2Buffer[bar_index - 1] == EMPTY_VALUE)
|
|
||||||
{
|
|
||||||
shortExit2StartBuffer[bar_index] = shortExit2Buffer[bar_index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Functions ...
|
|
||||||
//
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,222 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// -------------------------------------------
|
|
||||||
// Name: XDMNT
|
|
||||||
// Description: Dominant ...
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XDMNT Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
#define ShortName "XDMNT"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Imports ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Inputs ...
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showBull = true; // Show Bull
|
|
||||||
input bool showBear = true; // Show Bear
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 2
|
|
||||||
#property indicator_plots 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#define bullBufferIndex 0
|
|
||||||
double bullBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XDMNT Bull"
|
|
||||||
#property indicator_type1 DRAW_ARROW
|
|
||||||
#property indicator_color1 clrAqua
|
|
||||||
#property indicator_width1 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#define bearBufferIndex 1
|
|
||||||
double bearBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label2 "XDMNT Bear"
|
|
||||||
#property indicator_type2 DRAW_ARROW
|
|
||||||
#property indicator_color2 clrMagenta
|
|
||||||
#property indicator_width2 2
|
|
||||||
|
|
||||||
//
|
|
||||||
// Event Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(open, true);
|
|
||||||
ArraySetAsSeries(high, true);
|
|
||||||
ArraySetAsSeries(low, true);
|
|
||||||
ArraySetAsSeries(close, true);
|
|
||||||
ArraySetAsSeries(time, true);
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = 1; i < rates_total - 2; 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])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bullBuffer[i] = low[i + 1];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bullBuffer[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Bearish ...
|
|
||||||
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])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bearBuffer[i] = high[i + 1];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bearBuffer[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Custom Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = true;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Bull ...
|
|
||||||
ENUM_DRAW_TYPE bullDrawType = showBull ? DRAW_ARROW : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(bullBuffer, true);
|
|
||||||
PlotIndexSetInteger(bullBufferIndex, PLOT_ARROW, 225);
|
|
||||||
PlotIndexSetDouble(bullBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
||||||
SetIndexBuffer(bullBufferIndex, bullBuffer, INDICATOR_DATA);
|
|
||||||
|
|
||||||
//
|
|
||||||
PlotIndexSetInteger(bullBufferIndex, PLOT_SHOW_DATA, showBull);
|
|
||||||
PlotIndexSetInteger(bullBufferIndex, PLOT_DRAW_TYPE, bullDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Bear ...
|
|
||||||
ENUM_DRAW_TYPE bearDrawType = showBear ? DRAW_ARROW : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(bearBuffer, true);
|
|
||||||
PlotIndexSetInteger(bearBufferIndex, PLOT_ARROW, 225);
|
|
||||||
PlotIndexSetDouble(bearBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
||||||
SetIndexBuffer(bearBufferIndex, bearBuffer, INDICATOR_DATA);
|
|
||||||
|
|
||||||
//
|
|
||||||
PlotIndexSetInteger(bearBufferIndex, PLOT_SHOW_DATA, showBull);
|
|
||||||
PlotIndexSetInteger(bearBufferIndex, PLOT_DRAW_TYPE, bearDrawType);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
@@ -1,366 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// -------------------------------------------
|
|
||||||
// Name: XDON
|
|
||||||
// Description: DONCHAIN Channel ...
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XDON Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
#define ShortName "XDON"
|
|
||||||
|
|
||||||
//
|
|
||||||
// INPUT ...
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Market";
|
|
||||||
input int length = 52; // Market Length
|
|
||||||
input double offset = 0; // Offset
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showOpen = true; // Show Open
|
|
||||||
input bool showHigh = true; // Show High
|
|
||||||
input bool showClose = true; // Show Close
|
|
||||||
input bool showLow = true; // Show Low
|
|
||||||
|
|
||||||
//
|
|
||||||
// BUFFERS ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 8
|
|
||||||
#property indicator_plots 8
|
|
||||||
|
|
||||||
//
|
|
||||||
#define upperOBufferIndex 0
|
|
||||||
double upperOBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XDON OU"
|
|
||||||
#property indicator_type1 DRAW_LINE
|
|
||||||
#property indicator_color1 clrCornflowerBlue
|
|
||||||
#property indicator_width1 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#define lowerOBufferIndex 1
|
|
||||||
double lowerOBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label2 "XDON OL"
|
|
||||||
#property indicator_type2 DRAW_LINE
|
|
||||||
#property indicator_color2 clrCornflowerBlue
|
|
||||||
#property indicator_width2 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#define upperCBufferIndex 2
|
|
||||||
double upperCBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label3 "XDON CU"
|
|
||||||
#property indicator_type3 DRAW_LINE
|
|
||||||
#property indicator_color3 clrCoral
|
|
||||||
#property indicator_width3 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#define lowerCBufferIndex 3
|
|
||||||
double lowerCBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label4 "XDON CL"
|
|
||||||
#property indicator_type4 DRAW_LINE
|
|
||||||
#property indicator_color4 clrCoral
|
|
||||||
#property indicator_width4 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#define upperHBufferIndex 4
|
|
||||||
double upperHBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label5 "XDON HU"
|
|
||||||
#property indicator_type5 DRAW_LINE
|
|
||||||
#property indicator_color5 clrAquamarine
|
|
||||||
#property indicator_width5 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#define lowerHBufferIndex 5
|
|
||||||
double lowerHBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label6 "XDON HL"
|
|
||||||
#property indicator_type6 DRAW_LINE
|
|
||||||
#property indicator_color6 clrAquamarine
|
|
||||||
#property indicator_width6 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#define upperLBufferIndex 6
|
|
||||||
double upperLBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label7 "XDON LU"
|
|
||||||
#property indicator_type7 DRAW_LINE
|
|
||||||
#property indicator_color7 clrDarkOrchid
|
|
||||||
#property indicator_width7 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#define lowerLBufferIndex 7
|
|
||||||
double lowerLBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label8 "XDON LL"
|
|
||||||
#property indicator_type8 DRAW_LINE
|
|
||||||
#property indicator_color8 clrDarkOrchid
|
|
||||||
#property indicator_width8 2
|
|
||||||
|
|
||||||
//
|
|
||||||
// EVENT Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (rates_total < length - 1)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int start = prev_calculated == 0
|
|
||||||
? length
|
|
||||||
: prev_calculated - 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main Loop ...
|
|
||||||
for (int barIndex = start; barIndex < rates_total; barIndex++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// OPEN ...
|
|
||||||
|
|
||||||
//
|
|
||||||
double upperOValue = open[ArrayMaximum(open, barIndex - length + 1, length)];
|
|
||||||
double lowerOValue = open[ArrayMinimum(open, barIndex - length + 1, length)];
|
|
||||||
|
|
||||||
//
|
|
||||||
double oDelta = MathAbs(upperOValue - lowerOValue);
|
|
||||||
double oOffsetValue = oDelta * (offset) * 0.01;
|
|
||||||
|
|
||||||
//
|
|
||||||
upperOBuffer[barIndex] = upperOValue - oOffsetValue;
|
|
||||||
lowerOBuffer[barIndex] = lowerOValue + oOffsetValue;
|
|
||||||
|
|
||||||
//
|
|
||||||
// CLOSE ...
|
|
||||||
|
|
||||||
//
|
|
||||||
double upperCValue = close[ArrayMaximum(close, barIndex - length + 1, length)];
|
|
||||||
double lowerCValue = close[ArrayMinimum(close, barIndex - length + 1, length)];
|
|
||||||
|
|
||||||
//
|
|
||||||
double cDelta = MathAbs(upperCValue - lowerCValue);
|
|
||||||
double cOffsetValue = cDelta * (offset) * 0.01;
|
|
||||||
|
|
||||||
//
|
|
||||||
upperCBuffer[barIndex] = upperCValue - cOffsetValue;
|
|
||||||
lowerCBuffer[barIndex] = lowerCValue + cOffsetValue;
|
|
||||||
|
|
||||||
//
|
|
||||||
// HIGH ...
|
|
||||||
|
|
||||||
//
|
|
||||||
double upperHValue = high[ArrayMaximum(high, barIndex - length + 1, length)];
|
|
||||||
double lowerHValue = high[ArrayMinimum(high, barIndex - length + 1, length)];
|
|
||||||
|
|
||||||
//
|
|
||||||
double hDelta = MathAbs(upperHValue - lowerHValue);
|
|
||||||
double hOffsetValue = hDelta * (offset) * 0.01;
|
|
||||||
|
|
||||||
//
|
|
||||||
upperHBuffer[barIndex] = upperHValue - hOffsetValue;
|
|
||||||
lowerHBuffer[barIndex] = lowerHValue + hOffsetValue;
|
|
||||||
|
|
||||||
//
|
|
||||||
// LOW ...
|
|
||||||
|
|
||||||
//
|
|
||||||
double upperLValue = low[ArrayMaximum(low, barIndex - length + 1, length)];
|
|
||||||
double lowerLValue = low[ArrayMinimum(low, barIndex - length + 1, length)];
|
|
||||||
|
|
||||||
//
|
|
||||||
double lDelta = MathAbs(upperLValue - lowerLValue);
|
|
||||||
double lOffsetValue = lDelta * (offset) * 0.01;
|
|
||||||
|
|
||||||
//
|
|
||||||
upperLBuffer[barIndex] = upperLValue - lOffsetValue;
|
|
||||||
lowerLBuffer[barIndex] = lowerLValue + lOffsetValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// CUSTOM Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = length >= 7;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Open ...
|
|
||||||
ENUM_DRAW_TYPE openDrawType = showOpen ? DRAW_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// UPPER ...
|
|
||||||
SetIndexBuffer(upperOBufferIndex, upperOBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(upperOBufferIndex, PLOT_SHOW_DATA, showOpen);
|
|
||||||
PlotIndexSetDouble(upperOBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
|
||||||
PlotIndexSetInteger(upperOBufferIndex, PLOT_DRAW_TYPE, openDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// LOWER ...
|
|
||||||
SetIndexBuffer(lowerOBufferIndex, lowerOBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(lowerOBufferIndex, PLOT_SHOW_DATA, showOpen);
|
|
||||||
PlotIndexSetDouble(lowerOBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
|
||||||
PlotIndexSetInteger(lowerOBufferIndex, PLOT_DRAW_TYPE, openDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Close ...
|
|
||||||
ENUM_DRAW_TYPE closeDrawType = showClose ? DRAW_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// UPPER ...
|
|
||||||
SetIndexBuffer(upperCBufferIndex, upperCBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(upperCBufferIndex, PLOT_SHOW_DATA, showClose);
|
|
||||||
PlotIndexSetDouble(upperCBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
|
||||||
PlotIndexSetInteger(upperCBufferIndex, PLOT_DRAW_TYPE, closeDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// LOWER ...
|
|
||||||
SetIndexBuffer(lowerCBufferIndex, lowerCBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(lowerCBufferIndex, PLOT_SHOW_DATA, showClose);
|
|
||||||
PlotIndexSetDouble(lowerCBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
|
||||||
PlotIndexSetInteger(lowerCBufferIndex, PLOT_DRAW_TYPE, closeDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// High ...
|
|
||||||
ENUM_DRAW_TYPE highDrawType = showHigh ? DRAW_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// UPPER ...
|
|
||||||
SetIndexBuffer(upperHBufferIndex, upperHBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(upperHBufferIndex, PLOT_SHOW_DATA, showHigh);
|
|
||||||
PlotIndexSetDouble(upperHBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
|
||||||
PlotIndexSetInteger(upperHBufferIndex, PLOT_DRAW_TYPE, highDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// LOWER ...
|
|
||||||
SetIndexBuffer(lowerHBufferIndex, lowerHBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(lowerHBufferIndex, PLOT_SHOW_DATA, showHigh);
|
|
||||||
PlotIndexSetDouble(lowerHBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
|
||||||
PlotIndexSetInteger(lowerHBufferIndex, PLOT_DRAW_TYPE, highDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Low ...
|
|
||||||
ENUM_DRAW_TYPE lowDrawType = showLow ? DRAW_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// UPPER ...
|
|
||||||
SetIndexBuffer(upperLBufferIndex, upperLBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(upperLBufferIndex, PLOT_SHOW_DATA, showLow);
|
|
||||||
PlotIndexSetDouble(upperLBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
|
||||||
PlotIndexSetInteger(upperLBufferIndex, PLOT_DRAW_TYPE, lowDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// LOWER ...
|
|
||||||
SetIndexBuffer(lowerLBufferIndex, lowerLBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(lowerLBufferIndex, PLOT_SHOW_DATA, showLow);
|
|
||||||
PlotIndexSetDouble(lowerLBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
|
||||||
PlotIndexSetInteger(lowerLBufferIndex, PLOT_DRAW_TYPE, lowDrawType);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
@@ -1,479 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// --------------------------------------------
|
|
||||||
// Name: XHK
|
|
||||||
// Description: Hiken Ashi ...
|
|
||||||
// Market Analysor ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XHK Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
// Constants ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Indicator Short Name ...
|
|
||||||
#define ShortName "XHK"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Imports ...
|
|
||||||
#include <MovingAverages.mqh>
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Inputs ...
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Market";
|
|
||||||
input int smoothingLength = 17; // Smoothing Length
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool drawHikenAshi = true; // Draw Hiken Ashi
|
|
||||||
input bool drawSmoothedHikenAshi = true; // Draw Smoothed Hiken Ashi
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 10
|
|
||||||
#property indicator_plots 10
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Open ...
|
|
||||||
#define openBufferIndex 0
|
|
||||||
double openBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// High ...
|
|
||||||
#define highBufferIndex 1
|
|
||||||
double highBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// Low ...
|
|
||||||
#define lowBufferIndex 2
|
|
||||||
double lowBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// Close ...
|
|
||||||
#define closeBufferIndex 3
|
|
||||||
double closeBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// Candle Color ...
|
|
||||||
#define candleColorBufferIndex 4
|
|
||||||
double candleColorBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define candlesBufferIndex 0
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XHK Open;XHK High;XHK Low;XHK Close"
|
|
||||||
#property indicator_type1 DRAW_COLOR_CANDLES
|
|
||||||
#property indicator_color1 CLR_NONE, clrAqua, clrMagenta
|
|
||||||
|
|
||||||
//
|
|
||||||
// SM Open ...
|
|
||||||
#define openSMBufferIndex 5
|
|
||||||
double openSMBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// SM High ...
|
|
||||||
#define highSMBufferIndex 6
|
|
||||||
double highSMBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// SM Low ...
|
|
||||||
#define lowSMBufferIndex 7
|
|
||||||
double lowSMBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// SM Close ...
|
|
||||||
#define closeSMBufferIndex 8
|
|
||||||
double closeSMBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// SM Candle Color ...
|
|
||||||
#define candleColorSMBufferIndex 9
|
|
||||||
double candleColorSMBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define candlesSMBufferIndex 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label2 "XSMHK Open;XSMHK High;XSMHK Low;XSMHK Close"
|
|
||||||
#property indicator_type2 DRAW_COLOR_CANDLES
|
|
||||||
#property indicator_color2 CLR_NONE, clrDarkGreen, clrDarkRed
|
|
||||||
|
|
||||||
//
|
|
||||||
// Variables, Properties and etc ...
|
|
||||||
|
|
||||||
//
|
|
||||||
int maxLength;
|
|
||||||
|
|
||||||
//
|
|
||||||
double mHideColorIDX = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Event Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// because in some cases we may have more than one input for
|
|
||||||
// calculation and we must prevent any calculation
|
|
||||||
// untill we pass the biggest input length, here we get max Input length
|
|
||||||
// and then wait until pass it ...
|
|
||||||
maxLength = ExtractMaxLengthOfInputs();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Prepare Buffers ...
|
|
||||||
ArraySetAsSeries(time, true);
|
|
||||||
ArraySetAsSeries(open, true);
|
|
||||||
ArraySetAsSeries(high, true);
|
|
||||||
ArraySetAsSeries(low, true);
|
|
||||||
ArraySetAsSeries(close, true);
|
|
||||||
ArraySetAsSeries(tick_volume, true);
|
|
||||||
ArraySetAsSeries(volume, true);
|
|
||||||
ArraySetAsSeries(spread, true);
|
|
||||||
|
|
||||||
//
|
|
||||||
// this counts Available Bars ...
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
//
|
|
||||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main Loop ...
|
|
||||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
|
||||||
{
|
|
||||||
CalculateBuffers(i, prev_calculated, rates_total, open, high, close, low);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
CalculateSM(rates_total, prev_calculated);
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = true;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve all Exists Input Max Length ...
|
|
||||||
// use for Start Of Drawing ...
|
|
||||||
int ExtractMaxLengthOfInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Candles Color ...
|
|
||||||
ArraySetAsSeries(candleColorBuffer, true);
|
|
||||||
SetIndexBuffer(candleColorBufferIndex, candleColorBuffer, INDICATOR_COLOR_INDEX);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set EMPTY_VALUE on Candles Buffer ...
|
|
||||||
PlotIndexSetDouble(candlesBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
|
||||||
|
|
||||||
//
|
|
||||||
PlotIndexSetInteger(candlesBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
PlotIndexSetInteger(candleColorBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Open ...
|
|
||||||
ArraySetAsSeries(openBuffer, true);
|
|
||||||
PlotIndexSetInteger(openBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA);
|
|
||||||
|
|
||||||
//
|
|
||||||
// High ...
|
|
||||||
ArraySetAsSeries(highBuffer, true);
|
|
||||||
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(highBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Close ...
|
|
||||||
ArraySetAsSeries(closeBuffer, true);
|
|
||||||
SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(closeBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Low ...
|
|
||||||
ArraySetAsSeries(lowBuffer, true);
|
|
||||||
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(lowBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Candles Color ...
|
|
||||||
ArraySetAsSeries(candleColorSMBuffer, true);
|
|
||||||
SetIndexBuffer(candleColorSMBufferIndex, candleColorSMBuffer, INDICATOR_COLOR_INDEX);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set EMPTY_VALUE on Candles Buffer ...
|
|
||||||
PlotIndexSetDouble(candlesSMBufferIndex, PLOT_EMPTY_VALUE, 0.0);
|
|
||||||
|
|
||||||
//
|
|
||||||
PlotIndexSetInteger(candlesSMBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
PlotIndexSetInteger(candleColorSMBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Open ...
|
|
||||||
ArraySetAsSeries(openSMBuffer, true);
|
|
||||||
PlotIndexSetInteger(openSMBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
SetIndexBuffer(openSMBufferIndex, openSMBuffer, INDICATOR_DATA);
|
|
||||||
|
|
||||||
//
|
|
||||||
// High ...
|
|
||||||
ArraySetAsSeries(highSMBuffer, true);
|
|
||||||
SetIndexBuffer(highSMBufferIndex, highSMBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(highSMBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Close ...
|
|
||||||
ArraySetAsSeries(closeSMBuffer, true);
|
|
||||||
SetIndexBuffer(closeSMBufferIndex, closeSMBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(closeSMBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Low ...
|
|
||||||
ArraySetAsSeries(lowSMBuffer, true);
|
|
||||||
SetIndexBuffer(lowSMBufferIndex, lowSMBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(lowSMBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Buffers ...
|
|
||||||
void CalculateBuffers(
|
|
||||||
int bar_index, // Selected Bar Index
|
|
||||||
const int prevCalculated,
|
|
||||||
const int ratesTotal,
|
|
||||||
const double &open[],
|
|
||||||
const double &high[],
|
|
||||||
const double &close[],
|
|
||||||
const double &low[] //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double mPrevHKOpenValue;
|
|
||||||
double mPrevHKCloseValue;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (ArraySize(open) <= bar_index + 1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mPrevHKOpenValue = 0;
|
|
||||||
mPrevHKCloseValue = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mPrevHKOpenValue = openBuffer[bar_index + 1];
|
|
||||||
mPrevHKCloseValue = closeBuffer[bar_index + 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
double mHKOpenValue = (mPrevHKOpenValue + mPrevHKCloseValue) / 2;
|
|
||||||
double mHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4;
|
|
||||||
double mHKHighValue = MathMax(high[bar_index], MathMax(mHKOpenValue, mHKCloseValue));
|
|
||||||
double mHKLowValue = MathMin(low[bar_index], MathMin(mHKOpenValue, mHKCloseValue));
|
|
||||||
|
|
||||||
//
|
|
||||||
openBuffer[bar_index] = mHKOpenValue;
|
|
||||||
highBuffer[bar_index] = mHKHighValue;
|
|
||||||
lowBuffer[bar_index] = mHKLowValue;
|
|
||||||
closeBuffer[bar_index] = mHKCloseValue;
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isBearish =
|
|
||||||
//
|
|
||||||
openBuffer[bar_index] > closeBuffer[bar_index]
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
candleColorBuffer[bar_index] = !drawHikenAshi
|
|
||||||
? mHideColorIDX
|
|
||||||
: isBearish
|
|
||||||
? 2
|
|
||||||
: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Smoothed HikenAshi ...
|
|
||||||
void CalculateSM(
|
|
||||||
int ratesTotal, // Total Bars
|
|
||||||
int prevCalculated // Calculated Bars
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Open ...
|
|
||||||
int calculatedSMHKOpens = ExponentialMAOnBuffer(
|
|
||||||
ratesTotal,
|
|
||||||
prevCalculated,
|
|
||||||
0,
|
|
||||||
smoothingLength,
|
|
||||||
openBuffer,
|
|
||||||
openSMBuffer);
|
|
||||||
|
|
||||||
//
|
|
||||||
// High ...
|
|
||||||
int calculatedSMHKHighs = ExponentialMAOnBuffer(
|
|
||||||
ratesTotal,
|
|
||||||
prevCalculated,
|
|
||||||
0,
|
|
||||||
smoothingLength,
|
|
||||||
highBuffer,
|
|
||||||
highSMBuffer);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Low ...
|
|
||||||
int calculatedSMHKLows = ExponentialMAOnBuffer(
|
|
||||||
ratesTotal,
|
|
||||||
prevCalculated,
|
|
||||||
0,
|
|
||||||
smoothingLength,
|
|
||||||
lowBuffer,
|
|
||||||
lowSMBuffer);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Close ...
|
|
||||||
int calculatedSMHKCloses = ExponentialMAOnBuffer(
|
|
||||||
ratesTotal,
|
|
||||||
prevCalculated,
|
|
||||||
0,
|
|
||||||
smoothingLength,
|
|
||||||
closeBuffer,
|
|
||||||
closeSMBuffer);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Find Calculated Items for Colors ...
|
|
||||||
int mNumberOfItems = MathMin(calculatedSMHKOpens, calculatedSMHKHighs);
|
|
||||||
mNumberOfItems = MathMin(mNumberOfItems, calculatedSMHKLows);
|
|
||||||
mNumberOfItems = MathMin(mNumberOfItems, calculatedSMHKCloses);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Create a Loop for Color of Candles ...
|
|
||||||
for (int i = 0; i < mNumberOfItems; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool isBearish =
|
|
||||||
//
|
|
||||||
openSMBuffer[i] > closeSMBuffer[i]
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (drawSmoothedHikenAshi)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
candleColorSMBuffer[i] = isBearish
|
|
||||||
? 2
|
|
||||||
: 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
candleColorSMBuffer[i] = mHideColorIDX;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,368 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// -------------------------------------------
|
|
||||||
// Name: XHTD
|
|
||||||
// Description: HULL Trend Detector ...
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XHTD Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
#define ShortName "XHTD"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Imports ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Inputs ...
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Market";
|
|
||||||
input int length = 14; // Length
|
|
||||||
input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To
|
|
||||||
input double multiplier = 0.66; // Multiplier
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool show = true; // Show
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 2
|
|
||||||
#property indicator_plots 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#define mainBufferIndex 0
|
|
||||||
double mainBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define mainBufferColorIndex 1
|
|
||||||
double mainBufferColor[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define hideColorIDX 0
|
|
||||||
#define bullColorIDX 1
|
|
||||||
#define bearColorIDX 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XHTD"
|
|
||||||
#property indicator_type1 DRAW_COLOR_LINE
|
|
||||||
#property indicator_color1 CLR_NONE, clrGreen, clrDarkRed
|
|
||||||
#property indicator_style1 STYLE_DOT
|
|
||||||
#property indicator_width1 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define upBufferIndex 2
|
|
||||||
double upBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define downBufferIndex 3
|
|
||||||
double downBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define directionBufferIndex 4
|
|
||||||
double directionBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// Event Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (ArraySize(directionBuffer) != rates_total)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
ArrayResize(upBuffer, rates_total);
|
|
||||||
ArrayResize(downBuffer, rates_total);
|
|
||||||
ArrayResize(directionBuffer, rates_total);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = (int)MathMax(prev_calculated - 1, 1); i < rates_total; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double atr = 0;
|
|
||||||
for (int k = 0; k < length && (i - k - 1) >= 0; k++)
|
|
||||||
{
|
|
||||||
atr += MathMax(high[i - k], close[i - k - 1]) - MathMin(low[i - k], close[i - k - 1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
atr /= length;
|
|
||||||
|
|
||||||
//
|
|
||||||
double cprice = close[i];
|
|
||||||
double appliedPrice = getPrice(
|
|
||||||
appliedTo,
|
|
||||||
open,
|
|
||||||
close,
|
|
||||||
high,
|
|
||||||
low,
|
|
||||||
i,
|
|
||||||
rates_total //
|
|
||||||
);
|
|
||||||
double mprice = iHull(
|
|
||||||
appliedPrice,
|
|
||||||
length,
|
|
||||||
i,
|
|
||||||
rates_total //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
upBuffer[i] = mprice + multiplier * atr;
|
|
||||||
downBuffer[i] = mprice - multiplier * atr;
|
|
||||||
|
|
||||||
//
|
|
||||||
mainBufferColor[i] = mainBufferColor[i - 1];
|
|
||||||
directionBuffer[i] = directionBuffer[i - 1];
|
|
||||||
|
|
||||||
//
|
|
||||||
if (cprice > upBuffer[i - 1])
|
|
||||||
{
|
|
||||||
directionBuffer[i] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (cprice < downBuffer[i - 1])
|
|
||||||
{
|
|
||||||
directionBuffer[i] = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (directionBuffer[i] > 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
downBuffer[i] = MathMax(downBuffer[i], downBuffer[i - 1]);
|
|
||||||
|
|
||||||
//
|
|
||||||
mainBuffer[i] = downBuffer[i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
upBuffer[i] = MathMin(upBuffer[i], upBuffer[i - 1]);
|
|
||||||
|
|
||||||
//
|
|
||||||
mainBuffer[i] = upBuffer[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (directionBuffer[i] == 1)
|
|
||||||
{
|
|
||||||
mainBufferColor[i] = bullColorIDX;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (directionBuffer[i] == -1)
|
|
||||||
{
|
|
||||||
mainBufferColor[i] = bearColorIDX;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Custom Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = length >= 2 &&
|
|
||||||
multiplier > 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Main ...
|
|
||||||
ENUM_DRAW_TYPE mainDrawType = show ? DRAW_COLOR_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
PlotIndexSetInteger(mainBufferIndex, PLOT_SHOW_DATA, true);
|
|
||||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(mainBufferIndex, PLOT_DRAW_TYPE, mainDrawType);
|
|
||||||
SetIndexBuffer(mainBufferColorIndex, mainBufferColor, INDICATOR_COLOR_INDEX);
|
|
||||||
|
|
||||||
//
|
|
||||||
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
SetIndexBuffer(directionBufferIndex, directionBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Hull Handler ...
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
double getPrice(ENUM_APPLIED_PRICE price, const double& open[], const double& close[], const double& high[], const double& low[], int i, int bars)
|
|
||||||
{
|
|
||||||
switch (price)
|
|
||||||
{
|
|
||||||
case PRICE_CLOSE: return(close[i]);
|
|
||||||
case PRICE_OPEN: return(open[i]);
|
|
||||||
case PRICE_HIGH: return(high[i]);
|
|
||||||
case PRICE_LOW: return(low[i]);
|
|
||||||
case PRICE_MEDIAN: return((high[i]+low[i])/2.0);
|
|
||||||
case PRICE_TYPICAL: return((high[i]+low[i]+close[i])/3.0);
|
|
||||||
case PRICE_WEIGHTED: return((high[i]+low[i]+close[i]+close[i])/4.0);
|
|
||||||
//case PRICE_AVERAGE: return((high[i]+low[i]+close[i]+open[i])/4.0);
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
@@ -1,583 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// ---------------------------------------------
|
|
||||||
// Name: XHULL
|
|
||||||
// Description: Hull Trend Indicator ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XHULL Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
#define ShortName "XHULL"
|
|
||||||
|
|
||||||
//
|
|
||||||
struct XHullData
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double value;
|
|
||||||
double value3;
|
|
||||||
|
|
||||||
//
|
|
||||||
double wsum1;
|
|
||||||
double wsum2;
|
|
||||||
double wsum3;
|
|
||||||
|
|
||||||
//
|
|
||||||
double lsum1;
|
|
||||||
double lsum2;
|
|
||||||
double lsum3;
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Includes and Imports ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Includes Common Library ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Includes and Imports ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START XSCHULL Class Definition ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// a Class For Hull Calculations ...
|
|
||||||
class XSCHull
|
|
||||||
{
|
|
||||||
//
|
|
||||||
public:
|
|
||||||
//
|
|
||||||
// Constructor ...
|
|
||||||
XSCHull() : mFullPeriod(1), mHalfPeriod(1), mSqrtPeriod(1), mArraySize(-1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// These are a way above to assign Private variables at Construct time ...
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Deconstructor ...
|
|
||||||
~XSCHull()
|
|
||||||
{
|
|
||||||
ArrayFree(mData);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initial Hull ...
|
|
||||||
bool Init(
|
|
||||||
int mPeriod,
|
|
||||||
double mDivisor)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
mFullPeriod = (int)(mPeriod > 1 ? mPeriod : 1);
|
|
||||||
mHalfPeriod = (int)(mFullPeriod > 1 ? mFullPeriod / (mDivisor > 1 ? mDivisor : 1) : 1);
|
|
||||||
mSqrtPeriod = (int)MathSqrt(mFullPeriod);
|
|
||||||
|
|
||||||
//
|
|
||||||
mArraySize = -1;
|
|
||||||
mWeight1 = mWeight2 = mWeight3 = 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = true;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// CalCulate Specific Value ...
|
|
||||||
double Calculate(
|
|
||||||
double value,
|
|
||||||
int i,
|
|
||||||
int bars)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (mArraySize < bars)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mArraySize = ArrayResize(mData, bars + 500);
|
|
||||||
if (mArraySize < bars)
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
mData[i].value = value;
|
|
||||||
if (i > mFullPeriod)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mData[i].wsum1 = mData[i - 1].wsum1 + value * mHalfPeriod - mData[i - 1].lsum1;
|
|
||||||
mData[i].lsum1 = mData[i - 1].lsum1 + value - mData[i - mHalfPeriod].value;
|
|
||||||
mData[i].wsum2 = mData[i - 1].wsum2 + value * mFullPeriod - mData[i - 1].lsum2;
|
|
||||||
mData[i].lsum2 = mData[i - 1].lsum2 + value - mData[i - mFullPeriod].value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mData[i].wsum1 = mData[i].wsum2 =
|
|
||||||
mData[i].lsum1 = mData[i].lsum2 = mWeight1 = mWeight2 = 0;
|
|
||||||
for (int k = 0, w1 = mHalfPeriod, w2 = mFullPeriod; w2 > 0 && i >= k; k++, w1--, w2--)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (w1 > 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mData[i].wsum1 += mData[i - k].value * w1;
|
|
||||||
mData[i].lsum1 += mData[i - k].value;
|
|
||||||
mWeight1 += w1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
mData[i].wsum2 += mData[i - k].value * w2;
|
|
||||||
mData[i].lsum2 += mData[i - k].value;
|
|
||||||
mWeight2 += w2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
mData[i].value3 = 2.0 * mData[i].wsum1 / mWeight1 - mData[i].wsum2 / mWeight2;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (i > mSqrtPeriod)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mData[i].wsum3 = mData[i - 1].wsum3 + mData[i].value3 * mSqrtPeriod - mData[i - 1].lsum3;
|
|
||||||
mData[i].lsum3 = mData[i - 1].lsum3 + mData[i].value3 - mData[i - mSqrtPeriod].value3;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mData[i].wsum3 =
|
|
||||||
mData[i].lsum3 = mWeight3 = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int k = 0, w3 = mSqrtPeriod; w3 > 0 && i >= k; k++, w3--)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mData[i].wsum3 += mData[i - k].value3 * w3;
|
|
||||||
mData[i].lsum3 += mData[i - k].value3;
|
|
||||||
mWeight3 += w3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = mData[i].wsum3 / mWeight3;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Protected ...
|
|
||||||
protected:
|
|
||||||
//
|
|
||||||
// Private ...
|
|
||||||
private:
|
|
||||||
//
|
|
||||||
int mFullPeriod;
|
|
||||||
int mHalfPeriod;
|
|
||||||
int mSqrtPeriod;
|
|
||||||
int mArraySize;
|
|
||||||
double mWeight1;
|
|
||||||
double mWeight2;
|
|
||||||
double mWeight3;
|
|
||||||
|
|
||||||
//
|
|
||||||
XHullData mData[];
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// END XSCHULL Class Definition ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Market";
|
|
||||||
input int length = 72; // Length
|
|
||||||
input double divisor = 2.0; // Divisor (Speed)
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Calculation";
|
|
||||||
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Zone Applied to
|
|
||||||
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Zone Applied to
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showUpZone = true; // Show Up Zone
|
|
||||||
input bool showDownZone = true; // Show Down Zone
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Buffers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 4
|
|
||||||
#property indicator_plots 4
|
|
||||||
|
|
||||||
//
|
|
||||||
// UP Zone ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define upZoneBufferIndex 0
|
|
||||||
#define upZoneColorBufferIndex 1
|
|
||||||
|
|
||||||
//
|
|
||||||
double upZoneBuffer[];
|
|
||||||
double upZoneColorBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XHULL Up"
|
|
||||||
#property indicator_type1 DRAW_COLOR_LINE
|
|
||||||
#property indicator_color1 clrLightGray, clrAqua, clrMagenta
|
|
||||||
#property indicator_width1 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// DOWN Zone ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define downZoneBufferIndex 2
|
|
||||||
#define downZoneColorBufferIndex 3
|
|
||||||
|
|
||||||
//
|
|
||||||
double downZoneBuffer[];
|
|
||||||
double downZoneColorBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label2 "XHULL Down"
|
|
||||||
#property indicator_type2 DRAW_COLOR_LINE
|
|
||||||
#property indicator_color2 clrLightGray, clrAqua, clrMagenta
|
|
||||||
#property indicator_width2 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Buffers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
int maxLength;
|
|
||||||
|
|
||||||
//
|
|
||||||
XSCHull *mUpZHull;
|
|
||||||
XSCHull *mDownZHull;
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Event Handlers ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// because in some cases we may have more than one input for
|
|
||||||
// calculation and we must prevent any calculation
|
|
||||||
// untill we pass the biggest input length, here we get max Input length
|
|
||||||
// and then wait until pass it ...
|
|
||||||
maxLength = ExtractMaxLengthOfInputs();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Make an Instance of Hull Class ...
|
|
||||||
|
|
||||||
//
|
|
||||||
mUpZHull = new XSCHull();
|
|
||||||
mUpZHull.Init(
|
|
||||||
length,
|
|
||||||
divisor);
|
|
||||||
|
|
||||||
//
|
|
||||||
mDownZHull = new XSCHull();
|
|
||||||
mDownZHull.Init(
|
|
||||||
length,
|
|
||||||
divisor);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart mPeriod is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
|
|
||||||
//
|
|
||||||
delete mUpZHull;
|
|
||||||
delete mDownZHull;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// this counts Available Bars ...
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
//
|
|
||||||
limit = prev_calculated - 1;
|
|
||||||
if (limit < 0)
|
|
||||||
{
|
|
||||||
limit = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main Loop ...
|
|
||||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double upPrice = getPrice(
|
|
||||||
upAppliedTo,
|
|
||||||
open, high, low, close, i);
|
|
||||||
|
|
||||||
//
|
|
||||||
double downPrice = getPrice(
|
|
||||||
downAppliedTo,
|
|
||||||
open, high, low, close, i);
|
|
||||||
|
|
||||||
//
|
|
||||||
CalculateBuffers(
|
|
||||||
i,
|
|
||||||
rates_total,
|
|
||||||
upPrice,
|
|
||||||
downPrice);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// END Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Functions ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = true;
|
|
||||||
|
|
||||||
//
|
|
||||||
result =
|
|
||||||
length >= 9 &&
|
|
||||||
divisor >= 0.5;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve all Exists Input Max Length ...
|
|
||||||
// use for Start Of Drawing ...
|
|
||||||
int ExtractMaxLengthOfInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = length;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// UP Zone ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Draw Type ...
|
|
||||||
ENUM_DRAW_TYPE upZoneDrawType = showUpZone ? DRAW_COLOR_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffer ...
|
|
||||||
SetIndexBuffer(upZoneBufferIndex, upZoneBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(upZoneBufferIndex, PLOT_SHOW_DATA, showUpZone);
|
|
||||||
PlotIndexSetInteger(upZoneBufferIndex, PLOT_DRAW_TYPE, upZoneDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Color Buffer ...
|
|
||||||
SetIndexBuffer(upZoneColorBufferIndex, upZoneColorBuffer, INDICATOR_COLOR_INDEX);
|
|
||||||
|
|
||||||
//
|
|
||||||
// DOWN Zone ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Draw Type ...
|
|
||||||
ENUM_DRAW_TYPE downZoneDrawType = showDownZone ? DRAW_COLOR_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffer ...
|
|
||||||
SetIndexBuffer(downZoneBufferIndex, downZoneBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(downZoneBufferIndex - 1, PLOT_SHOW_DATA, showDownZone);
|
|
||||||
PlotIndexSetInteger(downZoneBufferIndex - 1, PLOT_DRAW_TYPE, downZoneDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Color Buffer ...
|
|
||||||
SetIndexBuffer(downZoneColorBufferIndex, downZoneColorBuffer, INDICATOR_COLOR_INDEX);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Buffers ...
|
|
||||||
void CalculateBuffers(
|
|
||||||
int bar_index, // Selected Bar Index
|
|
||||||
int ratesTotal, // Total Rates
|
|
||||||
double upPrice, // Up Price ...
|
|
||||||
double downPrice // Down Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double upValue = mUpZHull.Calculate(
|
|
||||||
upPrice,
|
|
||||||
bar_index,
|
|
||||||
ratesTotal);
|
|
||||||
upZoneBuffer[bar_index] = upValue;
|
|
||||||
double upColorIDX = (bar_index > 0)
|
|
||||||
? (upZoneBuffer[bar_index] > upZoneBuffer[bar_index - 1])
|
|
||||||
? 1
|
|
||||||
: (upZoneBuffer[bar_index] < upZoneBuffer[bar_index - 1])
|
|
||||||
? 2
|
|
||||||
: upZoneColorBuffer[bar_index - 1]
|
|
||||||
: 0;
|
|
||||||
upZoneColorBuffer[bar_index] = upColorIDX;
|
|
||||||
|
|
||||||
//
|
|
||||||
double downValue = mDownZHull.Calculate(
|
|
||||||
downPrice,
|
|
||||||
bar_index,
|
|
||||||
ratesTotal);
|
|
||||||
downZoneBuffer[bar_index] = downValue;
|
|
||||||
double downColorIDX = (bar_index > 0)
|
|
||||||
? (downZoneBuffer[bar_index] > downZoneBuffer[bar_index - 1])
|
|
||||||
? 1
|
|
||||||
: (downZoneBuffer[bar_index] < downZoneBuffer[bar_index - 1])
|
|
||||||
? 2
|
|
||||||
: downZoneColorBuffer[bar_index - 1]
|
|
||||||
: 0;
|
|
||||||
downZoneColorBuffer[bar_index] = downColorIDX;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Functions ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// TEMPLATE Function ...
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i)
|
|
||||||
{
|
|
||||||
switch (tprice)
|
|
||||||
{
|
|
||||||
case PRICE_CLOSE:
|
|
||||||
return (close[i]);
|
|
||||||
case PRICE_OPEN:
|
|
||||||
return (open[i]);
|
|
||||||
case PRICE_HIGH:
|
|
||||||
return (high[i]);
|
|
||||||
case PRICE_LOW:
|
|
||||||
return (low[i]);
|
|
||||||
case PRICE_MEDIAN:
|
|
||||||
return ((high[i] + low[i]) / 2.0);
|
|
||||||
case PRICE_TYPICAL:
|
|
||||||
return ((high[i] + low[i] + close[i]) / 3.0);
|
|
||||||
case PRICE_WEIGHTED:
|
|
||||||
return ((high[i] + low[i] + close[i] + close[i]) / 4.0);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,827 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// -------------------------------------------------
|
|
||||||
// Name: XICH
|
|
||||||
// Description: Ichimoku Kinko Hyo ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XICH Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Indicator Short Name ...
|
|
||||||
#define ShortName "XICH"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Ichimoku Golden Numbers ...
|
|
||||||
enum ENUM_X_ICHIMOKU_GOLDEN_NUMBERS
|
|
||||||
{
|
|
||||||
X_ICH_BASE = 9,
|
|
||||||
X_ICH_GOLDEN = 17,
|
|
||||||
X_ICH_CYCLE = 26,
|
|
||||||
X_ICH_PERIOD = 35,
|
|
||||||
X_ICH_STAR = 45,
|
|
||||||
X_ICH_MED = 52,
|
|
||||||
X_ICH_LONG = 63,
|
|
||||||
X_ICH_FULL = 72
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// Ichimoku Lines Calculator Mode ...
|
|
||||||
enum ENUM_X_ICHIMOKU_CALCULATION_MODE
|
|
||||||
{
|
|
||||||
//
|
|
||||||
X_XICH_HH_LL_MODE = 1, // Highest High and Lowest Low
|
|
||||||
X_XICH_HO_LC_MODE = 2, // Highest Open and Lowest Close
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// ICHIMOKU Kinko Hyo ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// TENKANSEN ...
|
|
||||||
input group "Tenkan Sen";
|
|
||||||
input int tenkanSenLength = 9; // Length
|
|
||||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE tenkanSenMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
|
||||||
|
|
||||||
//
|
|
||||||
// KIJUNSEN ...
|
|
||||||
input group "Kijun Sen";
|
|
||||||
input int kijunSenLength = 26; // Length
|
|
||||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE kijunSenMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
|
||||||
|
|
||||||
//
|
|
||||||
// SENKOUSPANB ...
|
|
||||||
input group "Senkou Span B";
|
|
||||||
input int senkouSpanBLength = 52; // Length
|
|
||||||
input ENUM_X_ICHIMOKU_CALCULATION_MODE senkouSpanBMode = X_XICH_HH_LL_MODE; // Calculation Mode
|
|
||||||
|
|
||||||
//
|
|
||||||
// CHIKOUSPAN ...
|
|
||||||
input group "Chikou Span";
|
|
||||||
input ENUM_APPLIED_PRICE chikuoSpanAppliedTo = PRICE_CLOSE; // Price Type
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showTenkanSen = true; // Show Tenkan Sen
|
|
||||||
input bool showKijunSen = true; // Show Kijun Sen
|
|
||||||
input bool showKijunSenPlus = false; // Show Kijun Sen +
|
|
||||||
input bool showKijunSenNegative = false; // Show Kijun Sen -
|
|
||||||
input bool showChikouSpan = true; // Show Chikou Span
|
|
||||||
input bool showSenkouSpanA = true; // Show Senkou Span A
|
|
||||||
input bool showSenkouSpanB = true; // Show Senkou Span B
|
|
||||||
input bool showKumo = true; // Show Kumo
|
|
||||||
input bool shiftKumo = true; // Shift Kumo to Future
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Includes and Imports ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Includes Common Library ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Includes and Imports ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Buffers ...
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 15
|
|
||||||
#property indicator_plots 8
|
|
||||||
|
|
||||||
//
|
|
||||||
// PLOTTED Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// ICHIMOKU ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// TENKANSEN ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define tenkanSenBufferIndex 0
|
|
||||||
double tenkanSenBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XICH TK"
|
|
||||||
#property indicator_type1 DRAW_LINE
|
|
||||||
#property indicator_color1 clrBrown
|
|
||||||
#property indicator_style1 STYLE_SOLID
|
|
||||||
#property indicator_width1 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// KIJUNSEN ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define kijunSenBufferIndex 1
|
|
||||||
double kijunSenBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label2 "XICH KJ"
|
|
||||||
#property indicator_type2 DRAW_LINE
|
|
||||||
#property indicator_color2 clrDodgerBlue
|
|
||||||
#property indicator_style2 STYLE_SOLID
|
|
||||||
#property indicator_width2 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define kijunSenPlusBufferIndex 2
|
|
||||||
double kijunSenPlusBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label3 "XICH KJ+"
|
|
||||||
#property indicator_type3 DRAW_LINE
|
|
||||||
#property indicator_color3 clrMediumTurquoise
|
|
||||||
#property indicator_style3 STYLE_DOT
|
|
||||||
#property indicator_width3 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define kijunSenNegativeBufferIndex 3
|
|
||||||
double kijunSenNegativeBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label4 "XICH KJ-"
|
|
||||||
#property indicator_type4 DRAW_LINE
|
|
||||||
#property indicator_color4 clrDarkSeaGreen
|
|
||||||
#property indicator_style4 STYLE_DOT
|
|
||||||
#property indicator_width4 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// CHIKOUSPAN ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define chikouSpanBufferIndex 4
|
|
||||||
double chikouSpanBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label5 "XICH CS"
|
|
||||||
#property indicator_type5 DRAW_LINE
|
|
||||||
#property indicator_color5 clrDarkGreen
|
|
||||||
#property indicator_style5 STYLE_SOLID
|
|
||||||
#property indicator_width5 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define senkouABufferIndex 5
|
|
||||||
double senkouABuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label6 "XICH SSA"
|
|
||||||
#property indicator_type6 DRAW_LINE
|
|
||||||
#property indicator_color6 clrLightGray
|
|
||||||
#property indicator_style6 STYLE_DASHDOTDOT
|
|
||||||
#property indicator_width6 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define senkouBBufferIndex 6
|
|
||||||
double senkouBBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label7 "XICH SSB"
|
|
||||||
#property indicator_type7 DRAW_LINE
|
|
||||||
#property indicator_color7 clrLightGray
|
|
||||||
#property indicator_style7 STYLE_DASHDOTDOT
|
|
||||||
#property indicator_width7 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// KUMO ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// SENKOUSPANA ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define senkouSpanABufferIndex 7
|
|
||||||
double senkouSpanABuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// SENKOUSPANB ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define senkouSpanBBufferIndex 8
|
|
||||||
double senkouSpanBBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// KUMOCLOUD ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define kumoBufferIndex 7
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label8 "XICH Kumo"
|
|
||||||
#property indicator_type8 DRAW_FILLING
|
|
||||||
#property indicator_color8 clrAqua, clrMagenta
|
|
||||||
#property indicator_style8 STYLE_SOLID
|
|
||||||
#property indicator_width8 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// DATA Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define dTenkanBufferIndex 9
|
|
||||||
double dTenkanBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define dKijunBufferIndex 10
|
|
||||||
double dKijunBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define dChikouBufferIndex 11
|
|
||||||
double dChikouBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define dSSABufferIndex 12
|
|
||||||
double dSSABuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define dSSBBufferIndex 13
|
|
||||||
double dSSBBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Buffers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
int maxLength;
|
|
||||||
int mHandler;
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_SERIESMODE mTenkanSenTopMode = NULL;
|
|
||||||
ENUM_SERIESMODE mTenkanSenBottomMode = NULL;
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_SERIESMODE mKijunSenTopMode = NULL;
|
|
||||||
ENUM_SERIESMODE mKijunSenBottomMode = NULL;
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_SERIESMODE mSenkouSpanBTopMode = NULL;
|
|
||||||
ENUM_SERIESMODE mSenkouSpanBBottomMode = NULL;
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// because in some cases we may have more than one input for
|
|
||||||
// calculation and we must prevent any calculation
|
|
||||||
// untill we pass the biggest input length, here we get max Input length
|
|
||||||
// and then wait until pass it ...
|
|
||||||
maxLength = ExtractMaxLengthOfInputs();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Handler ...
|
|
||||||
mHandler = iIchimoku(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
tenkanSenLength,
|
|
||||||
kijunSenLength,
|
|
||||||
senkouSpanBLength);
|
|
||||||
if (mHandler == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
return INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
|
|
||||||
//
|
|
||||||
IndicatorRelease(mHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Prepare Buffers ...
|
|
||||||
ArraySetAsSeries(time, true);
|
|
||||||
ArraySetAsSeries(open, true);
|
|
||||||
ArraySetAsSeries(high, true);
|
|
||||||
ArraySetAsSeries(low, true);
|
|
||||||
ArraySetAsSeries(close, true);
|
|
||||||
ArraySetAsSeries(tick_volume, true);
|
|
||||||
ArraySetAsSeries(volume, true);
|
|
||||||
ArraySetAsSeries(spread, true);
|
|
||||||
|
|
||||||
//
|
|
||||||
// this counts Available Bars ...
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Calculated Bars ...
|
|
||||||
int ichCalculatedBars = BarsCalculated(mHandler);
|
|
||||||
if (ichCalculatedBars < maxLength)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers Copy ...
|
|
||||||
int copiedTenkans = CopyBuffer(mHandler, TENKANSEN_LINE, 0, limit, dTenkanBuffer);
|
|
||||||
int copiedKijuns = CopyBuffer(mHandler, KIJUNSEN_LINE, 0, limit, dKijunBuffer);
|
|
||||||
int copiedChikous = CopyBuffer(mHandler, CHIKOUSPAN_LINE, 0, limit, dChikouBuffer);
|
|
||||||
int copiedSSAs = CopyBuffer(mHandler, SENKOUSPANA_LINE, 0, limit, dSSABuffer);
|
|
||||||
int copiedSSBs = CopyBuffer(mHandler, SENKOUSPANB_LINE, 0, limit, dSSBBuffer);
|
|
||||||
if (
|
|
||||||
copiedSSAs < 0 ||
|
|
||||||
copiedSSBs < 0 ||
|
|
||||||
copiedKijuns < 0 ||
|
|
||||||
copiedTenkans < 0 ||
|
|
||||||
copiedChikous < 0)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main Loop ...
|
|
||||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
|
||||||
{
|
|
||||||
CalculateBuffers(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Functions ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result =
|
|
||||||
//
|
|
||||||
(tenkanSenLength > 2 &&
|
|
||||||
kijunSenLength > tenkanSenLength &&
|
|
||||||
senkouSpanBLength > kijunSenLength)
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve all Exists Input Max Length ...
|
|
||||||
// use for Start Of Drawing ...
|
|
||||||
int ExtractMaxLengthOfInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Ichimoku ...
|
|
||||||
result = MathMax(result, tenkanSenLength);
|
|
||||||
result = MathMax(result, kijunSenLength);
|
|
||||||
result = MathMax(result, senkouSpanBLength);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// ICHIMOKU ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// TENKANSEN ...
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_DRAW_TYPE tenkanSenDrawType = showTenkanSen ? DRAW_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(tenkanSenBuffer, true);
|
|
||||||
SetIndexBuffer(tenkanSenBufferIndex, tenkanSenBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_SHOW_DATA, showTenkanSen);
|
|
||||||
PlotIndexSetInteger(tenkanSenBufferIndex, PLOT_DRAW_TYPE, tenkanSenDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// KIJUNSEN ...
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_DRAW_TYPE kijunSenDrawType = showKijunSen ? DRAW_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(kijunSenBuffer, true);
|
|
||||||
SetIndexBuffer(kijunSenBufferIndex, kijunSenBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_SHOW_DATA, showKijunSen);
|
|
||||||
PlotIndexSetInteger(kijunSenBufferIndex, PLOT_DRAW_TYPE, kijunSenDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// KIJUNSEN Plus ...
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_DRAW_TYPE kijunSenPlusDrawType = showKijunSenPlus ? DRAW_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(kijunSenPlusBuffer, true);
|
|
||||||
SetIndexBuffer(kijunSenPlusBufferIndex, kijunSenPlusBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_SHIFT, kijunSenLength);
|
|
||||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
PlotIndexSetInteger(kijunSenPlusBufferIndex, PLOT_DRAW_TYPE, kijunSenPlusDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// KIJUNSEN Negative ...
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_DRAW_TYPE kijunSenNegativeDrawType = showKijunSenNegative ? DRAW_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(kijunSenNegativeBuffer, true);
|
|
||||||
SetIndexBuffer(kijunSenNegativeBufferIndex, kijunSenNegativeBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_SHIFT, -kijunSenLength);
|
|
||||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
PlotIndexSetInteger(kijunSenNegativeBufferIndex, PLOT_DRAW_TYPE, kijunSenNegativeDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// CHIKOUSPAN ...
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_DRAW_TYPE chikouSpanDrawType = showChikouSpan ? DRAW_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(chikouSpanBuffer, true);
|
|
||||||
SetIndexBuffer(chikouSpanBufferIndex, chikouSpanBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_SHIFT, -kijunSenLength);
|
|
||||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_SHOW_DATA, showChikouSpan);
|
|
||||||
PlotIndexSetInteger(chikouSpanBufferIndex, PLOT_DRAW_TYPE, chikouSpanDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// SENKOUSPAN A and B ...
|
|
||||||
int shiftSize = shiftKumo ? kijunSenLength : 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
// SENKOUSPANA ...
|
|
||||||
ENUM_DRAW_TYPE senkouSpanADrawType = showSenkouSpanA ? DRAW_LINE : DRAW_NONE;
|
|
||||||
ArraySetAsSeries(senkouABuffer, true);
|
|
||||||
SetIndexBuffer(senkouABufferIndex, senkouABuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(senkouABufferIndex, PLOT_SHIFT, shiftSize);
|
|
||||||
PlotIndexSetInteger(senkouABufferIndex, PLOT_SHOW_DATA, showSenkouSpanA);
|
|
||||||
PlotIndexSetInteger(senkouABufferIndex, PLOT_DRAW_TYPE, senkouSpanADrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// SENKOUSPANB ...
|
|
||||||
ENUM_DRAW_TYPE senkouSpanBDrawType = showSenkouSpanB ? DRAW_LINE : DRAW_NONE;
|
|
||||||
ArraySetAsSeries(senkouBBuffer, true);
|
|
||||||
SetIndexBuffer(senkouBBufferIndex, senkouBBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(senkouBBufferIndex, PLOT_SHIFT, shiftSize);
|
|
||||||
PlotIndexSetInteger(senkouBBufferIndex, PLOT_SHOW_DATA, showSenkouSpanB);
|
|
||||||
PlotIndexSetInteger(senkouBBufferIndex, PLOT_DRAW_TYPE, senkouSpanBDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// KUMO ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// SENKOUSPANA ...
|
|
||||||
ArraySetAsSeries(senkouSpanABuffer, true);
|
|
||||||
SetIndexBuffer(senkouSpanABufferIndex, senkouSpanABuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(senkouSpanABufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
|
|
||||||
//
|
|
||||||
// SENKOUSPANB ...
|
|
||||||
ArraySetAsSeries(senkouSpanBBuffer, true);
|
|
||||||
SetIndexBuffer(senkouSpanBBufferIndex, senkouSpanBBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(senkouSpanBBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
|
|
||||||
//
|
|
||||||
// KUMO ...
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_DRAW_TYPE kumoDrawType = showKumo ? DRAW_FILLING : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
PlotIndexSetInteger(kumoBufferIndex, PLOT_SHIFT, shiftSize);
|
|
||||||
PlotIndexSetInteger(kumoBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
PlotIndexSetInteger(kumoBufferIndex, PLOT_DRAW_TYPE, kumoDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// DATA Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// D Tenkan ...
|
|
||||||
ArraySetAsSeries(dTenkanBuffer, true);
|
|
||||||
SetIndexBuffer(dTenkanBufferIndex, dTenkanBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// D Kijun ...
|
|
||||||
ArraySetAsSeries(dKijunBuffer, true);
|
|
||||||
SetIndexBuffer(dKijunBufferIndex, dKijunBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// D Chikou ...
|
|
||||||
ArraySetAsSeries(dChikouBuffer, true);
|
|
||||||
SetIndexBuffer(dChikouBufferIndex, dChikouBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// D SSA ...
|
|
||||||
ArraySetAsSeries(dSSABuffer, true);
|
|
||||||
SetIndexBuffer(dSSABufferIndex, dSSABuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// D SSB ...
|
|
||||||
ArraySetAsSeries(dSSBBuffer, true);
|
|
||||||
SetIndexBuffer(dSSBBufferIndex, dSSBBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Buffers ...
|
|
||||||
void CalculateBuffers(
|
|
||||||
int bar_index // Selected Bar Index
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// ICHIMOKU ...
|
|
||||||
|
|
||||||
//
|
|
||||||
double topValue;
|
|
||||||
double bottomValue;
|
|
||||||
|
|
||||||
//
|
|
||||||
// TENKANSEN ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Extract Tenkan Sen Top/Bottom Calculation Mode based on User Input ...
|
|
||||||
if (mTenkanSenTopMode == NULL || mTenkanSenBottomMode == NULL)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
switch (tenkanSenMode)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
case X_XICH_HH_LL_MODE:
|
|
||||||
//
|
|
||||||
mTenkanSenTopMode = MODE_HIGH;
|
|
||||||
mTenkanSenBottomMode = MODE_LOW;
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
case X_XICH_HO_LC_MODE:
|
|
||||||
//
|
|
||||||
mTenkanSenTopMode = MODE_OPEN;
|
|
||||||
mTenkanSenBottomMode = MODE_CLOSE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
XOHCL bar;
|
|
||||||
bar.Init(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
bar_index
|
|
||||||
//
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Top ...
|
|
||||||
topValue = bar
|
|
||||||
.FindHighest(
|
|
||||||
tenkanSenLength,
|
|
||||||
mTenkanSenTopMode
|
|
||||||
//
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Bottom ...
|
|
||||||
bottomValue = bar
|
|
||||||
.FindLowest(
|
|
||||||
tenkanSenLength,
|
|
||||||
mTenkanSenBottomMode
|
|
||||||
//
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
double tenkanSenValue = (topValue + bottomValue) / 2;
|
|
||||||
tenkanSenBuffer[bar_index] = tenkanSenValue;
|
|
||||||
|
|
||||||
//
|
|
||||||
// KIJUNSEN ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Extract Kijun Sen Top/Bottom Calculation Mode based on User Input ...
|
|
||||||
if (mKijunSenTopMode == NULL || mKijunSenBottomMode == NULL)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
switch (kijunSenMode)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
case X_XICH_HH_LL_MODE:
|
|
||||||
//
|
|
||||||
mKijunSenTopMode = MODE_HIGH;
|
|
||||||
mKijunSenBottomMode = MODE_LOW;
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
case X_XICH_HO_LC_MODE:
|
|
||||||
//
|
|
||||||
mKijunSenTopMode = MODE_OPEN;
|
|
||||||
mKijunSenBottomMode = MODE_CLOSE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Top ...
|
|
||||||
topValue = bar
|
|
||||||
.FindHighest(
|
|
||||||
kijunSenLength,
|
|
||||||
mKijunSenTopMode
|
|
||||||
//
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Bottom ...
|
|
||||||
bottomValue = bar
|
|
||||||
.FindLowest(
|
|
||||||
kijunSenLength,
|
|
||||||
mKijunSenBottomMode
|
|
||||||
//
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
double kijunSenValue = (topValue + bottomValue) / 2;
|
|
||||||
kijunSenBuffer[bar_index] = kijunSenValue;
|
|
||||||
|
|
||||||
//
|
|
||||||
kijunSenPlusBuffer[bar_index] = kijunSenValue;
|
|
||||||
kijunSenNegativeBuffer[bar_index] = kijunSenValue;
|
|
||||||
|
|
||||||
//
|
|
||||||
// CHIKOUSPAN ...
|
|
||||||
double chikouSpanValue = bar
|
|
||||||
.GetPrice(chikuoSpanAppliedTo);
|
|
||||||
|
|
||||||
//
|
|
||||||
chikouSpanBuffer[bar_index] = chikouSpanValue;
|
|
||||||
|
|
||||||
//
|
|
||||||
// KUMO ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// SENKOUSPANA ...
|
|
||||||
double senkouSpanAValue = (tenkanSenValue + kijunSenValue) / 2;
|
|
||||||
senkouABuffer[bar_index] = senkouSpanAValue;
|
|
||||||
senkouSpanABuffer[bar_index] = senkouSpanAValue;
|
|
||||||
|
|
||||||
//
|
|
||||||
// SENKOUSPANB ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Extract Senkou Span B Top/Bottom Calculation Mode based on User Input ...
|
|
||||||
if (mSenkouSpanBTopMode == NULL || mSenkouSpanBBottomMode == NULL)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
switch (senkouSpanBMode)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
case X_XICH_HH_LL_MODE:
|
|
||||||
//
|
|
||||||
mSenkouSpanBTopMode = MODE_HIGH;
|
|
||||||
mSenkouSpanBBottomMode = MODE_LOW;
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
case X_XICH_HO_LC_MODE:
|
|
||||||
//
|
|
||||||
mSenkouSpanBTopMode = MODE_OPEN;
|
|
||||||
mSenkouSpanBBottomMode = MODE_CLOSE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Top ...
|
|
||||||
topValue = bar
|
|
||||||
.FindHighest(
|
|
||||||
senkouSpanBLength,
|
|
||||||
mSenkouSpanBTopMode
|
|
||||||
//
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Bottom ...
|
|
||||||
bottomValue = bar
|
|
||||||
.FindLowest(
|
|
||||||
senkouSpanBLength,
|
|
||||||
mSenkouSpanBBottomMode
|
|
||||||
//
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
double senkouSpanBValue = (topValue + bottomValue) / 2;
|
|
||||||
senkouBBuffer[bar_index] = senkouSpanBValue;
|
|
||||||
senkouSpanBBuffer[bar_index] = senkouSpanBValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Functions ...
|
|
||||||
//
|
|
||||||
@@ -1,483 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 XMC MA Cross Indicator
|
|
||||||
// ---------------------------------------------------
|
|
||||||
// Name: XMC
|
|
||||||
// Description: Moving Average Crosses
|
|
||||||
// Market Analysor ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XMC Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Indicator Short Name ...
|
|
||||||
#define ShortName "XMC"
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Fast";
|
|
||||||
input int fastMaLength = 21; // Length
|
|
||||||
input int fastMaShift = 0; // Shift
|
|
||||||
input ENUM_MA_METHOD fastMaMethod = MODE_EMA; // Method
|
|
||||||
input ENUM_APPLIED_PRICE fastMaAppliedTo = PRICE_CLOSE; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Slow";
|
|
||||||
input int slowMaLength = 50; // Length
|
|
||||||
input int slowMaShift = 0; // Shift
|
|
||||||
input ENUM_MA_METHOD slowMaMethod = MODE_EMA; // Method
|
|
||||||
input ENUM_APPLIED_PRICE slowMaAppliedTo = PRICE_CLOSE; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Verifier";
|
|
||||||
input int verifierMaLength = 200; // Length
|
|
||||||
input int verifierMaShift = 0; // Shift
|
|
||||||
input ENUM_MA_METHOD verifierMaMethod = MODE_EMA; // Method
|
|
||||||
input ENUM_APPLIED_PRICE verifierMaAppliedTo = PRICE_CLOSE; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "PSar";
|
|
||||||
input double sarStep = 0.02; // Step
|
|
||||||
input double sarMaximum = 0.2; // Maximum
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showSar = true; // Show Sar
|
|
||||||
input bool showFastMa = true; // Show Fast
|
|
||||||
input bool showSlowMa = true; // Show Slow
|
|
||||||
input bool showVerifierMa = true; // Show Verifier
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Includes and Imports ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Includes Common Library ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Includes and Imports ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Buffers ...
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 4
|
|
||||||
#property indicator_plots 4
|
|
||||||
|
|
||||||
//
|
|
||||||
// PLOTTED Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// MA ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// FAST ...
|
|
||||||
#define fastMaBufferIndex 0
|
|
||||||
double fastMaBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XMC MA F"
|
|
||||||
#property indicator_type1 DRAW_LINE
|
|
||||||
#property indicator_color1 clrYellow
|
|
||||||
#property indicator_style1 STYLE_SOLID
|
|
||||||
#property indicator_width1 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// SLOW ...
|
|
||||||
#define slowMaBufferIndex 1
|
|
||||||
double slowMaBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label2 "XMC MA S"
|
|
||||||
#property indicator_type2 DRAW_LINE
|
|
||||||
#property indicator_color2 clrDarkOrange
|
|
||||||
#property indicator_style2 STYLE_SOLID
|
|
||||||
#property indicator_width2 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// VERIFIER ...
|
|
||||||
#define verifierMaBufferIndex 2
|
|
||||||
double verifierMaBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label3 "XMC MA V"
|
|
||||||
#property indicator_type3 DRAW_LINE
|
|
||||||
#property indicator_color3 clrDarkBlue
|
|
||||||
#property indicator_style3 STYLE_SOLID
|
|
||||||
#property indicator_width3 2
|
|
||||||
|
|
||||||
//
|
|
||||||
// SAR ...
|
|
||||||
#define sarBufferIndex 3
|
|
||||||
double sarBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label4 "XMC SAR"
|
|
||||||
#property indicator_type4 DRAW_ARROW
|
|
||||||
#property indicator_color4 clrDarkGreen
|
|
||||||
#property indicator_width4 2
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Buffers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
int maxLength;
|
|
||||||
|
|
||||||
//
|
|
||||||
int sarHandler = INVALID_HANDLE;
|
|
||||||
int fastMaHandler = INVALID_HANDLE;
|
|
||||||
int slowMaHandler = INVALID_HANDLE;
|
|
||||||
int verifierMaHandler = INVALID_HANDLE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// because in some cases we may have more than one input for
|
|
||||||
// calculation and we must prevent any calculation
|
|
||||||
// untill we pass the biggest input length, here we get max Input length
|
|
||||||
// and then wait until pass it ...
|
|
||||||
maxLength = ExtractMaxLengthOfInputs();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// SAR Initializer ...
|
|
||||||
sarHandler = iSAR(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
sarStep,
|
|
||||||
sarMaximum //
|
|
||||||
);
|
|
||||||
if (sarHandler == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
return INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// MA Initialization ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// FAST ...
|
|
||||||
fastMaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
fastMaLength,
|
|
||||||
fastMaShift,
|
|
||||||
fastMaMethod,
|
|
||||||
fastMaAppliedTo);
|
|
||||||
if (fastMaHandler == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
return INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// SLOW ...
|
|
||||||
slowMaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
slowMaLength,
|
|
||||||
slowMaShift,
|
|
||||||
slowMaMethod,
|
|
||||||
slowMaAppliedTo);
|
|
||||||
if (slowMaHandler == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
return INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// VERIFIER ...
|
|
||||||
verifierMaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
verifierMaLength,
|
|
||||||
verifierMaShift,
|
|
||||||
verifierMaMethod,
|
|
||||||
verifierMaAppliedTo);
|
|
||||||
if (verifierMaHandler == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
return INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
|
|
||||||
//
|
|
||||||
// Here we can handle De Initialization Reasons ...
|
|
||||||
IndicatorRelease(sarHandler);
|
|
||||||
IndicatorRelease(fastMaHandler);
|
|
||||||
IndicatorRelease(slowMaHandler);
|
|
||||||
IndicatorRelease(verifierMaHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculations ...
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Prepare Buffers ...
|
|
||||||
ArraySetAsSeries(time, true);
|
|
||||||
ArraySetAsSeries(open, true);
|
|
||||||
ArraySetAsSeries(high, true);
|
|
||||||
ArraySetAsSeries(low, true);
|
|
||||||
ArraySetAsSeries(close, true);
|
|
||||||
ArraySetAsSeries(tick_volume, true);
|
|
||||||
ArraySetAsSeries(volume, true);
|
|
||||||
ArraySetAsSeries(spread, true);
|
|
||||||
|
|
||||||
//
|
|
||||||
// this counts Available Bars ...
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Calculated Bars ...
|
|
||||||
int sarCalculatedBars = BarsCalculated(sarHandler);
|
|
||||||
int fastMaCalculatedBars = BarsCalculated(fastMaHandler);
|
|
||||||
int slowMaCalculatedBars = BarsCalculated(slowMaHandler);
|
|
||||||
int verifierMaCalculatedBars = BarsCalculated(verifierMaHandler);
|
|
||||||
if (sarCalculatedBars < maxLength ||
|
|
||||||
fastMaCalculatedBars < maxLength ||
|
|
||||||
slowMaCalculatedBars < maxLength ||
|
|
||||||
verifierMaCalculatedBars < maxLength)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers Copy ...
|
|
||||||
int copiedSars = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer);
|
|
||||||
int copiedFastMas = CopyBuffer(fastMaHandler, 0, 0, limit, fastMaBuffer);
|
|
||||||
int copiedSlowMas = CopyBuffer(slowMaHandler, 0, 0, limit, slowMaBuffer);
|
|
||||||
int copiedVerifierMas = CopyBuffer(verifierMaHandler, 0, 0, limit, verifierMaBuffer);
|
|
||||||
if (copiedSars <= 0 ||
|
|
||||||
copiedFastMas <= 0 ||
|
|
||||||
copiedSlowMas <= 0 ||
|
|
||||||
copiedVerifierMas <= 0)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main Loop ...
|
|
||||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
|
||||||
{
|
|
||||||
CalculateBuffers(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Functions ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result =
|
|
||||||
//
|
|
||||||
// Validate Ma ...
|
|
||||||
(fastMaLength > 2 &&
|
|
||||||
slowMaLength > fastMaLength &&
|
|
||||||
verifierMaLength > slowMaLength)
|
|
||||||
//
|
|
||||||
&&
|
|
||||||
//
|
|
||||||
(sarStep > 0 &&
|
|
||||||
sarMaximum > sarStep)
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve all Exists Input Max Length ...
|
|
||||||
// use for Start Of Drawing ...
|
|
||||||
int ExtractMaxLengthOfInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Ma ...
|
|
||||||
result = MathMax(result, fastMaLength);
|
|
||||||
result = MathMax(result, slowMaLength);
|
|
||||||
result = MathMax(result, verifierMaLength);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// SAR ...
|
|
||||||
ENUM_DRAW_TYPE sarDrawType = showSar ? DRAW_ARROW : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// PEAKS ...
|
|
||||||
ArraySetAsSeries(sarBuffer, true);
|
|
||||||
SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(sarBufferIndex, PLOT_ARROW, 225);
|
|
||||||
PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, 0);
|
|
||||||
|
|
||||||
//
|
|
||||||
PlotIndexSetInteger(sarBufferIndex, PLOT_SHOW_DATA, showSar);
|
|
||||||
PlotIndexSetInteger(sarBufferIndex, PLOT_DRAW_TYPE, sarDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// MA ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// FAST ...
|
|
||||||
ENUM_DRAW_TYPE fastMaDrawType = showFastMa ? DRAW_LINE : DRAW_NONE;
|
|
||||||
ArraySetAsSeries(fastMaBuffer, true);
|
|
||||||
SetIndexBuffer(fastMaBufferIndex, fastMaBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_SHOW_DATA, showFastMa);
|
|
||||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_TYPE, fastMaDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// SLOW ...
|
|
||||||
ENUM_DRAW_TYPE slowMaDrawType = showSlowMa ? DRAW_LINE : DRAW_NONE;
|
|
||||||
ArraySetAsSeries(slowMaBuffer, true);
|
|
||||||
SetIndexBuffer(slowMaBufferIndex, slowMaBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_SHOW_DATA, showSlowMa);
|
|
||||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_TYPE, slowMaDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// VERIFIER ...
|
|
||||||
ENUM_DRAW_TYPE verifierMaDrawType = showVerifierMa ? DRAW_LINE : DRAW_NONE;
|
|
||||||
ArraySetAsSeries(verifierMaBuffer, true);
|
|
||||||
SetIndexBuffer(verifierMaBufferIndex, verifierMaBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_SHOW_DATA, showVerifierMa);
|
|
||||||
PlotIndexSetInteger(verifierMaBufferIndex, PLOT_DRAW_TYPE, verifierMaDrawType);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string indicatorShortName = "";
|
|
||||||
StringConcatenate(indicatorShortName, ShortName, "");
|
|
||||||
|
|
||||||
//
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Buffers ...
|
|
||||||
void CalculateBuffers(
|
|
||||||
int bar_index // Selected Bar Index
|
|
||||||
)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Functions ...
|
|
||||||
//
|
|
||||||
@@ -1,855 +0,0 @@
|
|||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// --------------------------------------
|
|
||||||
// Name: XMRB
|
|
||||||
// Description: Moving Average Ribbon
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XMRB Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Indicator Short Name ...
|
|
||||||
#define ShortName "XMRB"
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Ribbon 1";
|
|
||||||
input int fast1Length = 20; // Fast
|
|
||||||
input int slow1Length = 50; // Slow
|
|
||||||
input ENUM_APPLIED_PRICE r1AppliedTo = PRICE_HIGH; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Ribbon 2";
|
|
||||||
input int fast2Length = 20; // Fast
|
|
||||||
input int slow2Length = 50; // Slow
|
|
||||||
input ENUM_APPLIED_PRICE r2AppliedTo = PRICE_OPEN; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Ribbon 3";
|
|
||||||
input int fast3Length = 20; // Fast
|
|
||||||
input int slow3Length = 50; // Slow
|
|
||||||
input ENUM_APPLIED_PRICE r3AppliedTo = PRICE_CLOSE; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Ribbon 4";
|
|
||||||
input int fast4Length = 20; // Fast
|
|
||||||
input int slow4Length = 50; // Slow
|
|
||||||
input ENUM_APPLIED_PRICE r4AppliedTo = PRICE_MEDIAN; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Ribbon 5";
|
|
||||||
input int fast5Length = 20; // Fast
|
|
||||||
input int slow5Length = 50; // Slow
|
|
||||||
input ENUM_APPLIED_PRICE r5AppliedTo = PRICE_TYPICAL; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Ribbon 6";
|
|
||||||
input int fast6Length = 20; // Fast
|
|
||||||
input int slow6Length = 50; // Slow
|
|
||||||
input ENUM_APPLIED_PRICE r6AppliedTo = PRICE_LOW; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Calculation";
|
|
||||||
input ENUM_MA_METHOD ribbonMode = MODE_EMA; // Mode
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showFastMa = true; // Show Fast
|
|
||||||
input bool showSlowMa = true; // Show Slow
|
|
||||||
input bool showRibbon = false; // Show Ribbon
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Includes and Imports ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Includes Common Library ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Includes and Imports ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Buffers ...
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 14
|
|
||||||
#property indicator_plots 14
|
|
||||||
|
|
||||||
//
|
|
||||||
// PLOTTED Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// MA ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// FAST ...
|
|
||||||
#define fastMaBufferIndex 0
|
|
||||||
double fastMaBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XMRB F"
|
|
||||||
#property indicator_type1 DRAW_LINE
|
|
||||||
#property indicator_color1 clrLime
|
|
||||||
#property indicator_style1 STYLE_SOLID
|
|
||||||
#property indicator_width1 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// SLOW ...
|
|
||||||
#define slowMaBufferIndex 1
|
|
||||||
double slowMaBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label2 "XMRB S"
|
|
||||||
#property indicator_type2 DRAW_LINE
|
|
||||||
#property indicator_color2 clrRed
|
|
||||||
#property indicator_style2 STYLE_SOLID
|
|
||||||
#property indicator_width2 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// DATA Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// FAST ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define fast1BufferIndex 2
|
|
||||||
double fast1Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label3 "XMRB 1 F"
|
|
||||||
#property indicator_type3 DRAW_LINE
|
|
||||||
#property indicator_color3 clrAquamarine
|
|
||||||
#property indicator_style3 STYLE_DOT
|
|
||||||
#property indicator_width3 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define fast2BufferIndex 3
|
|
||||||
double fast2Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label4 "XMRB 2 F"
|
|
||||||
#property indicator_type4 DRAW_LINE
|
|
||||||
#property indicator_color4 clrAquamarine
|
|
||||||
#property indicator_style4 STYLE_DOT
|
|
||||||
#property indicator_width4 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define fast3BufferIndex 4
|
|
||||||
double fast3Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label5 "XMRB 3 F"
|
|
||||||
#property indicator_type5 DRAW_LINE
|
|
||||||
#property indicator_color5 clrAquamarine
|
|
||||||
#property indicator_style5 STYLE_DOT
|
|
||||||
#property indicator_width5 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define fast4BufferIndex 5
|
|
||||||
double fast4Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label6 "XMRB 4 F"
|
|
||||||
#property indicator_type6 DRAW_LINE
|
|
||||||
#property indicator_color6 clrAquamarine
|
|
||||||
#property indicator_style6 STYLE_DOT
|
|
||||||
#property indicator_width6 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define fast5BufferIndex 6
|
|
||||||
double fast5Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label7 "XMRB 5 F"
|
|
||||||
#property indicator_type7 DRAW_LINE
|
|
||||||
#property indicator_color7 clrAquamarine
|
|
||||||
#property indicator_style7 STYLE_DOT
|
|
||||||
#property indicator_width7 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define fast6BufferIndex 7
|
|
||||||
double fast6Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label8 "XMRB 6 F"
|
|
||||||
#property indicator_type8 DRAW_LINE
|
|
||||||
#property indicator_color8 clrAquamarine
|
|
||||||
#property indicator_style8 STYLE_DOT
|
|
||||||
#property indicator_width8 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// SLOW ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define slow1BufferIndex 8
|
|
||||||
double slow1Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label9 "XMRB 1 S"
|
|
||||||
#property indicator_type9 DRAW_LINE
|
|
||||||
#property indicator_color9 clrPlum
|
|
||||||
#property indicator_style9 STYLE_DOT
|
|
||||||
#property indicator_width9 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define slow2BufferIndex 9
|
|
||||||
double slow2Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label10 "XMRB 2 S"
|
|
||||||
#property indicator_type10 DRAW_LINE
|
|
||||||
#property indicator_color10 clrPlum
|
|
||||||
#property indicator_style10 STYLE_DOT
|
|
||||||
#property indicator_width10 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define slow3BufferIndex 10
|
|
||||||
double slow3Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label11 "XMRB 3 S"
|
|
||||||
#property indicator_type11 DRAW_LINE
|
|
||||||
#property indicator_color11 clrPlum
|
|
||||||
#property indicator_style11 STYLE_DOT
|
|
||||||
#property indicator_width11 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define slow4BufferIndex 11
|
|
||||||
double slow4Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label12 "XMRB 4 S"
|
|
||||||
#property indicator_type12 DRAW_LINE
|
|
||||||
#property indicator_color12 clrPlum
|
|
||||||
#property indicator_style12 STYLE_DOT
|
|
||||||
#property indicator_width12 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define slow5BufferIndex 12
|
|
||||||
double slow5Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label13 "XMRB 5 S"
|
|
||||||
#property indicator_type13 DRAW_LINE
|
|
||||||
#property indicator_color13 clrPlum
|
|
||||||
#property indicator_style13 STYLE_DOT
|
|
||||||
#property indicator_width13 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define slow6BufferIndex 13
|
|
||||||
double slow6Buffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label14 "XMRB 6 S"
|
|
||||||
#property indicator_type14 DRAW_LINE
|
|
||||||
#property indicator_color14 clrPlum
|
|
||||||
#property indicator_style14 STYLE_DOT
|
|
||||||
#property indicator_width14 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Buffers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
int maxLength;
|
|
||||||
|
|
||||||
//
|
|
||||||
int fast1MaHandler = INVALID_HANDLE;
|
|
||||||
int fast2MaHandler = INVALID_HANDLE;
|
|
||||||
int fast3MaHandler = INVALID_HANDLE;
|
|
||||||
int fast4MaHandler = INVALID_HANDLE;
|
|
||||||
int fast5MaHandler = INVALID_HANDLE;
|
|
||||||
int fast6MaHandler = INVALID_HANDLE;
|
|
||||||
|
|
||||||
//
|
|
||||||
int slow1MaHandler = INVALID_HANDLE;
|
|
||||||
int slow2MaHandler = INVALID_HANDLE;
|
|
||||||
int slow3MaHandler = INVALID_HANDLE;
|
|
||||||
int slow4MaHandler = INVALID_HANDLE;
|
|
||||||
int slow5MaHandler = INVALID_HANDLE;
|
|
||||||
int slow6MaHandler = INVALID_HANDLE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// because in some cases we may have more than one input for
|
|
||||||
// calculation and we must prevent any calculation
|
|
||||||
// untill we pass the biggest input length, here we get max Input length
|
|
||||||
// and then wait until pass it ...
|
|
||||||
maxLength = ExtractMaxLengthOfInputs();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialize MAs ...
|
|
||||||
if (!InitializeMas())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
|
|
||||||
//
|
|
||||||
// Here we can handle De Initialization Reasons ...
|
|
||||||
|
|
||||||
//
|
|
||||||
IndicatorRelease(fast1MaHandler);
|
|
||||||
IndicatorRelease(fast2MaHandler);
|
|
||||||
IndicatorRelease(fast3MaHandler);
|
|
||||||
IndicatorRelease(fast4MaHandler);
|
|
||||||
IndicatorRelease(fast5MaHandler);
|
|
||||||
IndicatorRelease(fast6MaHandler);
|
|
||||||
|
|
||||||
//
|
|
||||||
IndicatorRelease(slow1MaHandler);
|
|
||||||
IndicatorRelease(slow2MaHandler);
|
|
||||||
IndicatorRelease(slow3MaHandler);
|
|
||||||
IndicatorRelease(slow4MaHandler);
|
|
||||||
IndicatorRelease(slow5MaHandler);
|
|
||||||
IndicatorRelease(slow6MaHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Prepare Buffers ...
|
|
||||||
ArraySetAsSeries(time, true);
|
|
||||||
ArraySetAsSeries(open, true);
|
|
||||||
ArraySetAsSeries(high, true);
|
|
||||||
ArraySetAsSeries(low, true);
|
|
||||||
ArraySetAsSeries(close, true);
|
|
||||||
ArraySetAsSeries(tick_volume, true);
|
|
||||||
ArraySetAsSeries(volume, true);
|
|
||||||
ArraySetAsSeries(spread, true);
|
|
||||||
|
|
||||||
//
|
|
||||||
// this counts Available Bars ...
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Calculated Bars ...
|
|
||||||
//
|
|
||||||
int fast1MaCalculatedBars = BarsCalculated(fast1MaHandler);
|
|
||||||
int fast2MaCalculatedBars = BarsCalculated(fast2MaHandler);
|
|
||||||
int fast3MaCalculatedBars = BarsCalculated(fast3MaHandler);
|
|
||||||
int fast4MaCalculatedBars = BarsCalculated(fast4MaHandler);
|
|
||||||
int fast5MaCalculatedBars = BarsCalculated(fast5MaHandler);
|
|
||||||
int fast6MaCalculatedBars = BarsCalculated(fast6MaHandler);
|
|
||||||
//
|
|
||||||
int slow1MaCalculatedBars = BarsCalculated(slow1MaHandler);
|
|
||||||
int slow2MaCalculatedBars = BarsCalculated(slow2MaHandler);
|
|
||||||
int slow3MaCalculatedBars = BarsCalculated(slow3MaHandler);
|
|
||||||
int slow4MaCalculatedBars = BarsCalculated(slow4MaHandler);
|
|
||||||
int slow5MaCalculatedBars = BarsCalculated(slow5MaHandler);
|
|
||||||
int slow6MaCalculatedBars = BarsCalculated(slow6MaHandler);
|
|
||||||
if (
|
|
||||||
fast1MaCalculatedBars < maxLength ||
|
|
||||||
fast2MaCalculatedBars < maxLength ||
|
|
||||||
fast3MaCalculatedBars < maxLength ||
|
|
||||||
fast4MaCalculatedBars < maxLength ||
|
|
||||||
fast5MaCalculatedBars < maxLength ||
|
|
||||||
fast6MaCalculatedBars < maxLength ||
|
|
||||||
slow1MaCalculatedBars < maxLength ||
|
|
||||||
slow2MaCalculatedBars < maxLength ||
|
|
||||||
slow3MaCalculatedBars < maxLength ||
|
|
||||||
slow4MaCalculatedBars < maxLength ||
|
|
||||||
slow5MaCalculatedBars < maxLength ||
|
|
||||||
slow6MaCalculatedBars < maxLength //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers Copy ...
|
|
||||||
//
|
|
||||||
int copiedFast1Mas = CopyBuffer(fast1MaHandler, 0, 0, limit, fast1Buffer);
|
|
||||||
int copiedFast2Mas = CopyBuffer(fast2MaHandler, 0, 0, limit, fast2Buffer);
|
|
||||||
int copiedFast3Mas = CopyBuffer(fast3MaHandler, 0, 0, limit, fast3Buffer);
|
|
||||||
int copiedFast4Mas = CopyBuffer(fast4MaHandler, 0, 0, limit, fast4Buffer);
|
|
||||||
int copiedFast5Mas = CopyBuffer(fast5MaHandler, 0, 0, limit, fast5Buffer);
|
|
||||||
int copiedFast6Mas = CopyBuffer(fast6MaHandler, 0, 0, limit, fast6Buffer);
|
|
||||||
//
|
|
||||||
int copiedSlow1Mas = CopyBuffer(slow1MaHandler, 0, 0, limit, slow1Buffer);
|
|
||||||
int copiedSlow2Mas = CopyBuffer(slow2MaHandler, 0, 0, limit, slow2Buffer);
|
|
||||||
int copiedSlow3Mas = CopyBuffer(slow3MaHandler, 0, 0, limit, slow3Buffer);
|
|
||||||
int copiedSlow4Mas = CopyBuffer(slow4MaHandler, 0, 0, limit, slow4Buffer);
|
|
||||||
int copiedSlow5Mas = CopyBuffer(slow5MaHandler, 0, 0, limit, slow5Buffer);
|
|
||||||
int copiedSlow6Mas = CopyBuffer(slow6MaHandler, 0, 0, limit, slow6Buffer);
|
|
||||||
if (
|
|
||||||
copiedFast1Mas <= 0 ||
|
|
||||||
copiedFast2Mas <= 0 ||
|
|
||||||
copiedFast3Mas <= 0 ||
|
|
||||||
copiedFast4Mas <= 0 ||
|
|
||||||
copiedFast5Mas <= 0 ||
|
|
||||||
copiedFast6Mas <= 0 ||
|
|
||||||
copiedSlow1Mas <= 0 ||
|
|
||||||
copiedSlow2Mas <= 0 ||
|
|
||||||
copiedSlow3Mas <= 0 ||
|
|
||||||
copiedSlow4Mas <= 0 ||
|
|
||||||
copiedSlow5Mas <= 0 ||
|
|
||||||
copiedSlow6Mas <= 0 //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main Loop ...
|
|
||||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
|
||||||
{
|
|
||||||
CalculateBuffers(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Functions ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result =
|
|
||||||
//
|
|
||||||
(fast1Length > 2 &&
|
|
||||||
fast2Length > 2 &&
|
|
||||||
fast3Length > 2 &&
|
|
||||||
fast4Length > 2 &&
|
|
||||||
fast5Length > 2 &&
|
|
||||||
fast6Length > 2 &&
|
|
||||||
slow1Length > fast1Length &&
|
|
||||||
slow2Length > fast2Length &&
|
|
||||||
slow3Length > fast3Length &&
|
|
||||||
slow4Length > fast4Length &&
|
|
||||||
slow5Length > fast5Length &&
|
|
||||||
slow6Length > fast6Length
|
|
||||||
//
|
|
||||||
)
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve all Exists Input Max Length ...
|
|
||||||
// use for Start Of Drawing ...
|
|
||||||
int ExtractMaxLengthOfInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Ma ...
|
|
||||||
|
|
||||||
//
|
|
||||||
result = MathMax(fast1Length, fast2Length);
|
|
||||||
result = MathMax(result, fast3Length);
|
|
||||||
result = MathMax(result, fast4Length);
|
|
||||||
result = MathMax(result, fast5Length);
|
|
||||||
result = MathMax(result, fast6Length);
|
|
||||||
|
|
||||||
//
|
|
||||||
result = MathMax(result, slow1Length);
|
|
||||||
result = MathMax(result, slow2Length);
|
|
||||||
result = MathMax(result, slow3Length);
|
|
||||||
result = MathMax(result, slow4Length);
|
|
||||||
result = MathMax(result, slow5Length);
|
|
||||||
result = MathMax(result, slow6Length);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialize Ma Handlers ...
|
|
||||||
bool InitializeMas()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
fast1MaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
fast1Length,
|
|
||||||
0,
|
|
||||||
ribbonMode,
|
|
||||||
r1AppliedTo);
|
|
||||||
fast2MaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
fast2Length,
|
|
||||||
0,
|
|
||||||
ribbonMode,
|
|
||||||
r2AppliedTo);
|
|
||||||
fast3MaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
fast3Length,
|
|
||||||
0,
|
|
||||||
ribbonMode,
|
|
||||||
r3AppliedTo);
|
|
||||||
fast4MaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
fast4Length,
|
|
||||||
0,
|
|
||||||
ribbonMode,
|
|
||||||
r4AppliedTo);
|
|
||||||
fast5MaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
fast5Length,
|
|
||||||
0,
|
|
||||||
ribbonMode,
|
|
||||||
r5AppliedTo);
|
|
||||||
fast6MaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
fast6Length,
|
|
||||||
0,
|
|
||||||
ribbonMode,
|
|
||||||
r6AppliedTo);
|
|
||||||
|
|
||||||
//
|
|
||||||
slow1MaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
slow1Length,
|
|
||||||
0,
|
|
||||||
ribbonMode,
|
|
||||||
r1AppliedTo);
|
|
||||||
slow2MaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
slow2Length,
|
|
||||||
0,
|
|
||||||
ribbonMode,
|
|
||||||
r2AppliedTo);
|
|
||||||
slow3MaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
slow3Length,
|
|
||||||
0,
|
|
||||||
ribbonMode,
|
|
||||||
r3AppliedTo);
|
|
||||||
slow4MaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
slow4Length,
|
|
||||||
0,
|
|
||||||
ribbonMode,
|
|
||||||
r4AppliedTo);
|
|
||||||
slow5MaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
slow5Length,
|
|
||||||
0,
|
|
||||||
ribbonMode,
|
|
||||||
r5AppliedTo);
|
|
||||||
slow6MaHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
slow6Length,
|
|
||||||
0,
|
|
||||||
ribbonMode,
|
|
||||||
r6AppliedTo);
|
|
||||||
|
|
||||||
//
|
|
||||||
result =
|
|
||||||
fast1MaHandler != INVALID_HANDLE &&
|
|
||||||
fast2MaHandler != INVALID_HANDLE &&
|
|
||||||
fast3MaHandler != INVALID_HANDLE &&
|
|
||||||
fast4MaHandler != INVALID_HANDLE &&
|
|
||||||
fast5MaHandler != INVALID_HANDLE &&
|
|
||||||
fast6MaHandler != INVALID_HANDLE &&
|
|
||||||
slow1MaHandler != INVALID_HANDLE &&
|
|
||||||
slow2MaHandler != INVALID_HANDLE &&
|
|
||||||
slow3MaHandler != INVALID_HANDLE &&
|
|
||||||
slow4MaHandler != INVALID_HANDLE &&
|
|
||||||
slow5MaHandler != INVALID_HANDLE &&
|
|
||||||
slow6MaHandler != INVALID_HANDLE;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// FAST ...
|
|
||||||
ENUM_DRAW_TYPE fastDrawType = showFastMa ? DRAW_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
ArraySetAsSeries(fastMaBuffer, true);
|
|
||||||
SetIndexBuffer(fastMaBufferIndex, fastMaBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_SHOW_DATA, showFastMa);
|
|
||||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(fastMaBufferIndex, PLOT_DRAW_TYPE, fastDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// SLOW ...
|
|
||||||
ENUM_DRAW_TYPE slowDrawType = showSlowMa ? DRAW_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
ArraySetAsSeries(slowMaBuffer, true);
|
|
||||||
SetIndexBuffer(slowMaBufferIndex, slowMaBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_SHOW_DATA, showSlowMa);
|
|
||||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(slowMaBufferIndex, PLOT_DRAW_TYPE, slowDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// DATA ...
|
|
||||||
ENUM_DRAW_TYPE ribbonDrawType = showRibbon ? DRAW_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(fast1Buffer, true);
|
|
||||||
SetIndexBuffer(fast1BufferIndex, fast1Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(fast1BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
|
||||||
PlotIndexSetInteger(fast1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(fast1BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(fast2Buffer, true);
|
|
||||||
SetIndexBuffer(fast2BufferIndex, fast2Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(fast2BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
|
||||||
PlotIndexSetInteger(fast2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(fast2BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(fast3Buffer, true);
|
|
||||||
SetIndexBuffer(fast3BufferIndex, fast3Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(fast3BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
|
||||||
PlotIndexSetInteger(fast3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(fast3BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(fast4Buffer, true);
|
|
||||||
SetIndexBuffer(fast4BufferIndex, fast4Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(fast4BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
|
||||||
PlotIndexSetInteger(fast4BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(fast4BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(fast5Buffer, true);
|
|
||||||
SetIndexBuffer(fast5BufferIndex, fast5Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(fast5BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
|
||||||
PlotIndexSetInteger(fast5BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(fast5BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(fast6Buffer, true);
|
|
||||||
SetIndexBuffer(fast6BufferIndex, fast6Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(fast6BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
|
||||||
PlotIndexSetInteger(fast6BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(fast6BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(slow1Buffer, true);
|
|
||||||
SetIndexBuffer(slow1BufferIndex, slow1Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(slow1BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
|
||||||
PlotIndexSetInteger(slow1BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(slow1BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(slow2Buffer, true);
|
|
||||||
SetIndexBuffer(slow2BufferIndex, slow2Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(slow2BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
|
||||||
PlotIndexSetInteger(slow2BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(slow2BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(slow3Buffer, true);
|
|
||||||
SetIndexBuffer(slow3BufferIndex, slow3Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(slow3BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
|
||||||
PlotIndexSetInteger(slow3BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(slow3BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(slow4Buffer, true);
|
|
||||||
SetIndexBuffer(slow4BufferIndex, slow4Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(slow4BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
|
||||||
PlotIndexSetInteger(slow4BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(slow4BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(slow5Buffer, true);
|
|
||||||
SetIndexBuffer(slow5BufferIndex, slow5Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(slow5BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
|
||||||
PlotIndexSetInteger(slow5BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(slow5BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArraySetAsSeries(slow6Buffer, true);
|
|
||||||
SetIndexBuffer(slow6BufferIndex, slow6Buffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(slow6BufferIndex, PLOT_SHOW_DATA, showRibbon);
|
|
||||||
PlotIndexSetInteger(slow6BufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(slow6BufferIndex, PLOT_DRAW_TYPE, ribbonDrawType);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Buffers ...
|
|
||||||
void CalculateBuffers(
|
|
||||||
int bar_index // Selected Bar Index
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Retireve Values ...
|
|
||||||
|
|
||||||
//
|
|
||||||
double fast1Value = fast1Buffer[bar_index];
|
|
||||||
double fast2Value = fast2Buffer[bar_index];
|
|
||||||
double fast3Value = fast3Buffer[bar_index];
|
|
||||||
double fast4Value = fast4Buffer[bar_index];
|
|
||||||
double fast5Value = fast5Buffer[bar_index];
|
|
||||||
double fast6Value = fast6Buffer[bar_index];
|
|
||||||
|
|
||||||
//
|
|
||||||
double fasts[] = {
|
|
||||||
fast1Value,
|
|
||||||
fast2Value,
|
|
||||||
fast3Value,
|
|
||||||
fast4Value,
|
|
||||||
fast5Value,
|
|
||||||
fast6Value};
|
|
||||||
|
|
||||||
//
|
|
||||||
double slow1Value = slow1Buffer[bar_index];
|
|
||||||
double slow2Value = slow2Buffer[bar_index];
|
|
||||||
double slow3Value = slow3Buffer[bar_index];
|
|
||||||
double slow4Value = slow4Buffer[bar_index];
|
|
||||||
double slow5Value = slow5Buffer[bar_index];
|
|
||||||
double slow6Value = slow6Buffer[bar_index];
|
|
||||||
|
|
||||||
//
|
|
||||||
double slows[] = {
|
|
||||||
slow1Value,
|
|
||||||
slow2Value,
|
|
||||||
slow3Value,
|
|
||||||
slow4Value,
|
|
||||||
slow5Value,
|
|
||||||
slow6Value};
|
|
||||||
|
|
||||||
//
|
|
||||||
double fastValue = GetAverage(fasts);
|
|
||||||
fastMaBuffer[bar_index] = fastValue;
|
|
||||||
|
|
||||||
//
|
|
||||||
double slowValue = GetAverage(slows);
|
|
||||||
slowMaBuffer[bar_index] = slowValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Functions ...
|
|
||||||
//
|
|
||||||
@@ -1,702 +0,0 @@
|
|||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// ---------------------------------------------
|
|
||||||
// Name: XOSC
|
|
||||||
// Description: provides some oscillator values
|
|
||||||
// as empty Indicator ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm X121_XAMA Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
#define ShortName "XOSC"
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// ATR ...
|
|
||||||
input group "ATR";
|
|
||||||
input int atrLength = 14; // Length
|
|
||||||
|
|
||||||
//
|
|
||||||
// RVI ...
|
|
||||||
// The buffer numbers are the following: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
|
|
||||||
input group "RVI";
|
|
||||||
input int rviLength = 10; // Length
|
|
||||||
|
|
||||||
//
|
|
||||||
// BULLPOWER ...
|
|
||||||
input group "Bulls Power";
|
|
||||||
input int bullpLength = 13; // Length
|
|
||||||
|
|
||||||
//
|
|
||||||
// BEARPOWER ...
|
|
||||||
input group "Bears Power";
|
|
||||||
input int bearpLength = 13; // Length
|
|
||||||
|
|
||||||
//
|
|
||||||
// VOLUME ...
|
|
||||||
input group "Volumes";
|
|
||||||
input ENUM_APPLIED_VOLUME volumeAppliedTo = VOLUME_TICK; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
// RSI ...
|
|
||||||
input group "RSI";
|
|
||||||
input int rsiLength = 14; // Length
|
|
||||||
input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
// CCI ...
|
|
||||||
input group "CCI";
|
|
||||||
input int cciLength = 14; // Length
|
|
||||||
input ENUM_APPLIED_PRICE cciAppliedTo = PRICE_TYPICAL; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
// STDDEV ...
|
|
||||||
input group "Standard Deviation";
|
|
||||||
input int stddevLength = 20; // Length
|
|
||||||
input int stddevShift = 0; // Shift
|
|
||||||
input ENUM_MA_METHOD stddevMethod = MODE_SMA; // Mode
|
|
||||||
input ENUM_APPLIED_PRICE stddevAppliedTo = PRICE_CLOSE; // AppliedTo
|
|
||||||
|
|
||||||
//
|
|
||||||
// MOMENTUM ...
|
|
||||||
input group "Momentum";
|
|
||||||
input int momentumLength = 14; // Length
|
|
||||||
input ENUM_APPLIED_PRICE momentumAppliedTo = PRICE_CLOSE; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
// SAR ...
|
|
||||||
input group "SAR";
|
|
||||||
input double sarStep = 0.02; // Step
|
|
||||||
input double sarMaximum = 0.2; // Maximum
|
|
||||||
|
|
||||||
//
|
|
||||||
// MACD ...
|
|
||||||
// The buffer numbers are the following: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
|
|
||||||
input group "MACD";
|
|
||||||
input int macdFastLength = 12; // Fast Length
|
|
||||||
input int macdSlowLength = 26; // Slow Length
|
|
||||||
input int macdSignaLength = 9; // Signal Length
|
|
||||||
input ENUM_APPLIED_PRICE macdAppliedTo = PRICE_CLOSE; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
// STOCHASTIC ...
|
|
||||||
// The buffer numbers: 0 - MAIN_LINE, 1 - SIGNAL_LINE.
|
|
||||||
input group "Stochastic";
|
|
||||||
input int stochKLength = 5; // K Length
|
|
||||||
input int stochDLength = 3; // D Length
|
|
||||||
input int stochSlowing = 3; // Slowing
|
|
||||||
input ENUM_MA_METHOD stochMaMethod = MODE_SMA; // Ma Method
|
|
||||||
input ENUM_STO_PRICE stochMode = STO_LOWHIGH; // Calculation Mode
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Includes Common Library ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Buffers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 15
|
|
||||||
#property indicator_plots 0
|
|
||||||
|
|
||||||
//
|
|
||||||
// ATR ...
|
|
||||||
#define atrBufferIndex 0
|
|
||||||
double atrBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// RVI ...
|
|
||||||
#define rviMainBufferIndex 1
|
|
||||||
#define rviSignalBufferIndex 2
|
|
||||||
double rviMainBuffer[];
|
|
||||||
double rviSignalBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// BULLPOWER ...
|
|
||||||
#define bullPBufferIndex 3
|
|
||||||
double bullPBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// BEARPOWER ...
|
|
||||||
#define bearPBufferIndex 4
|
|
||||||
double bearPBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// VOLUME ...
|
|
||||||
#define volumeBufferIndex 5
|
|
||||||
double volumeBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// RSI ...
|
|
||||||
#define rsiBufferIndex 6
|
|
||||||
double rsiBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// CCI ...
|
|
||||||
#define cciBufferIndex 7
|
|
||||||
double cciBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// MOMENTUM ...
|
|
||||||
#define momentumBufferIndex 8
|
|
||||||
double momentumBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// SAR ...
|
|
||||||
#define sarBufferIndex 9
|
|
||||||
double sarBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// MACD ...
|
|
||||||
#define macdMainBufferIndex 10
|
|
||||||
#define macdSignalBufferIndex 11
|
|
||||||
double macdMainBuffer[];
|
|
||||||
double macdSignalBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// STOCHASTIC ...
|
|
||||||
#define stochMainBufferIndex 12
|
|
||||||
#define stochSignalBufferIndex 13
|
|
||||||
double stochMainBuffer[];
|
|
||||||
double stochSignalBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// STANDARDDEVIATION ...
|
|
||||||
#define stddevBufferIndex 14
|
|
||||||
double stddevBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Buffers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
int maxLength;
|
|
||||||
|
|
||||||
//
|
|
||||||
int atrHandler = INVALID_HANDLE;
|
|
||||||
int rviHandler = INVALID_HANDLE;
|
|
||||||
int bullPHandler = INVALID_HANDLE;
|
|
||||||
int bearPHandler = INVALID_HANDLE;
|
|
||||||
int volumeHandler = INVALID_HANDLE;
|
|
||||||
int rsiHandler = INVALID_HANDLE;
|
|
||||||
int cciHandler = INVALID_HANDLE;
|
|
||||||
int momentumHandler = INVALID_HANDLE;
|
|
||||||
int sarHandler = INVALID_HANDLE;
|
|
||||||
int macdHandler = INVALID_HANDLE;
|
|
||||||
int stochHandler = INVALID_HANDLE;
|
|
||||||
int stddevHandler = INVALID_HANDLE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// because in some cases we may have more than one input for
|
|
||||||
// calculation and we must prevent any calculation
|
|
||||||
// untill we pass the biggest input length, here we get max Input length
|
|
||||||
// and then wait until pass it ...
|
|
||||||
maxLength = ExtractMaxLengthOfInputs();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initializing Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// ATR ...
|
|
||||||
atrHandler = iATR(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
atrLength);
|
|
||||||
|
|
||||||
//
|
|
||||||
// RVI ...
|
|
||||||
rviHandler = iRVI(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
rviLength);
|
|
||||||
|
|
||||||
//
|
|
||||||
// BULLSPOWER ...
|
|
||||||
bullPHandler = iBullsPower(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
bullpLength);
|
|
||||||
|
|
||||||
//
|
|
||||||
// BEARSPOWER ...
|
|
||||||
bearPHandler = iBearsPower(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
bullpLength);
|
|
||||||
|
|
||||||
//
|
|
||||||
// VOLUMES ...
|
|
||||||
volumeHandler = iVolumes(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
volumeAppliedTo);
|
|
||||||
|
|
||||||
//
|
|
||||||
// RSI ...
|
|
||||||
rsiHandler = iRSI(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
rsiLength,
|
|
||||||
rsiAppliedTo);
|
|
||||||
|
|
||||||
//
|
|
||||||
// CCI ...
|
|
||||||
cciHandler = iCCI(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
cciLength,
|
|
||||||
cciAppliedTo);
|
|
||||||
|
|
||||||
//
|
|
||||||
// MOMENTUM ...
|
|
||||||
momentumHandler = iMomentum(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
momentumLength,
|
|
||||||
momentumAppliedTo);
|
|
||||||
|
|
||||||
//
|
|
||||||
// SAR ...
|
|
||||||
sarHandler = iSAR(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
sarStep,
|
|
||||||
sarMaximum);
|
|
||||||
|
|
||||||
//
|
|
||||||
// MACD ...
|
|
||||||
macdHandler = iMACD(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
macdFastLength,
|
|
||||||
macdSlowLength,
|
|
||||||
macdSignaLength,
|
|
||||||
macdAppliedTo);
|
|
||||||
|
|
||||||
//
|
|
||||||
// STOCHASTIC ...
|
|
||||||
stochHandler = iStochastic(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
stochKLength,
|
|
||||||
stochDLength,
|
|
||||||
stochSlowing,
|
|
||||||
stochMaMethod,
|
|
||||||
stochMode);
|
|
||||||
|
|
||||||
//
|
|
||||||
// STANDARDDEVIATION ...
|
|
||||||
stddevHandler = iStdDev(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
stddevLength,
|
|
||||||
stddevShift,
|
|
||||||
stddevMethod,
|
|
||||||
stddevAppliedTo);
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isAllHandlersInit =
|
|
||||||
//
|
|
||||||
atrHandler != INVALID_HANDLE &&
|
|
||||||
rviHandler != INVALID_HANDLE &&
|
|
||||||
bullPHandler != INVALID_HANDLE &&
|
|
||||||
bearPHandler != INVALID_HANDLE &&
|
|
||||||
volumeHandler != INVALID_HANDLE &&
|
|
||||||
rsiHandler != INVALID_HANDLE &&
|
|
||||||
cciHandler != INVALID_HANDLE &&
|
|
||||||
momentumHandler != INVALID_HANDLE &&
|
|
||||||
sarHandler != INVALID_HANDLE &&
|
|
||||||
macdHandler != INVALID_HANDLE &&
|
|
||||||
stochHandler != INVALID_HANDLE &&
|
|
||||||
stddevHandler != INVALID_HANDLE
|
|
||||||
//
|
|
||||||
;
|
|
||||||
if (!isAllHandlersInit)
|
|
||||||
{
|
|
||||||
return INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
|
|
||||||
//
|
|
||||||
// Here we can handle De Initialization Reasons ...
|
|
||||||
IndicatorRelease(atrHandler);
|
|
||||||
IndicatorRelease(rviHandler);
|
|
||||||
IndicatorRelease(bullPHandler);
|
|
||||||
IndicatorRelease(bearPHandler);
|
|
||||||
IndicatorRelease(volumeHandler);
|
|
||||||
IndicatorRelease(rsiHandler);
|
|
||||||
IndicatorRelease(cciHandler);
|
|
||||||
IndicatorRelease(momentumHandler);
|
|
||||||
IndicatorRelease(sarHandler);
|
|
||||||
IndicatorRelease(macdHandler);
|
|
||||||
IndicatorRelease(stochHandler);
|
|
||||||
IndicatorRelease(stddevHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Prepare Buffers ...
|
|
||||||
ArraySetAsSeries(time, true);
|
|
||||||
ArraySetAsSeries(open, true);
|
|
||||||
ArraySetAsSeries(high, true);
|
|
||||||
ArraySetAsSeries(low, true);
|
|
||||||
ArraySetAsSeries(close, true);
|
|
||||||
ArraySetAsSeries(tick_volume, true);
|
|
||||||
ArraySetAsSeries(volume, true);
|
|
||||||
ArraySetAsSeries(spread, true);
|
|
||||||
|
|
||||||
//
|
|
||||||
// this counts Available Bars ...
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Calculated Bars ...
|
|
||||||
int atrCalculatedBars = BarsCalculated(atrHandler);
|
|
||||||
int rviCalculatedBars = BarsCalculated(rviHandler);
|
|
||||||
int bullPCalculatedBars = BarsCalculated(bullPHandler);
|
|
||||||
int bearPCalculatedBars = BarsCalculated(bearPHandler);
|
|
||||||
int volumeCalculatedBars = BarsCalculated(volumeHandler);
|
|
||||||
int rsiCalculatedBars = BarsCalculated(rsiHandler);
|
|
||||||
int cciCalculatedBars = BarsCalculated(cciHandler);
|
|
||||||
int momentumCalculatedBars = BarsCalculated(momentumHandler);
|
|
||||||
int sarCalculatedBars = BarsCalculated(sarHandler);
|
|
||||||
int macdCalculatedBars = BarsCalculated(macdHandler);
|
|
||||||
int stochCalculatedBars = BarsCalculated(stochHandler);
|
|
||||||
int stddevCalculatedBars = BarsCalculated(stddevHandler);
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isCalculatedBarsPassed =
|
|
||||||
//
|
|
||||||
atrCalculatedBars >= maxLength &&
|
|
||||||
rviCalculatedBars >= maxLength &&
|
|
||||||
bullPCalculatedBars >= maxLength &&
|
|
||||||
bearPCalculatedBars >= maxLength &&
|
|
||||||
volumeCalculatedBars >= maxLength &&
|
|
||||||
rsiCalculatedBars >= maxLength &&
|
|
||||||
cciCalculatedBars >= maxLength &&
|
|
||||||
momentumCalculatedBars >= maxLength &&
|
|
||||||
sarCalculatedBars >= maxLength &&
|
|
||||||
macdCalculatedBars >= maxLength &&
|
|
||||||
stochCalculatedBars >= maxLength &&
|
|
||||||
stddevCalculatedBars >= maxLength
|
|
||||||
//
|
|
||||||
;
|
|
||||||
if (!isCalculatedBarsPassed)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers Copy ...
|
|
||||||
int atrCopiedItems = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer);
|
|
||||||
int rviMainCopiedItems = CopyBuffer(rviHandler, MAIN_LINE, 0, limit, rviMainBuffer);
|
|
||||||
int rviSignalCopiedItems = CopyBuffer(rviHandler, SIGNAL_LINE, 0, limit, rviSignalBuffer);
|
|
||||||
int bullPCopiedItems = CopyBuffer(bullPHandler, 0, 0, limit, bullPBuffer);
|
|
||||||
int bearPCopiedItems = CopyBuffer(bearPHandler, 0, 0, limit, bearPBuffer);
|
|
||||||
int volumeCopiedItems = CopyBuffer(volumeHandler, 0, 0, limit, volumeBuffer);
|
|
||||||
int rsiCopiedItems = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer);
|
|
||||||
int cciCopiedItems = CopyBuffer(cciHandler, 0, 0, limit, cciBuffer);
|
|
||||||
int momentumCopiedItems = CopyBuffer(momentumHandler, 0, 0, limit, momentumBuffer);
|
|
||||||
int sarCopiedItems = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer);
|
|
||||||
int macdMainCopiedItems = CopyBuffer(macdHandler, MAIN_LINE, 0, limit, macdMainBuffer);
|
|
||||||
int macdSignalCopiedItems = CopyBuffer(macdHandler, SIGNAL_LINE, 0, limit, macdSignalBuffer);
|
|
||||||
int stochMainCopiedItems = CopyBuffer(stochHandler, MAIN_LINE, 0, limit, stochMainBuffer);
|
|
||||||
int stocSignalhCopiedItems = CopyBuffer(stochHandler, SIGNAL_LINE, 0, limit, stochSignalBuffer);
|
|
||||||
int stddevCopiedItems = CopyBuffer(stddevHandler, 0, 0, limit, stddevBuffer);
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isCopiedBarsPassed =
|
|
||||||
//
|
|
||||||
atrCopiedItems > 0 &&
|
|
||||||
rviMainCopiedItems > 0 &&
|
|
||||||
rviSignalCopiedItems > 0 &&
|
|
||||||
bullPCopiedItems > 0 &&
|
|
||||||
bearPCopiedItems > 0 &&
|
|
||||||
volumeCopiedItems > 0 &&
|
|
||||||
rsiCopiedItems > 0 &&
|
|
||||||
cciCopiedItems > 0 &&
|
|
||||||
momentumCopiedItems > 0 &&
|
|
||||||
sarCopiedItems > 0 &&
|
|
||||||
macdMainCopiedItems > 0 &&
|
|
||||||
macdSignalCopiedItems > 0 &&
|
|
||||||
stochMainCopiedItems > 0 &&
|
|
||||||
stocSignalhCopiedItems > 0 &&
|
|
||||||
stddevCopiedItems > 0
|
|
||||||
//
|
|
||||||
;
|
|
||||||
if (!isCopiedBarsPassed)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main Loop ...
|
|
||||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Do Buffers Calculation ...
|
|
||||||
// HERE We Do Not anything ...
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Functions ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Args ...
|
|
||||||
result =
|
|
||||||
//
|
|
||||||
atrLength >= 2 &&
|
|
||||||
rviLength >= 2 &&
|
|
||||||
bullpLength >= 2 &&
|
|
||||||
bearpLength >= 2 &&
|
|
||||||
rsiLength >= 2 &&
|
|
||||||
cciLength >= 2 &&
|
|
||||||
momentumLength >= 2 &&
|
|
||||||
sarStep > 0 &&
|
|
||||||
sarStep < sarMaximum &&
|
|
||||||
macdFastLength >= 2 &&
|
|
||||||
macdSlowLength > macdFastLength &&
|
|
||||||
macdSignaLength >= 2 &&
|
|
||||||
stochKLength >= 2 &&
|
|
||||||
stochDLength >= 2 &&
|
|
||||||
stochSlowing >= 2 &&
|
|
||||||
stddevLength >= 2 &&
|
|
||||||
stddevShift >= 0
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve all Exists Input Max Length ...
|
|
||||||
// use for Start Of Drawing ...
|
|
||||||
int ExtractMaxLengthOfInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = MathMax(atrLength, rviLength);
|
|
||||||
result = MathMax(result, bullpLength);
|
|
||||||
result = MathMax(result, bearpLength);
|
|
||||||
result = MathMax(result, rsiLength);
|
|
||||||
result = MathMax(result, cciLength);
|
|
||||||
result = MathMax(result, momentumLength);
|
|
||||||
result = MathMax(result, macdFastLength);
|
|
||||||
result = MathMax(result, macdSlowLength);
|
|
||||||
result = MathMax(result, macdSignaLength);
|
|
||||||
result = MathMax(result, stochKLength);
|
|
||||||
result = MathMax(result, stochDLength);
|
|
||||||
result = MathMax(result, stochSlowing);
|
|
||||||
result = MathMax(result, stddevLength);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// DATA Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// ATR ...
|
|
||||||
ArraySetAsSeries(atrBuffer, true);
|
|
||||||
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// RVI ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main ...
|
|
||||||
ArraySetAsSeries(rviMainBuffer, true);
|
|
||||||
SetIndexBuffer(rviMainBufferIndex, rviMainBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Signal ...
|
|
||||||
ArraySetAsSeries(rviSignalBuffer, true);
|
|
||||||
SetIndexBuffer(rviSignalBufferIndex, rviSignalBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// BULLPOWER ...
|
|
||||||
ArraySetAsSeries(bullPBuffer, true);
|
|
||||||
SetIndexBuffer(bullPBufferIndex, bullPBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// BEARPOWER ...
|
|
||||||
ArraySetAsSeries(bearPBuffer, true);
|
|
||||||
SetIndexBuffer(bearPBufferIndex, bearPBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// VOLUME ...
|
|
||||||
ArraySetAsSeries(volumeBuffer, true);
|
|
||||||
SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// RSI ...
|
|
||||||
ArraySetAsSeries(rsiBuffer, true);
|
|
||||||
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// CCI ...
|
|
||||||
ArraySetAsSeries(cciBuffer, true);
|
|
||||||
SetIndexBuffer(cciBufferIndex, cciBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// MOMENTUM ...
|
|
||||||
ArraySetAsSeries(momentumBuffer, true);
|
|
||||||
SetIndexBuffer(momentumBufferIndex, momentumBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// SAR ...
|
|
||||||
ArraySetAsSeries(sarBuffer, true);
|
|
||||||
SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// STANDARDDEVIATION ...
|
|
||||||
ArraySetAsSeries(stddevBuffer, true);
|
|
||||||
SetIndexBuffer(stddevBufferIndex, stddevBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// MACD ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main ...
|
|
||||||
ArraySetAsSeries(macdMainBuffer, true);
|
|
||||||
SetIndexBuffer(macdMainBufferIndex, macdMainBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Signal ...
|
|
||||||
ArraySetAsSeries(macdSignalBuffer, true);
|
|
||||||
SetIndexBuffer(macdSignalBufferIndex, macdSignalBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Functions ...
|
|
||||||
//
|
|
||||||
@@ -1,542 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// -------------------------------------------
|
|
||||||
// Name: XRL
|
|
||||||
// Description: Regression Line ...
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XRL Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
#define ShortName "XRL"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Imports ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Inputs ...
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Market";
|
|
||||||
input group "Fast";
|
|
||||||
input int fastLength = 9; // Length
|
|
||||||
input ENUM_APPLIED_PRICE fastAppliedTo = PRICE_CLOSE; // Applied To
|
|
||||||
input group "Slow";
|
|
||||||
input int slowLength = 18; // Length
|
|
||||||
input ENUM_APPLIED_PRICE slowAppliedTo = PRICE_CLOSE; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showFast = true; // Show Fast
|
|
||||||
input bool showSlow = true; // Show Slow
|
|
||||||
input bool showVerifier = true; // Show Verifier
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 11
|
|
||||||
#property indicator_plots 6
|
|
||||||
|
|
||||||
//
|
|
||||||
#define hideColorIDX 0
|
|
||||||
#define neuturalColorIDX 1
|
|
||||||
#define bullColorIDX 2
|
|
||||||
#define bearColorIDX 3
|
|
||||||
|
|
||||||
//
|
|
||||||
// Fast ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define fastBufferIndex 0
|
|
||||||
#define fastBufferPlotIndex 0
|
|
||||||
double fastBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define fastBufferColorIndex 1
|
|
||||||
double fastBufferColor[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XRL F"
|
|
||||||
#property indicator_type1 DRAW_COLOR_LINE
|
|
||||||
#property indicator_color1 CLR_NONE, clrGray, clrAqua, clrMagenta
|
|
||||||
#property indicator_style1 STYLE_DOT
|
|
||||||
#property indicator_width1 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// Slow ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define slowBufferIndex 2
|
|
||||||
#define slowBufferPlotIndex 1
|
|
||||||
double slowBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define slowBufferColorIndex 3
|
|
||||||
double slowBufferColor[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label2 "XRL S"
|
|
||||||
#property indicator_type2 DRAW_COLOR_LINE
|
|
||||||
#property indicator_color2 CLR_NONE, clrGray, clrAqua, clrMagenta
|
|
||||||
#property indicator_style2 STYLE_DOT
|
|
||||||
#property indicator_width2 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// Verifier ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define verifierBufferIndex 4
|
|
||||||
#define verifierBufferPlotIndex 2
|
|
||||||
double verifierBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define verifierBufferColorIndex 5
|
|
||||||
double verifierBufferColor[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label3 "XRL V"
|
|
||||||
#property indicator_type3 DRAW_COLOR_LINE
|
|
||||||
#property indicator_color3 CLR_NONE, clrGray, clrAqua, clrMagenta
|
|
||||||
#property indicator_style3 STYLE_DOT
|
|
||||||
#property indicator_width3 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define fastLRBufferIndex 6
|
|
||||||
double fastLRBuffer[];
|
|
||||||
|
|
||||||
#define slowLRBufferIndex 7
|
|
||||||
double slowLRBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define fastStateBufferIndex 8
|
|
||||||
double fastStateBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define slowStateBufferIndex 9
|
|
||||||
double slowStateBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define verifierStateBufferIndex 10
|
|
||||||
double verifierStateBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// Variables ...
|
|
||||||
|
|
||||||
//
|
|
||||||
int maxLength = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
XLinearRegression fastCalculator;
|
|
||||||
XLinearRegression slowCalculator;
|
|
||||||
XLinearRegression verifierCalculator;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Event Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// because in some cases we may have more than one input for
|
|
||||||
// calculation and we must prevent any calculation
|
|
||||||
// untill we pass the biggest input length, here we get max Input length
|
|
||||||
// and then wait until pass it ...
|
|
||||||
maxLength = ExtractMaxLengthOfInputs();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int limit = (prev_calculated > 0) ? prev_calculated - 1 : 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Fast ...
|
|
||||||
CalculateFast(
|
|
||||||
open,
|
|
||||||
high,
|
|
||||||
low,
|
|
||||||
close,
|
|
||||||
limit,
|
|
||||||
rates_total //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Slow ...
|
|
||||||
CalculateSlow(
|
|
||||||
open,
|
|
||||||
high,
|
|
||||||
low,
|
|
||||||
close,
|
|
||||||
limit,
|
|
||||||
rates_total //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Verifier ...
|
|
||||||
CalculateVerifier(
|
|
||||||
open,
|
|
||||||
high,
|
|
||||||
low,
|
|
||||||
close,
|
|
||||||
limit,
|
|
||||||
rates_total //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Custom Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = fastLength >= 2 &&
|
|
||||||
slowLength > fastLength;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve all Exists Input Max Length ...
|
|
||||||
// use for Start Of Drawing ...
|
|
||||||
int ExtractMaxLengthOfInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Ichimoku ...
|
|
||||||
result = MathMax(fastLength, slowLength);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Fast ...
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_DRAW_TYPE fastDrawType = showFast ? DRAW_COLOR_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
SetIndexBuffer(fastBufferIndex, fastBuffer, INDICATOR_DATA);
|
|
||||||
SetIndexBuffer(fastBufferColorIndex, fastBufferColor, INDICATOR_COLOR_INDEX);
|
|
||||||
|
|
||||||
//
|
|
||||||
PlotIndexSetDouble(fastBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
||||||
PlotIndexSetInteger(fastBufferPlotIndex, PLOT_SHOW_DATA, showFast);
|
|
||||||
PlotIndexSetInteger(fastBufferPlotIndex, PLOT_DRAW_TYPE, fastDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Slow ...
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_DRAW_TYPE slowDrawType = showSlow ? DRAW_COLOR_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
SetIndexBuffer(slowBufferIndex, slowBuffer, INDICATOR_DATA);
|
|
||||||
SetIndexBuffer(slowBufferColorIndex, slowBufferColor, INDICATOR_COLOR_INDEX);
|
|
||||||
|
|
||||||
//
|
|
||||||
PlotIndexSetDouble(slowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
||||||
PlotIndexSetInteger(slowBufferPlotIndex, PLOT_SHOW_DATA, showSlow);
|
|
||||||
PlotIndexSetInteger(slowBufferPlotIndex, PLOT_DRAW_TYPE, slowDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Verifier ...
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_DRAW_TYPE verifierDrawType = showVerifier ? DRAW_COLOR_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
//
|
|
||||||
SetIndexBuffer(verifierBufferIndex, verifierBuffer, INDICATOR_DATA);
|
|
||||||
SetIndexBuffer(verifierBufferColorIndex, verifierBufferColor, INDICATOR_COLOR_INDEX);
|
|
||||||
|
|
||||||
//
|
|
||||||
PlotIndexSetDouble(verifierBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
||||||
PlotIndexSetInteger(verifierBufferPlotIndex, PLOT_SHOW_DATA, showVerifier);
|
|
||||||
PlotIndexSetInteger(verifierBufferPlotIndex, PLOT_DRAW_TYPE, verifierDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Data Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
SetIndexBuffer(fastLRBufferIndex, fastLRBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
SetIndexBuffer(slowLRBufferIndex, slowLRBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
SetIndexBuffer(fastStateBufferIndex, fastStateBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
SetIndexBuffer(slowStateBufferIndex, slowStateBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
SetIndexBuffer(verifierStateBufferIndex, verifierStateBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Custom Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
void CalculateFast(
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
int limit,
|
|
||||||
const int rates_total //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Fast ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Fast Intercept and Slope ...
|
|
||||||
double fastSlope = 0;
|
|
||||||
double fastIntercept = 0;
|
|
||||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double fastAppliedPrice = iGetPrice(fastAppliedTo, open[i], high[i], low[i], close[i]);
|
|
||||||
|
|
||||||
//
|
|
||||||
double fastLRValue = fastCalculator.Calculate(
|
|
||||||
fastAppliedPrice,
|
|
||||||
fastLength,
|
|
||||||
fastSlope,
|
|
||||||
fastIntercept,
|
|
||||||
i,
|
|
||||||
rates_total //
|
|
||||||
);
|
|
||||||
fastLRBuffer[i] = fastLRValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Fast ...
|
|
||||||
for (int i = 0; i < fastLength && !IsStopped(); i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double fast = fastIntercept + fastSlope * (fastLength - i - 1);
|
|
||||||
fastBuffer[rates_total - i - 1] = fast;
|
|
||||||
|
|
||||||
//
|
|
||||||
double fastColor =
|
|
||||||
(fastSlope > 0)
|
|
||||||
? bullColorIDX
|
|
||||||
: (fastSlope < 0)
|
|
||||||
? bearColorIDX
|
|
||||||
: neuturalColorIDX;
|
|
||||||
double fastState = (fastSlope > 0)
|
|
||||||
? 1
|
|
||||||
: -1;
|
|
||||||
|
|
||||||
//
|
|
||||||
fastBufferColor[rates_total - i - 1] = fastColor;
|
|
||||||
fastStateBuffer[rates_total - i - 1] = fastState;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int fastDrawBegin = rates_total - fastLength;
|
|
||||||
PlotIndexSetInteger(fastBufferPlotIndex, PLOT_DRAW_BEGIN, fastDrawBegin);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
void CalculateSlow(
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
int limit,
|
|
||||||
const int rates_total //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Slow ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Slow Intercept and Slope ...
|
|
||||||
double slowSlope = 0;
|
|
||||||
double slowIntercept = 0;
|
|
||||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double slowAppliedPrice = iGetPrice(slowAppliedTo, open[i], high[i], low[i], close[i]);
|
|
||||||
|
|
||||||
//
|
|
||||||
double slowLRValue = slowCalculator.Calculate(
|
|
||||||
slowAppliedPrice,
|
|
||||||
slowLength,
|
|
||||||
slowSlope,
|
|
||||||
slowIntercept,
|
|
||||||
i,
|
|
||||||
rates_total //
|
|
||||||
);
|
|
||||||
slowLRBuffer[i] = slowLRValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Slow ...
|
|
||||||
for (int i = 0; i < slowLength && !IsStopped(); i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double slow = slowIntercept + slowSlope * (slowLength - i - 1);
|
|
||||||
slowBuffer[rates_total - i - 1] = slow;
|
|
||||||
|
|
||||||
//
|
|
||||||
double slowColor =
|
|
||||||
(slowSlope > 0)
|
|
||||||
? bullColorIDX
|
|
||||||
: (slowSlope < 0)
|
|
||||||
? bearColorIDX
|
|
||||||
: neuturalColorIDX;
|
|
||||||
double slowState = (slowSlope > 0)
|
|
||||||
? 1
|
|
||||||
: -1;
|
|
||||||
|
|
||||||
//
|
|
||||||
slowBufferColor[rates_total - i - 1] = slowColor;
|
|
||||||
slowStateBuffer[rates_total - i - 1] = slowState;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int slowDrawBegin = rates_total - slowLength;
|
|
||||||
PlotIndexSetInteger(slowBufferPlotIndex, PLOT_DRAW_BEGIN, slowDrawBegin);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
void CalculateVerifier(
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
int limit,
|
|
||||||
const int rates_total //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Calculate Verifier ...
|
|
||||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double verifierSlope;
|
|
||||||
double verifierIntercept;
|
|
||||||
|
|
||||||
//
|
|
||||||
double verifierAppliedPrice = iGetPrice(slowAppliedTo, open[i], high[i], low[i], close[i]);
|
|
||||||
|
|
||||||
//
|
|
||||||
double verifier = verifierCalculator.Calculate(
|
|
||||||
verifierAppliedPrice,
|
|
||||||
slowLength,
|
|
||||||
verifierSlope,
|
|
||||||
verifierIntercept,
|
|
||||||
i,
|
|
||||||
rates_total //
|
|
||||||
);
|
|
||||||
verifierBuffer[i] = verifier;
|
|
||||||
|
|
||||||
//
|
|
||||||
double verifierColor =
|
|
||||||
(i > 0)
|
|
||||||
? (verifierBuffer[i] > verifierBuffer[i - 1])
|
|
||||||
? bullColorIDX
|
|
||||||
: (verifierBuffer[i] < verifierBuffer[i - 1])
|
|
||||||
? bearColorIDX
|
|
||||||
: verifierBufferColor[i - 1]
|
|
||||||
: neuturalColorIDX;
|
|
||||||
double verifierState =
|
|
||||||
(i > 0)
|
|
||||||
? (verifierBuffer[i] > verifierBuffer[i - 1])
|
|
||||||
? 1
|
|
||||||
: (verifierBuffer[i] < verifierBuffer[i - 1])
|
|
||||||
? -1
|
|
||||||
: verifierStateBuffer[i - 1]
|
|
||||||
: -1;
|
|
||||||
|
|
||||||
//
|
|
||||||
verifierBufferColor[i] = verifierColor;
|
|
||||||
verifierStateBuffer[i] = verifierState;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
@@ -1,279 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// -------------------------------------------
|
|
||||||
// Name: XSLN
|
|
||||||
// Description: HULL Trend Detector ...
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XSLN Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
#define ShortName "XSLN"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Imports ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Inputs ...
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool show = true; // Show
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 3
|
|
||||||
#property indicator_plots 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#define mainBufferIndex 0
|
|
||||||
double mainBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define mainBufferColorIndex 1
|
|
||||||
double mainBufferColor[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define stateBufferIndex 2
|
|
||||||
double stateBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define hideColorIDX 0
|
|
||||||
#define bullColorIDX 1
|
|
||||||
#define bearColorIDX 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XSLN"
|
|
||||||
#property indicator_type1 DRAW_COLOR_LINE
|
|
||||||
#property indicator_color1 CLR_NONE, clrGreen, clrDarkRed
|
|
||||||
#property indicator_style1 STYLE_DOT
|
|
||||||
#property indicator_width1 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// Variables ...
|
|
||||||
|
|
||||||
//
|
|
||||||
double work[][5];
|
|
||||||
#define hHi 0
|
|
||||||
#define hLo 1
|
|
||||||
#define lHi 2
|
|
||||||
#define lLo 3
|
|
||||||
#define trend 4
|
|
||||||
|
|
||||||
//
|
|
||||||
// Event Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (ArrayRange(work, 0) != rates_total)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
ArrayResize(work, rates_total);
|
|
||||||
ArrayResize(stateBuffer, 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;
|
|
||||||
stateBuffer[i] = -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)
|
|
||||||
{
|
|
||||||
mainBuffer[i] = work[i][hLo];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mainBuffer[i] = work[i][lHi];
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
stateBuffer[i] = stateBuffer[i - 1];
|
|
||||||
mainBufferColor[i] = mainBufferColor[i - 1];
|
|
||||||
|
|
||||||
//
|
|
||||||
if (work[i][trend] == 1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
stateBuffer[i] = 1;
|
|
||||||
mainBufferColor[i] = bullColorIDX;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (work[i][trend] == -1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
stateBuffer[i] = -1;
|
|
||||||
mainBufferColor[i] = bearColorIDX;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Custom Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = true;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Main ...
|
|
||||||
ENUM_DRAW_TYPE mainDrawType = show ? DRAW_COLOR_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
PlotIndexSetInteger(mainBufferIndex, PLOT_SHOW_DATA, true);
|
|
||||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(mainBufferIndex, PLOT_DRAW_TYPE, mainDrawType);
|
|
||||||
SetIndexBuffer(mainBufferColorIndex, mainBufferColor, INDICATOR_COLOR_INDEX);
|
|
||||||
|
|
||||||
//
|
|
||||||
SetIndexBuffer(stateBufferIndex, stateBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
@@ -1,421 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// ----------------------------------------------------
|
|
||||||
// Name: XSSLC
|
|
||||||
// Description: SSL Channel Indicator
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XSSLC Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Indicator Short Name ...
|
|
||||||
#define ShortName "XSSLC"
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Market";
|
|
||||||
input int length = 36; // Length
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Calculation";
|
|
||||||
input ENUM_MA_METHOD method = MODE_SMA; // Method
|
|
||||||
input ENUM_APPLIED_PRICE upAppliedTo = PRICE_HIGH; // Up Applied To
|
|
||||||
input ENUM_APPLIED_PRICE downAppliedTo = PRICE_LOW; // Down Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showUp = true; // Show Up
|
|
||||||
input bool showDown = true; // Show Down
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Includes and Imports ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Includes Common Library ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Includes and Imports ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Buffers ...
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 5
|
|
||||||
#property indicator_plots 2
|
|
||||||
|
|
||||||
//
|
|
||||||
// PLOTTED Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define upBufferIndex 0
|
|
||||||
double upBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XSSLC Up"
|
|
||||||
#property indicator_type1 DRAW_LINE
|
|
||||||
#property indicator_color1 clrLime
|
|
||||||
#property indicator_style1 STYLE_SOLID
|
|
||||||
#property indicator_width1 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define downBufferIndex 1
|
|
||||||
double downBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label2 "XSSLC Down"
|
|
||||||
#property indicator_type2 DRAW_LINE
|
|
||||||
#property indicator_color2 clrRed
|
|
||||||
#property indicator_style2 STYLE_SOLID
|
|
||||||
#property indicator_width2 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// DATA Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define upMaBufferIndex 2
|
|
||||||
double upMaBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define downMaBufferIndex 3
|
|
||||||
double downMaBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define kpiBufferIndex 4
|
|
||||||
double kpiBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Buffers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
int maxLength;
|
|
||||||
|
|
||||||
//
|
|
||||||
int upHandler = INVALID_HANDLE;
|
|
||||||
int downHandler = INVALID_HANDLE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// because in some cases we may have more than one input for
|
|
||||||
// calculation and we must prevent any calculation
|
|
||||||
// untill we pass the biggest input length, here we get max Input length
|
|
||||||
// and then wait until pass it ...
|
|
||||||
maxLength = ExtractMaxLengthOfInputs();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialize Requierd Handlers ...
|
|
||||||
upHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
length,
|
|
||||||
0,
|
|
||||||
method,
|
|
||||||
upAppliedTo);
|
|
||||||
downHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
length,
|
|
||||||
0,
|
|
||||||
method,
|
|
||||||
downAppliedTo);
|
|
||||||
if (upHandler == INVALID_HANDLE || downHandler == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string msg = "Error in Initilizing Indicator ...";
|
|
||||||
Print(msg);
|
|
||||||
|
|
||||||
//
|
|
||||||
return INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
|
|
||||||
//
|
|
||||||
// Release Indicators ...
|
|
||||||
IndicatorRelease(upHandler);
|
|
||||||
IndicatorRelease(downHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Prepare Buffers ...
|
|
||||||
ArraySetAsSeries(time, true);
|
|
||||||
ArraySetAsSeries(open, true);
|
|
||||||
ArraySetAsSeries(high, true);
|
|
||||||
ArraySetAsSeries(low, true);
|
|
||||||
ArraySetAsSeries(close, true);
|
|
||||||
ArraySetAsSeries(tick_volume, true);
|
|
||||||
ArraySetAsSeries(volume, true);
|
|
||||||
ArraySetAsSeries(spread, true);
|
|
||||||
|
|
||||||
//
|
|
||||||
// this counts Available Bars ...
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Calculated Bars ...
|
|
||||||
int upCalculatedBars = BarsCalculated(upHandler);
|
|
||||||
int downCalculatedBars = BarsCalculated(downHandler);
|
|
||||||
if (upCalculatedBars < maxLength ||
|
|
||||||
downCalculatedBars < maxLength)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers Copy ...
|
|
||||||
int copiedUps = CopyBuffer(upHandler, 0, 0, limit, upMaBuffer);
|
|
||||||
int copiedDowns = CopyBuffer(downHandler, 0, 0, limit, downMaBuffer);
|
|
||||||
if (copiedUps <= 0 ||
|
|
||||||
copiedDowns <= 0)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main Loop ...
|
|
||||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
|
||||||
{
|
|
||||||
CalculateBuffers(i, limit, rates_total, prev_calculated, close);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Functions ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result =
|
|
||||||
//
|
|
||||||
(length > 2)
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve all Exists Input Max Length ...
|
|
||||||
// use for Start Of Drawing ...
|
|
||||||
int ExtractMaxLengthOfInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = MathMax(result, length);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// UP ...
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_DRAW_TYPE upDrawType = showUp ? DRAW_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
ArraySetAsSeries(upBuffer, true);
|
|
||||||
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(upBufferIndex, PLOT_SHOW_DATA, showUp);
|
|
||||||
PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_TYPE, upDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// DOWN ...
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_DRAW_TYPE downDrawType = showDown ? DRAW_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
ArraySetAsSeries(downBuffer, true);
|
|
||||||
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(downBufferIndex, PLOT_SHOW_DATA, showDown);
|
|
||||||
PlotIndexSetInteger(downBufferIndex, PLOT_DRAW_BEGIN, maxLength);
|
|
||||||
PlotIndexSetInteger(downBufferIndex, PLOT_DRAW_TYPE, downDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// DATA Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// UP MA ...
|
|
||||||
ArraySetAsSeries(upMaBuffer, true);
|
|
||||||
SetIndexBuffer(upMaBufferIndex, upMaBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// DOWN MA ...
|
|
||||||
ArraySetAsSeries(downMaBuffer, true);
|
|
||||||
SetIndexBuffer(downMaBufferIndex, downMaBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// KPI ...
|
|
||||||
ArraySetAsSeries(kpiBuffer, true);
|
|
||||||
SetIndexBuffer(kpiBufferIndex, kpiBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Buffers ...
|
|
||||||
void CalculateBuffers(
|
|
||||||
int bar_index, // Selected Bar Index
|
|
||||||
int limit,
|
|
||||||
int ratesTotal,
|
|
||||||
int prevCalculated,
|
|
||||||
const double &close[])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double upMaValue = upMaBuffer[bar_index];
|
|
||||||
double downMaValue = downMaBuffer[bar_index];
|
|
||||||
|
|
||||||
//
|
|
||||||
double closeValue = close[bar_index];
|
|
||||||
|
|
||||||
//
|
|
||||||
double kpiValue;
|
|
||||||
if (closeValue > upMaValue)
|
|
||||||
{
|
|
||||||
kpiValue = 1;
|
|
||||||
}
|
|
||||||
else if (closeValue < downMaValue)
|
|
||||||
{
|
|
||||||
kpiValue = -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
kpiValue = kpiBuffer[bar_index + 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
kpiBuffer[bar_index] = kpiValue;
|
|
||||||
|
|
||||||
//
|
|
||||||
double upValue = kpiValue < 0 ? downMaValue : upMaValue;
|
|
||||||
upBuffer[bar_index] = upValue;
|
|
||||||
|
|
||||||
//
|
|
||||||
double downValue = kpiValue < 0 ? upMaValue : downMaValue;
|
|
||||||
downBuffer[bar_index] = downValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Functions ...
|
|
||||||
//
|
|
||||||
@@ -1,561 +0,0 @@
|
|||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// ---------------------------------------------
|
|
||||||
// Name: XSTR
|
|
||||||
// Description: Super Trend Indicator ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm X121_XAMA Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
#define ShortName "XSTR"
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Market ...
|
|
||||||
input group "ATR";
|
|
||||||
input int atrLength = 14; // Length
|
|
||||||
input double atrMultiplier = 3.0; // Multiplier
|
|
||||||
input ENUM_APPLIED_PRICE atrAppliedTo = PRICE_MEDIAN; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
// Presentation ...
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showTrends = true; // Show Trends
|
|
||||||
input bool fillTrends = true; // Fill Trends
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Includes Common Library ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Buffers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 9
|
|
||||||
#property indicator_plots 2
|
|
||||||
|
|
||||||
//
|
|
||||||
#define fillUpBufferIndex 0
|
|
||||||
double fillUpBuffer[];
|
|
||||||
|
|
||||||
#define fillDownBufferIndex 1
|
|
||||||
double fillDownBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define fillingPlotBufferIndex 0
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XSTR Filling"
|
|
||||||
#property indicator_type1 DRAW_FILLING
|
|
||||||
#property indicator_color1 clrBisque, clrPaleGreen
|
|
||||||
|
|
||||||
//
|
|
||||||
#define mainBufferIndex 2
|
|
||||||
#define mainPlotBufferIndex 1
|
|
||||||
double mainBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define mainColorBufferIndex 3
|
|
||||||
double mainColorBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label2 "XSTR"
|
|
||||||
#property indicator_type2 DRAW_COLOR_LINE
|
|
||||||
#property indicator_color2 CLR_NONE, clrGreen, clrDarkRed
|
|
||||||
#property indicator_style2 STYLE_DOT
|
|
||||||
|
|
||||||
//
|
|
||||||
// DATA Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define atrBufferIndex 4
|
|
||||||
double atrBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define trendBufferIndex 5
|
|
||||||
double trendBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define upBufferIndex 6
|
|
||||||
double upBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define downBufferIndex 7
|
|
||||||
double downBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define priceBufferIndex 8
|
|
||||||
double priceBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Buffers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
int maxLength;
|
|
||||||
|
|
||||||
//
|
|
||||||
int atrHandler = INVALID_HANDLE;
|
|
||||||
|
|
||||||
//
|
|
||||||
int changeOfTrend;
|
|
||||||
int startBearishTrend;
|
|
||||||
int startBullishTrend;
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// because in some cases we may have more than one input for
|
|
||||||
// calculation and we must prevent any calculation
|
|
||||||
// untill we pass the biggest input length, here we get max Input length
|
|
||||||
// and then wait until pass it ...
|
|
||||||
maxLength = ExtractMaxLengthOfInputs();
|
|
||||||
|
|
||||||
//
|
|
||||||
atrHandler = iATR(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
atrLength);
|
|
||||||
if (atrHandler == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
return INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
|
|
||||||
//
|
|
||||||
// Here we can handle De Initialization Reasons ...
|
|
||||||
IndicatorRelease(atrHandler);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int numOfRequiredAtrs;
|
|
||||||
if (prev_calculated > rates_total || prev_calculated < 0)
|
|
||||||
{
|
|
||||||
numOfRequiredAtrs = rates_total;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
numOfRequiredAtrs = rates_total - prev_calculated;
|
|
||||||
if (prev_calculated > 0)
|
|
||||||
{
|
|
||||||
numOfRequiredAtrs++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Checking for stop ...
|
|
||||||
if (IsStopped())
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Number of items Copy or not ...
|
|
||||||
int copiedATRs = CopyBuffer(atrHandler, 0, 0, numOfRequiredAtrs, atrBuffer);
|
|
||||||
if (copiedATRs <= 0)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
//
|
|
||||||
// checking for the limit start of calculation of an indicator ...
|
|
||||||
if (prev_calculated > rates_total || prev_calculated <= 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// starting index for calculation of all bars ...
|
|
||||||
limit = maxLength;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// starting number for calculation of new bars
|
|
||||||
limit = prev_calculated - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main Loop ...
|
|
||||||
for (int i = limit; i < rates_total && !IsStopped(); i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Calculated Price ...
|
|
||||||
double price = getPrice(
|
|
||||||
atrAppliedTo,
|
|
||||||
open,
|
|
||||||
high,
|
|
||||||
low,
|
|
||||||
close,
|
|
||||||
i);
|
|
||||||
// price = (high[i] + low[i]) / 2;
|
|
||||||
priceBuffer[i] = price;
|
|
||||||
|
|
||||||
//
|
|
||||||
double atr = atrBuffer[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
// Up ...
|
|
||||||
upBuffer[i] = price + (atrMultiplier * atr);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Down ...
|
|
||||||
downBuffer[i] = price - (atrMultiplier * atr);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (close[i] > upBuffer[i - 1])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
trendBuffer[i] = 1;
|
|
||||||
if (trendBuffer[i - 1] == -1)
|
|
||||||
{
|
|
||||||
changeOfTrend = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (close[i] < downBuffer[i - 1])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
trendBuffer[i] = -1;
|
|
||||||
if (trendBuffer[i - 1] == 1)
|
|
||||||
{
|
|
||||||
changeOfTrend = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (trendBuffer[i - 1] == 1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
trendBuffer[i] = 1;
|
|
||||||
changeOfTrend = 0;
|
|
||||||
}
|
|
||||||
else if (trendBuffer[i - 1] == -1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
trendBuffer[i] = -1;
|
|
||||||
changeOfTrend = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Down Trend Starting ...
|
|
||||||
if (trendBuffer[i] < 0 && trendBuffer[i - 1] > 0)
|
|
||||||
{
|
|
||||||
startBearishTrend = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
startBearishTrend = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Up Trend Starting ...
|
|
||||||
if (trendBuffer[i] > 0 && trendBuffer[i - 1] < 0)
|
|
||||||
{
|
|
||||||
startBullishTrend = 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
startBullishTrend = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (trendBuffer[i] > 0 && downBuffer[i] < downBuffer[i - 1])
|
|
||||||
{
|
|
||||||
downBuffer[i] = downBuffer[i - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (trendBuffer[i] < 0 && upBuffer[i] > upBuffer[i - 1])
|
|
||||||
{
|
|
||||||
upBuffer[i] = upBuffer[i - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (startBearishTrend == 1)
|
|
||||||
{
|
|
||||||
upBuffer[i] = priceBuffer[i] + (atrMultiplier * atr);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (startBullishTrend == 1)
|
|
||||||
{
|
|
||||||
downBuffer[i] = priceBuffer[i] - (atrMultiplier * atr);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Draw the indicator ...
|
|
||||||
|
|
||||||
//
|
|
||||||
double colorIDX = 0;
|
|
||||||
mainColorBuffer[i] = colorIDX;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (trendBuffer[i] == 1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mainBuffer[i] = downBuffer[i];
|
|
||||||
if (changeOfTrend == 1)
|
|
||||||
{
|
|
||||||
mainBuffer[i - 1] = mainBuffer[i - 2];
|
|
||||||
changeOfTrend = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
colorIDX = 1;
|
|
||||||
}
|
|
||||||
else if (trendBuffer[i] == -1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mainBuffer[i] = upBuffer[i];
|
|
||||||
if (changeOfTrend == 1)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mainBuffer[i - 1] = mainBuffer[i - 2];
|
|
||||||
changeOfTrend = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
colorIDX = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (showTrends)
|
|
||||||
{
|
|
||||||
mainColorBuffer[i] = colorIDX;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Filling ...
|
|
||||||
if (fillTrends)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
fillUpBuffer[i] = mainBuffer[i];
|
|
||||||
fillDownBuffer[i] = close[i];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
fillUpBuffer[i] = EMPTY_VALUE;
|
|
||||||
fillDownBuffer[i] = EMPTY_VALUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Functions ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Args ...
|
|
||||||
result =
|
|
||||||
//
|
|
||||||
atrLength >= 2
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve all Exists Input Max Length ...
|
|
||||||
// use for Start Of Drawing ...
|
|
||||||
int ExtractMaxLengthOfInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = atrLength;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// PLOT Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// FILLINGS ...
|
|
||||||
SetIndexBuffer(fillUpBufferIndex, fillUpBuffer, INDICATOR_DATA);
|
|
||||||
SetIndexBuffer(fillDownBufferIndex, fillDownBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(fillingPlotBufferIndex, PLOT_SHOW_DATA, false);
|
|
||||||
|
|
||||||
//
|
|
||||||
// MAIN ...
|
|
||||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(mainPlotBufferIndex, PLOT_SHOW_DATA, showTrends);
|
|
||||||
SetIndexBuffer(mainColorBufferIndex, mainColorBuffer, INDICATOR_COLOR_INDEX);
|
|
||||||
|
|
||||||
//
|
|
||||||
// DATA Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// ATR ...
|
|
||||||
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// TREND ...
|
|
||||||
SetIndexBuffer(trendBufferIndex, trendBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// UP ...
|
|
||||||
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// DOWN ...
|
|
||||||
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// PRICE ...
|
|
||||||
SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Functions ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// TEMPLATE Function ...
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
double getPrice(ENUM_APPLIED_PRICE tprice, T &open[], T &high[], T &low[], T &close[], int i)
|
|
||||||
{
|
|
||||||
switch (tprice)
|
|
||||||
{
|
|
||||||
case PRICE_CLOSE:
|
|
||||||
return (close[i]);
|
|
||||||
case PRICE_OPEN:
|
|
||||||
return (open[i]);
|
|
||||||
case PRICE_HIGH:
|
|
||||||
return (high[i]);
|
|
||||||
case PRICE_LOW:
|
|
||||||
return (low[i]);
|
|
||||||
case PRICE_MEDIAN:
|
|
||||||
return ((high[i] + low[i]) / 2.0);
|
|
||||||
case PRICE_TYPICAL:
|
|
||||||
return ((high[i] + low[i] + close[i]) / 3.0);
|
|
||||||
case PRICE_WEIGHTED:
|
|
||||||
return ((high[i] + low[i] + close[i] + close[i]) / 4.0);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@@ -1,371 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Trend Detector Oscillator
|
|
||||||
// --------------------------------------------------
|
|
||||||
// Name: XTD
|
|
||||||
// Description: trend detecting in both sides ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XTD Oscillator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
#define ShortName "XTDP"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Imports ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5";
|
|
||||||
|
|
||||||
//
|
|
||||||
// Inputs ...
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Market";
|
|
||||||
input int length = 14; // Market Length
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showBullishPower = true;
|
|
||||||
input bool showBearishPower = true;
|
|
||||||
input bool showBullishPressure = true;
|
|
||||||
input bool showBearishPressure = true;
|
|
||||||
input bool showSignal = true;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_separate_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 5
|
|
||||||
#property indicator_plots 5
|
|
||||||
|
|
||||||
//
|
|
||||||
#define bullishBufferIndex 0
|
|
||||||
#define bearishBufferIndex 1
|
|
||||||
#define bullishPBufferIndex 2
|
|
||||||
#define bearishPBufferIndex 3
|
|
||||||
#define signalBufferIndex 4
|
|
||||||
|
|
||||||
//
|
|
||||||
double bullishBuffer[];
|
|
||||||
double bearishBuffer[];
|
|
||||||
double bullishPBuffer[];
|
|
||||||
double bearishPBuffer[];
|
|
||||||
double signalBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XBullPressure"
|
|
||||||
#property indicator_type1 DRAW_LINE
|
|
||||||
#property indicator_color1 clrLime
|
|
||||||
#property indicator_style1 STYLE_SOLID
|
|
||||||
#property indicator_width1 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label2 "XBearPressure"
|
|
||||||
#property indicator_type2 DRAW_LINE
|
|
||||||
#property indicator_color2 clrRed
|
|
||||||
#property indicator_style2 STYLE_SOLID
|
|
||||||
#property indicator_width2 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label3 "XBullPow"
|
|
||||||
#property indicator_type3 DRAW_LINE
|
|
||||||
#property indicator_color3 clrAqua
|
|
||||||
#property indicator_style3 STYLE_SOLID
|
|
||||||
#property indicator_width3 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label4 "XBearPow"
|
|
||||||
#property indicator_type4 DRAW_LINE
|
|
||||||
#property indicator_color4 clrMagenta
|
|
||||||
#property indicator_style4 STYLE_SOLID
|
|
||||||
#property indicator_width4 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label5 "XSignal"
|
|
||||||
#property indicator_type5 DRAW_LINE
|
|
||||||
#property indicator_color5 clrYellow
|
|
||||||
#property indicator_style5 STYLE_SOLID
|
|
||||||
#property indicator_width5 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// Event Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
|
|
||||||
//
|
|
||||||
// Here we can handle De Initialization Reasons ...
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculations ...
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Prepare Buffers ...
|
|
||||||
ArraySetAsSeries(time, true);
|
|
||||||
ArraySetAsSeries(open, true);
|
|
||||||
ArraySetAsSeries(high, true);
|
|
||||||
ArraySetAsSeries(low, true);
|
|
||||||
ArraySetAsSeries(close, true);
|
|
||||||
ArraySetAsSeries(tick_volume, true);
|
|
||||||
ArraySetAsSeries(volume, true);
|
|
||||||
ArraySetAsSeries(spread, true);
|
|
||||||
|
|
||||||
//
|
|
||||||
// this counts Available Bars ...
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
//
|
|
||||||
// because in some cases we may have more than one input for
|
|
||||||
// calculation and we must prevent any calculation
|
|
||||||
// untill we pass the biggest input length, here we get max Input length
|
|
||||||
// and then wait until pass it ...
|
|
||||||
int maxLength = MathMax(0, length);
|
|
||||||
|
|
||||||
//
|
|
||||||
limit = prev_calculated < maxLength ? rates_total - (maxLength + 1) : rates_total - prev_calculated;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main Loop ...
|
|
||||||
for (int i = limit; i >= 0 && !IsStopped(); i--)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
CalculateBuffers(i,
|
|
||||||
open,
|
|
||||||
high,
|
|
||||||
low,
|
|
||||||
close //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Args ...
|
|
||||||
if (length >= 5)
|
|
||||||
{
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Bullish Buffer ...
|
|
||||||
ENUM_DRAW_TYPE bullishDrawType = showBullishPressure ? DRAW_LINE : DRAW_NONE;
|
|
||||||
string bullishBufferLabel = ShortName + "BullPress " + "(" + (string)length + ")";
|
|
||||||
ArraySetAsSeries(bullishBuffer, true);
|
|
||||||
SetIndexBuffer(bullishBufferIndex, bullishBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(bullishBufferIndex, PLOT_DRAW_BEGIN, length);
|
|
||||||
PlotIndexSetString(bullishBufferIndex, PLOT_LABEL, bullishBufferLabel);
|
|
||||||
PlotIndexSetInteger(bullishBufferIndex, PLOT_DRAW_TYPE, bullishDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Bearish Buffer ...
|
|
||||||
ENUM_DRAW_TYPE bearishDrawType = showBearishPressure ? DRAW_LINE : DRAW_NONE;
|
|
||||||
string bearishBufferLabel = ShortName + "BearPress " + "(" + (string)length + ")";
|
|
||||||
ArraySetAsSeries(bearishBuffer, true);
|
|
||||||
SetIndexBuffer(bearishBufferIndex, bearishBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(bearishBufferIndex, PLOT_DRAW_BEGIN, length);
|
|
||||||
PlotIndexSetString(bearishBufferIndex, PLOT_LABEL, bearishBufferLabel);
|
|
||||||
PlotIndexSetInteger(bearishBufferIndex, PLOT_DRAW_TYPE, bearishDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Bullish Buffer ...
|
|
||||||
ENUM_DRAW_TYPE bullishPDrawType = showBullishPower ? DRAW_LINE : DRAW_NONE;
|
|
||||||
string bullishPBufferLabel = ShortName + "BullPow " + "(" + (string)length + ")";
|
|
||||||
ArraySetAsSeries(bullishPBuffer, true);
|
|
||||||
SetIndexBuffer(bullishPBufferIndex, bullishPBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(bullishPBufferIndex, PLOT_DRAW_BEGIN, length);
|
|
||||||
PlotIndexSetString(bullishPBufferIndex, PLOT_LABEL, bullishPBufferLabel);
|
|
||||||
PlotIndexSetInteger(bullishPBufferIndex, PLOT_DRAW_TYPE, bullishPDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Bearish Buffer ...
|
|
||||||
ENUM_DRAW_TYPE bearishPDrawType = showBearishPower ? DRAW_LINE : DRAW_NONE;
|
|
||||||
string bearishPBufferLabel = ShortName + "BearPow " + "(" + (string)length + ")";
|
|
||||||
ArraySetAsSeries(bearishPBuffer, true);
|
|
||||||
SetIndexBuffer(bearishPBufferIndex, bearishPBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(bearishPBufferIndex, PLOT_DRAW_BEGIN, length);
|
|
||||||
PlotIndexSetString(bearishPBufferIndex, PLOT_LABEL, bearishPBufferLabel);
|
|
||||||
PlotIndexSetInteger(bearishPBufferIndex, PLOT_DRAW_TYPE, bearishPDrawType);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Signal Buffer ...
|
|
||||||
ENUM_DRAW_TYPE signalDrawType = showSignal ? DRAW_LINE : DRAW_NONE;
|
|
||||||
string signalBufferLabel = ShortName + "Signal " + "(" + (string)length + ")";
|
|
||||||
ArraySetAsSeries(signalBuffer, true);
|
|
||||||
SetIndexBuffer(signalBufferIndex, signalBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetInteger(signalBufferIndex, PLOT_DRAW_BEGIN, length);
|
|
||||||
PlotIndexSetString(signalBufferIndex, PLOT_LABEL, signalBufferLabel);
|
|
||||||
PlotIndexSetInteger(signalBufferIndex, PLOT_DRAW_TYPE, signalDrawType);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string indicatorShortName = "";
|
|
||||||
StringConcatenate(indicatorShortName, ShortName, " ", "( ", length, " )");
|
|
||||||
|
|
||||||
//
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Buffers ...
|
|
||||||
void CalculateBuffers(
|
|
||||||
int bar_index,
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[] // History of Close Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double bullPow = 0;
|
|
||||||
double bearPow = 0;
|
|
||||||
double bullPressure = 0;
|
|
||||||
double bearPressure = 0;
|
|
||||||
double signal = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Loop through Closes ...
|
|
||||||
for (int i = bar_index; i <= bar_index + length; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double iO = open[i];
|
|
||||||
double iH = high[i];
|
|
||||||
double iL = low[i];
|
|
||||||
double iC = close[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
double iUp = MathMax(iO, iC);
|
|
||||||
double iDown = MathMin(iO, iC);
|
|
||||||
|
|
||||||
//
|
|
||||||
double iUpShadow = iH - iUp;
|
|
||||||
double iDownShadow = iDown - iL;
|
|
||||||
|
|
||||||
//
|
|
||||||
bullPressure += iDownShadow;
|
|
||||||
bearPressure += iUpShadow;
|
|
||||||
|
|
||||||
//
|
|
||||||
signal += (iUp - iDown);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Bearish ...
|
|
||||||
if (iO > iC)
|
|
||||||
{
|
|
||||||
bearPow += signal;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Bullish ...
|
|
||||||
if (iO < iC)
|
|
||||||
{
|
|
||||||
bullPow += signal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Bullish Power Buffer ...
|
|
||||||
bullishPBuffer[bar_index] = bullPow;
|
|
||||||
bullishBuffer[bar_index] = bullPressure;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Bearish Power Buffer ...
|
|
||||||
bearishPBuffer[bar_index] = bearPow;
|
|
||||||
bearishBuffer[bar_index] = bearPressure;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Signal Buffer ...
|
|
||||||
// signal = length;
|
|
||||||
signalBuffer[bar_index] = signal;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
@@ -1,332 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Candle Indicator
|
|
||||||
// ---------------------------------------------
|
|
||||||
// Name: XTM
|
|
||||||
// Description: Trend Magic Indicator ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XTM Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Constants ...
|
|
||||||
//
|
|
||||||
#define ShortName "XTM"
|
|
||||||
|
|
||||||
//
|
|
||||||
// XTM Indicator States ...
|
|
||||||
enum ENUM_X_XTM_STATES
|
|
||||||
{
|
|
||||||
X_XTM_BULLISH = 1,
|
|
||||||
X_XTM_BEARISH = -1,
|
|
||||||
X_XTM_NEUTURAL = 0,
|
|
||||||
};
|
|
||||||
//
|
|
||||||
// END Constants ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Market";
|
|
||||||
input int maPeriod = 14; // Period
|
|
||||||
input int maShift = 0; // Shift
|
|
||||||
input ENUM_MA_METHOD maMethod = MODE_SMA; // Method
|
|
||||||
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // Applied To
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showLine = true; // Show Line
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Inputs ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Includes Common Library ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Buffers ...
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 3
|
|
||||||
#property indicator_plots 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// maBuffer ...
|
|
||||||
#define maBufferIndex 0
|
|
||||||
#define maColorBufferIndex 1
|
|
||||||
#define stateBufferIndex 2
|
|
||||||
|
|
||||||
double maBuffer[];
|
|
||||||
double maColorBuffer[];
|
|
||||||
double stateBuffer[];
|
|
||||||
|
|
||||||
#property indicator_label1 "XTM"
|
|
||||||
#property indicator_type1 DRAW_COLOR_LINE
|
|
||||||
#property indicator_color1 clrLime, clrGray, clrRed, CLR_NONE
|
|
||||||
#property indicator_style1 STYLE_SOLID
|
|
||||||
#property indicator_width1 1
|
|
||||||
//
|
|
||||||
// END Buffers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
int maHandler = INVALID_HANDLE;
|
|
||||||
//
|
|
||||||
// END Global Definitions: Variables, Properties and etc ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Event Handlers ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initializing MA Handler ...
|
|
||||||
maHandler = iMA(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
maPeriod,
|
|
||||||
maShift,
|
|
||||||
maMethod,
|
|
||||||
maAppliedTo);
|
|
||||||
if (maHandler == INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
return INIT_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
|
|
||||||
//
|
|
||||||
// Here we can handle De Initialization Reasons ...
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculations ...
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Prepare Buffers ...
|
|
||||||
ArraySetAsSeries(time, true);
|
|
||||||
ArraySetAsSeries(open, true);
|
|
||||||
ArraySetAsSeries(high, true);
|
|
||||||
ArraySetAsSeries(low, true);
|
|
||||||
ArraySetAsSeries(close, true);
|
|
||||||
ArraySetAsSeries(tick_volume, true);
|
|
||||||
ArraySetAsSeries(volume, true);
|
|
||||||
ArraySetAsSeries(spread, true);
|
|
||||||
|
|
||||||
//
|
|
||||||
// this counts Available Bars ...
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
//
|
|
||||||
// because in some cases we may have more than one input for
|
|
||||||
// calculation and we must prevent any calculation
|
|
||||||
// untill we pass the biggest input length, here we get max Input length
|
|
||||||
// and then wait until pass it ...
|
|
||||||
int maxLength = MathMax(0, maPeriod);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Calculated Bars ...
|
|
||||||
int maCalculatedBars = BarsCalculated(maHandler);
|
|
||||||
if (maCalculatedBars < maxLength)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers Copy ...
|
|
||||||
int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer);
|
|
||||||
if (copiedMas <= 0)
|
|
||||||
{
|
|
||||||
return prev_calculated;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Main Loop ...
|
|
||||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Do Buffers Calculation ...
|
|
||||||
CalculateBuffers(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// END Event Handlers ...
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// START Functions ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Args ...
|
|
||||||
if (maPeriod >= 2)
|
|
||||||
{
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string maBufferLabel = "XTM " + "(" + (string)maPeriod + ")";
|
|
||||||
|
|
||||||
//
|
|
||||||
// Ma Buffer ...
|
|
||||||
ArraySetAsSeries(maBuffer, true);
|
|
||||||
SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA);
|
|
||||||
PlotIndexSetString(maBufferIndex, PLOT_LABEL, maBufferLabel);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Ma Color Buffer ...
|
|
||||||
ArraySetAsSeries(maColorBuffer, true);
|
|
||||||
SetIndexBuffer(maColorBufferIndex, maColorBuffer, INDICATOR_COLOR_INDEX);
|
|
||||||
|
|
||||||
//
|
|
||||||
// State Buffer ...
|
|
||||||
ArraySetAsSeries(stateBuffer, true);
|
|
||||||
SetIndexBuffer(stateBufferIndex, stateBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string indicatorShortName = "";
|
|
||||||
StringConcatenate(indicatorShortName, ShortName, " ", "(", maPeriod, ")");
|
|
||||||
|
|
||||||
//
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, indicatorShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Buffers ...
|
|
||||||
void CalculateBuffers(int bar_index)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Requirements ...
|
|
||||||
XOHCL candle;
|
|
||||||
candle.Init(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
bar_index
|
|
||||||
//
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
double maValue = maBuffer[bar_index];
|
|
||||||
|
|
||||||
//
|
|
||||||
double lineColorIndex =
|
|
||||||
maValue < candle.low ? 0 : maValue > candle.high ? 2
|
|
||||||
: 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define State Value ...
|
|
||||||
// lineColorIndex == 0 => Bullish => 1;
|
|
||||||
// lineColorIndex == 1 => Neutural => 0;
|
|
||||||
// lineColorIndex == 2 => Bearish => -1;
|
|
||||||
double stateValue =
|
|
||||||
lineColorIndex == 0 ? X_XTM_BULLISH : lineColorIndex == 2 ? X_XTM_BEARISH
|
|
||||||
: X_XTM_NEUTURAL;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Ma Buffer Color Index ...
|
|
||||||
maColorBuffer[bar_index] = showLine ? lineColorIndex : 3;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set State Buffer Value ...
|
|
||||||
stateBuffer[bar_index] = stateValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// END Functions ...
|
|
||||||
//
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// -------------------------------------------
|
|
||||||
// Name: XVWAP
|
|
||||||
// Description: VWap Implementation ...
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XVWAP Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
#define ShortName "XVWAP"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Imports ...
|
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Inputs ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 0
|
|
||||||
#property indicator_plots 0
|
|
||||||
|
|
||||||
//
|
|
||||||
// #define hideColorIDX 0
|
|
||||||
// #define bullColorIDX 1
|
|
||||||
// #define bearColorIDX 2
|
|
||||||
|
|
||||||
// //
|
|
||||||
// #define bullpBufferIndex 1
|
|
||||||
// double bullpBuffer[];
|
|
||||||
|
|
||||||
// //
|
|
||||||
// #property indicator_label1 ""
|
|
||||||
// #property indicator_type1 DRAW_COLOR_LINE
|
|
||||||
// #property indicator_color1 CLR_NONE, clrGreen, clrDarkRed
|
|
||||||
// #property indicator_style1 STYLE_DOT
|
|
||||||
// #property indicator_width1 1
|
|
||||||
|
|
||||||
//
|
|
||||||
// Variables ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Event Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Custom Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result =
|
|
||||||
//
|
|
||||||
true
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Main ...
|
|
||||||
// ENUM_DRAW_TYPE mainDrawType = show ? DRAW_COLOR_LINE : DRAW_NONE;
|
|
||||||
|
|
||||||
// ArraySetAsSeries(mainBuffer, true);
|
|
||||||
// ArraySetAsSeries(mainBufferColor, true);
|
|
||||||
// PlotIndexSetInteger(mainBufferIndex, PLOT_SHOW_DATA, true);
|
|
||||||
// SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
|
||||||
// PlotIndexSetInteger(mainBufferIndex, PLOT_DRAW_TYPE, mainDrawType);
|
|
||||||
// SetIndexBuffer(mainBufferColorIndex, mainBufferColor, INDICATOR_COLOR_INDEX);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
@@ -1,750 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Indicator
|
|
||||||
// ---------------------------------------------
|
|
||||||
// Name: XZG
|
|
||||||
// Description: Zogzag Implementation ...
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Maintainer:
|
|
||||||
// ------------
|
|
||||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
||||||
//
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Global Properties ...
|
|
||||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
||||||
#property link "https://saherelm.ir"
|
|
||||||
#property version "1.00"
|
|
||||||
#property description "SaherElm XZG Indicator"
|
|
||||||
#property strict
|
|
||||||
|
|
||||||
//
|
|
||||||
#define ShortName "XZG"
|
|
||||||
|
|
||||||
//
|
|
||||||
// DEFINITIONS ...
|
|
||||||
enum ENUM_X_ZG_SEARCH_MODE
|
|
||||||
{
|
|
||||||
X_ZG_SEARCH_EXTREMUM = 0, // searching for the first extremum
|
|
||||||
X_ZG_SEARCH_PEAK = 1, // searching for the next ZigZag peak
|
|
||||||
X_ZG_SEARCH_VALE = -1 // searching for the next ZigZag vale
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// How to Calculate Up and Down Price ...
|
|
||||||
enum ENUM_X_ZG_PRICE_MODE
|
|
||||||
{
|
|
||||||
//
|
|
||||||
X_ZG_PRICE_HIGH_LOW_MODE = 1,
|
|
||||||
X_ZG_PRICE_OPEN_CLOSE_MODE = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// INPUT ...
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Market";
|
|
||||||
input int depth = 12; // Depth
|
|
||||||
input int deviation = 5; // Deviation
|
|
||||||
input int backStep = 3; // Back Step
|
|
||||||
input ENUM_X_ZG_PRICE_MODE mode = X_ZG_PRICE_HIGH_LOW_MODE; // Mode
|
|
||||||
|
|
||||||
//
|
|
||||||
input group "Presentation";
|
|
||||||
input bool showZigZag = true; // Show ZigZag
|
|
||||||
input bool showPeaksAndVales = true; // Show Peaks and Vales
|
|
||||||
|
|
||||||
//
|
|
||||||
// BUFFERS ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_chart_window
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_buffers 6
|
|
||||||
#property indicator_plots 4
|
|
||||||
|
|
||||||
//
|
|
||||||
// ZigZag ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define mainBufferIndex 0
|
|
||||||
#define mainBufferPlotIndex 0
|
|
||||||
double mainBuffer[];
|
|
||||||
|
|
||||||
#define mainColorBufferIndex 1
|
|
||||||
double mainColorBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label1 "XZG Main"
|
|
||||||
#property indicator_type1 DRAW_COLOR_SECTION
|
|
||||||
#property indicator_color1 CLR_NONE, clrRoyalBlue, clrSaddleBrown
|
|
||||||
#property indicator_width1 2
|
|
||||||
|
|
||||||
//
|
|
||||||
// Highs ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// ZigZag Pointer or Line Indicator ...
|
|
||||||
#define arrowBufferIndex 2
|
|
||||||
#define arrowBufferPlotIndex 1
|
|
||||||
double arrowBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#define arrowColorBufferIndex 3
|
|
||||||
double arrowColorBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
#property indicator_label2 "XZG PV"
|
|
||||||
#property indicator_type2 DRAW_COLOR_ARROW
|
|
||||||
#property indicator_color2 CLR_NONE, clrAqua, clrMagenta
|
|
||||||
#property indicator_width2 1
|
|
||||||
|
|
||||||
//
|
|
||||||
#define highsBufferIndex 4
|
|
||||||
double highsBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// Lows ...
|
|
||||||
|
|
||||||
//
|
|
||||||
#define lowsBufferIndex 5
|
|
||||||
double lowsBuffer[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// VARIABLES ...
|
|
||||||
|
|
||||||
//
|
|
||||||
int mRecalc = 3; // Number of last extremes for recalculation
|
|
||||||
|
|
||||||
//
|
|
||||||
// EVENT Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialization ...
|
|
||||||
int OnInit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
if (!ValidateInputs())
|
|
||||||
{
|
|
||||||
return INIT_PARAMETERS_INCORRECT;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// logTag = ShortName;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Index Buffers ...
|
|
||||||
DefineBuffers();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator ShortName ...
|
|
||||||
SetIndicatorName();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Init Succeed ...
|
|
||||||
return INIT_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInitialization ...
|
|
||||||
void OnDeinit(const int reason)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
||||||
// REASON_REMOVE 1 Program removed from a chart
|
|
||||||
// REASON_RECOMPILE 2 Program recompiled
|
|
||||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
||||||
// REASON_CHARTCLOSE 4 Chart closed
|
|
||||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
||||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
||||||
// REASON_TEMPLATE 7 Another chart template applied
|
|
||||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
||||||
// REASON_CLOSE 9 Terminal closed
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating what we want ...
|
|
||||||
int OnCalculate(
|
|
||||||
const int rates_total, // Total Bars on Chart ...
|
|
||||||
const int prev_calculated, // Total Calculated Bars on Charts ...
|
|
||||||
const datetime &time[], // History of Open Time ...
|
|
||||||
const double &open[], // History of Open Price ...
|
|
||||||
const double &high[], // History of High Price ...
|
|
||||||
const double &low[], // History of Low Price ...
|
|
||||||
const double &close[], // History of Close Price ...
|
|
||||||
const long &tick_volume[], // History of Tick Volumes on Bar ...
|
|
||||||
const long &volume[], // History of Trade Volumes ...
|
|
||||||
const int &spread[] // History of Spread Price ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double mZGHigh[];
|
|
||||||
double mZGLow[];
|
|
||||||
if (mode == X_ZG_PRICE_OPEN_CLOSE_MODE)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
ArrayCopy(
|
|
||||||
mZGHigh,
|
|
||||||
open
|
|
||||||
//
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArrayCopy(
|
|
||||||
mZGLow,
|
|
||||||
close
|
|
||||||
//
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
ArrayCopy(
|
|
||||||
mZGHigh,
|
|
||||||
high
|
|
||||||
//
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
ArrayCopy(
|
|
||||||
mZGLow,
|
|
||||||
low
|
|
||||||
//
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int zigZagResult = CalcukateZigZag(
|
|
||||||
prev_calculated,
|
|
||||||
rates_total,
|
|
||||||
mZGHigh,
|
|
||||||
mZGLow
|
|
||||||
//
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (zigZagResult != rates_total)
|
|
||||||
{
|
|
||||||
return zigZagResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// CUSTOM Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Input Args for Initialization ...
|
|
||||||
bool ValidateInputs()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result =
|
|
||||||
//
|
|
||||||
depth > 0 &&
|
|
||||||
deviation > 0 &&
|
|
||||||
backStep > 0
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Indexes and Styles ...
|
|
||||||
void DefineBuffers()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Main ...
|
|
||||||
|
|
||||||
//
|
|
||||||
SetIndexBuffer(mainBufferIndex, mainBuffer, INDICATOR_DATA);
|
|
||||||
SetIndexBuffer(mainColorBufferIndex, mainColorBuffer, INDICATOR_COLOR_INDEX);
|
|
||||||
|
|
||||||
//
|
|
||||||
PlotIndexSetInteger(mainBufferPlotIndex, PLOT_SHOW_DATA, showZigZag);
|
|
||||||
PlotIndexSetInteger(mainBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
||||||
PlotIndexSetDouble(mainBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Arrow ...
|
|
||||||
|
|
||||||
//
|
|
||||||
SetIndexBuffer(arrowBufferIndex, arrowBuffer, INDICATOR_DATA);
|
|
||||||
|
|
||||||
//
|
|
||||||
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_SHOW_DATA, showPeaksAndVales);
|
|
||||||
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
|
|
||||||
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_ARROW, 159);
|
|
||||||
PlotIndexSetInteger(arrowBufferPlotIndex, PLOT_ARROW_SHIFT, 0);
|
|
||||||
PlotIndexSetDouble(arrowBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Arrow Color ...
|
|
||||||
SetIndexBuffer(arrowColorBufferIndex, arrowColorBuffer, INDICATOR_COLOR_INDEX);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Highs ...
|
|
||||||
SetIndexBuffer(highsBufferIndex, highsBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Lows ...
|
|
||||||
SetIndexBuffer(lowsBufferIndex, lowsBuffer, INDICATOR_CALCULATIONS);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Indicator Short Name and also we can define Buffers Labels ...
|
|
||||||
void SetIndicatorName()
|
|
||||||
{
|
|
||||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculating Zig Zag ...
|
|
||||||
int CalcukateZigZag(
|
|
||||||
const int prev_calculated,
|
|
||||||
const int rates_total,
|
|
||||||
double &high[],
|
|
||||||
double &low[]
|
|
||||||
//
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (rates_total < 100)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Define Variables ...
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
int start = 0;
|
|
||||||
int extreme_counter = 0;
|
|
||||||
int extreme_search = X_ZG_SEARCH_EXTREMUM;
|
|
||||||
int shift = 0;
|
|
||||||
int back = 0;
|
|
||||||
int last_high_pos = 0;
|
|
||||||
int last_low_pos = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
double val = 0;
|
|
||||||
double res = 0;
|
|
||||||
double curlow = 0;
|
|
||||||
double curhigh = 0;
|
|
||||||
double last_high = 0;
|
|
||||||
double last_low = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
double colorIDX = 0;
|
|
||||||
double lastZigZagValue = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initializing ...
|
|
||||||
if (prev_calculated == 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
ArrayInitialize(mainBuffer, 0);
|
|
||||||
ArrayInitialize(highsBuffer, 0);
|
|
||||||
ArrayInitialize(lowsBuffer, 0);
|
|
||||||
|
|
||||||
//
|
|
||||||
start = depth;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Already Calculated Before ...
|
|
||||||
if (prev_calculated > 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
i = rates_total - 1;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Searching for the third X_ZG_SEARCH_EXTREMUM from the last UnComplete Bar ...
|
|
||||||
while (extreme_counter < mRecalc && i > rates_total - 100)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
res = mainBuffer[i];
|
|
||||||
if (res != 0)
|
|
||||||
{
|
|
||||||
extreme_counter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
i++;
|
|
||||||
start = i;
|
|
||||||
|
|
||||||
//
|
|
||||||
// What type of X_ZG_SEARCH_EXTREMUM we Search for ...
|
|
||||||
if (lowsBuffer[i] != 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
curlow = lowsBuffer[i];
|
|
||||||
extreme_search = X_ZG_SEARCH_PEAK;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
curhigh = highsBuffer[i];
|
|
||||||
extreme_search = X_ZG_SEARCH_VALE;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Clear Values ...
|
|
||||||
for (i = start + 1; i < rates_total && !IsStopped(); i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mainBuffer[i] = 0;
|
|
||||||
lowsBuffer[i] = 0;
|
|
||||||
highsBuffer[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Search for High and Low Extremes ...
|
|
||||||
for (shift = start; shift < rates_total && !IsStopped(); shift++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Low ...
|
|
||||||
val = low[Lowest(low, depth, shift)];
|
|
||||||
if (val == last_low)
|
|
||||||
{
|
|
||||||
val = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
last_low = val;
|
|
||||||
|
|
||||||
//
|
|
||||||
if ((low[shift] - val) > deviation * _Point)
|
|
||||||
{
|
|
||||||
val = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
for (back = 1; back <= backStep; back++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
res = lowsBuffer[shift - back];
|
|
||||||
if ((res != 0) && (res > val))
|
|
||||||
{
|
|
||||||
lowsBuffer[shift - back] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (low[shift] == val)
|
|
||||||
{
|
|
||||||
lowsBuffer[shift] = val;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lowsBuffer[shift] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// High ...
|
|
||||||
val = high[Highest(high, depth, shift)];
|
|
||||||
if (val == last_high)
|
|
||||||
{
|
|
||||||
val = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
last_high = val;
|
|
||||||
|
|
||||||
//
|
|
||||||
if ((val - high[shift]) > deviation * _Point)
|
|
||||||
{
|
|
||||||
val = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
for (back = 1; back <= backStep; back++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
res = highsBuffer[shift - back];
|
|
||||||
if ((res != 0) && (res < val))
|
|
||||||
{
|
|
||||||
highsBuffer[shift - back] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (high[shift] == val)
|
|
||||||
{
|
|
||||||
highsBuffer[shift] = val;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
highsBuffer[shift] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Last Value ...
|
|
||||||
if (extreme_search == 0) // Undefined Values ...
|
|
||||||
{
|
|
||||||
//
|
|
||||||
last_low = 0;
|
|
||||||
last_high = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
last_low = curlow;
|
|
||||||
last_high = curhigh;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Final Selection of Extreme Points for ZigZag ...
|
|
||||||
for (shift = start; shift < rates_total && !IsStopped(); shift++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
res = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
switch (extreme_search)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
case X_ZG_SEARCH_EXTREMUM:
|
|
||||||
//
|
|
||||||
if (last_low == 0 && last_high == 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (highsBuffer[shift] != 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
last_high_pos = shift;
|
|
||||||
last_high = high[shift];
|
|
||||||
|
|
||||||
//
|
|
||||||
extreme_search = X_ZG_SEARCH_VALE;
|
|
||||||
|
|
||||||
//
|
|
||||||
mainBuffer[shift] = last_high;
|
|
||||||
|
|
||||||
//
|
|
||||||
res = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (lowsBuffer[shift] != 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
last_low_pos = shift;
|
|
||||||
last_low = low[shift];
|
|
||||||
|
|
||||||
//
|
|
||||||
extreme_search = X_ZG_SEARCH_PEAK;
|
|
||||||
|
|
||||||
//
|
|
||||||
mainBuffer[shift] = last_low;
|
|
||||||
|
|
||||||
//
|
|
||||||
res = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
case X_ZG_SEARCH_PEAK:
|
|
||||||
//
|
|
||||||
if (lowsBuffer[shift] != 0 && lowsBuffer[shift] < last_low && highsBuffer[shift] == 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mainBuffer[last_low_pos] = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
last_low_pos = shift;
|
|
||||||
last_low = lowsBuffer[shift];
|
|
||||||
|
|
||||||
//
|
|
||||||
mainBuffer[shift] = last_low;
|
|
||||||
|
|
||||||
//
|
|
||||||
res = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (highsBuffer[shift] != 0 && lowsBuffer[shift] == 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
last_high_pos = shift;
|
|
||||||
last_high = highsBuffer[shift];
|
|
||||||
|
|
||||||
//
|
|
||||||
mainBuffer[shift] = last_high;
|
|
||||||
|
|
||||||
//
|
|
||||||
extreme_search = X_ZG_SEARCH_VALE;
|
|
||||||
|
|
||||||
//
|
|
||||||
res = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
case X_ZG_SEARCH_VALE:
|
|
||||||
//
|
|
||||||
if (highsBuffer[shift] != 0 && highsBuffer[shift] > last_high && lowsBuffer[shift] == 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mainBuffer[last_high_pos] = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
last_high_pos = shift;
|
|
||||||
last_high = highsBuffer[shift];
|
|
||||||
|
|
||||||
//
|
|
||||||
mainBuffer[shift] = last_high;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (lowsBuffer[shift] != 0 && highsBuffer[shift] == 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
last_low_pos = shift;
|
|
||||||
last_low = lowsBuffer[shift];
|
|
||||||
|
|
||||||
//
|
|
||||||
mainBuffer[shift] = last_low;
|
|
||||||
|
|
||||||
//
|
|
||||||
extreme_search = X_ZG_SEARCH_PEAK;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
double iZigZagForColor = lastZigZagValue;
|
|
||||||
double iZigZag = mainBuffer[shift];
|
|
||||||
if (iZigZag == 0 && lastZigZagValue != 0)
|
|
||||||
{
|
|
||||||
arrowBuffer[shift] = lastZigZagValue;
|
|
||||||
}
|
|
||||||
else if (iZigZag != 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
lastZigZagValue = iZigZag;
|
|
||||||
arrowBuffer[shift] = lastZigZagValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
colorIDX =
|
|
||||||
lastZigZagValue > iZigZagForColor
|
|
||||||
? 1
|
|
||||||
: lastZigZagValue < iZigZagForColor
|
|
||||||
? 2
|
|
||||||
: colorIDX;
|
|
||||||
|
|
||||||
//
|
|
||||||
mainColorBuffer[shift] = showZigZag ? colorIDX : 0;
|
|
||||||
arrowColorBuffer[shift] = showPeaksAndVales ? colorIDX : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return rates_total;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// TOOLS ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Search for the index of the highest bar ...
|
|
||||||
int Highest(
|
|
||||||
const double &mArray[],
|
|
||||||
const int mDepth,
|
|
||||||
const int mStart //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (mStart < 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
double max = mArray[mStart];
|
|
||||||
result = mStart;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Start searching ...
|
|
||||||
for (int i = mStart - 1; i > mStart - mDepth && i >= 0; i--)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (mArray[i] > max)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
result = i;
|
|
||||||
max = mArray[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Return index of the highest bar
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Search for the index of the lowest bar ...
|
|
||||||
int Lowest(
|
|
||||||
const double &mArray[],
|
|
||||||
const int mDepth,
|
|
||||||
const int mStart //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (mStart < 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
double min = mArray[mStart];
|
|
||||||
result = mStart;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Start searching ...
|
|
||||||
for (int i = mStart - 1; i > mStart - mDepth && i >= 0; i--)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (mArray[i] < min)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
result = i;
|
|
||||||
min = mArray[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Return index of the lowest bar
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user