#Chaos ArrZZx2
#Chaos ArrZZx2

#Chaos ArrZZx2

更新日期:
2022-09-14
分类标签:
语言:
中文
平台:
没限制

87 人已下载 手机查看

#Chaos ArrZZx2

 

//+————+—————————————————–+
//| v.22.04.07 | ArrZZx2.mq4 |
//+————+ |
//|————| Bookkeeper, 2007, yuzefovich@gmail.com |
//+————+—————————————————–+
//+——————————————————————+
//| #Chaos ArrZZx2(1).mq5 |
//| Copyright © 2020, Andriy Moraru |
//+——————————————————————+
#property copyright “Copyright © 2020, Andriy Moraru, EarnForex.com”
#property link “https://www.earnforex.com/forum/threads/how-do-you-convert-mt4-indicators-to-mt5.23198/”

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_plots 6
#property indicator_color1 clrWhite
#property indicator_type1 DRAW_ARROW
#property indicator_width1 5
#property indicator_color2 clrLime
#property indicator_width2 2
#property indicator_color3 clrBlue //C’0,128,255′
#property indicator_width3 7
#property indicator_type3 DRAW_ARROW
#property indicator_color4 clrRed //C’192,0,192′
#property indicator_width4 7
#property indicator_type4 DRAW_ARROW
#property indicator_color5 clrDodgerBlue //C’0,128,255′
#property indicator_width5 3
#property indicator_type5 DRAW_ARROW
#property indicator_color6 clrMediumVioletRed //C’192,0,192′
#property indicator_width6 3
#property indicator_type6 DRAW_ARROW

int SR = 3; // = 3..4 Xard settings (3, 21, 20, 21, 3, false, 0)
// 60, 36, 24, 13, 4..12..20..12
input int SRZZ = 60;
int MainRZZ = 20; // 20, 12..20..54..20
int FP = 21;
int SMF = 3; // 1..5
bool DrawZZ = false;
ENUM_APPLIED_PRICE PriceConst = PRICE_CLOSE;

// Buffers:
double Lmt[];
double LZZ[];
double SA[];
double SM[];
double Up[];
double Dn[];
double pUp[];
double pDn[];

int LTF[6] = {0, 0, 0, 0, 0, 0}, STF[5] = {0, 0, 0, 0, 0};
int MaxBar, nSBZZ, nLBZZ, SBZZ, LBZZ;
bool First = true;
int prevBars = 0;
int handle_ma;

void MainCalculation(const int Pos, const int bars, const double& Open[], const double& High[], const double& Low[], const double& Close[])
{
if ((bars – Pos) > (SR + 1)) SACalc(Pos, Open, High, Low, Close);
else SA[Pos] = 0;

if ((bars – Pos) > (FP + SR + 2)) SMCalc(Pos);
else SM[Pos] = 0;
}

void SACalc(const int Pos, const double& Open[], const double& High[], const double& Low[], const double& Close[])
{
int sw, i, w, ww, Shift;
double sum;

double MA[1];
CopyBuffer(handle_ma, 0, Pos, 1, MA);
SA[Pos] = MA[0];

for (Shift = Pos + SR + 2; Shift > Pos; Shift–)
{
sum = 0.0;
sw = 0;
i = 0;
w = Shift + SR;
ww = Shift – SR;
if (ww < Pos) ww = Pos;
while (w >= Shift)
{
i++;
sum = sum + i * SnakePrice(w, Open, High, Low, Close);
sw = sw + i;
w–;
}
while(w >= ww)
{
i–;
sum = sum + i * SnakePrice(w, Open, High, Low, Close);
sw = sw + i;
w–;
}
SA[Shift] = sum / sw;
}
}

double SnakePrice(const int Shift, const double& Open[], const double& High[], const double& Low[], const double& Close[])
{
switch(PriceConst)
{
case PRICE_CLOSE:
return(Close[Shift]);
case PRICE_OPEN:
return(Open[Shift]);
case PRICE_HIGH:
return(High[Shift]);
case PRICE_LOW:
return(Low[Shift]);
case PRICE_MEDIAN:
return((High[Shift] + Low[Shift]) / 2);
case PRICE_TYPICAL:
return((Close[Shift] + High[Shift] + Low[Shift]) / 3);
case PRICE_WEIGHTED:
return((2 * Close[Shift] + High[Shift] + Low[Shift]) / 4);
default:
return(Open[Shift]);
}
}

void SMCalc(const int i)
{
double t, b;
for (int Shift = i + SR + 2; Shift >= i; Shift–)
{
t = SA[ArrayMaximum(SA, Shift, FP)];
b = SA[ArrayMinimum(SA, Shift, FP)];
SM[Shift] = (2 * (2 + SMF) * SA[Shift] – (t + b)) / 2 / (1 + SMF);
}
}

void LZZCalc(const int Pos, const int bars)
{
int i, RBar, LBar, ZZ = 0, NZZ, NZig, NZag;
i = Pos – 1;
NZig = 0;
NZag = 0;
while ((i < MaxBar) && (ZZ == 0))
{
i++;
LZZ[i] = 0;
RBar = i – MainRZZ;
if (RBar < Pos) RBar = Pos;
LBar = i + MainRZZ;
if (i == ArrayMinimum(SM, RBar, LBar – RBar + 1))
{
ZZ = -1;
NZig = i;
}
if(i == ArrayMaximum(SM, RBar, LBar – RBar + 1))
{
ZZ = 1;
NZag = i;
}
}

if (ZZ == 0) return;

NZZ = 0;
if (i > Pos)
{
if (SM[i] > SM[Pos])
{
if (ZZ == 1)
{
if ((i >= Pos + MainRZZ) && (NZZ < 5))
{
NZZ++;
LTF[NZZ] = i;
}
NZag = i;
LZZ[i] = SM[i];
}
}
else
{
if (ZZ == -1)
{
if ((i >= Pos + MainRZZ) && (NZZ < 5))
{
NZZ++;
LTF[NZZ] = i;
}
NZig = i;
LZZ[i] = SM[i];
}
}
}

while ((i < LBZZ) || (NZZ < 5))
{
LZZ[i] = 0;
RBar = i – MainRZZ;
if (RBar < Pos) RBar = Pos;
LBar = i + MainRZZ;
if (i == ArrayMinimum(SM, RBar, LBar – RBar + 1))
{
if ((ZZ == -1) && (SM[i] < SM[NZig]))
{
if ((i >= Pos + MainRZZ) && (NZZ < 5)) LTF[NZZ] = i;
LZZ[NZig] = 0;
LZZ[i] = SM[i];
NZig = i;
}
if (ZZ == 1)
{
if ((i >= Pos + MainRZZ) && (NZZ < 5))
{
NZZ++;
LTF[NZZ] = i;
}
LZZ[i] = SM[i];
ZZ = -1;
NZig = i;
}
}
if (i == ArrayMaximum(SM, RBar, LBar – RBar + 1))
{
if ((ZZ == 1) && (SM[i] > SM[NZag]))
{
if ((i >= Pos + MainRZZ) && (NZZ < 5)) LTF[NZZ] = i;
LZZ[NZag] = 0;
LZZ[i] = SM[i];
NZag = i;
}
if (ZZ == -1)
{
if ((i >= Pos + MainRZZ) && (NZZ < 5))
{
NZZ++;
LTF[NZZ] = i;
}
LZZ[i] = SM[i];
ZZ = 1;
NZag = i;
}
}
i++;
if (i > MaxBar) return;
}
nLBZZ = bars – LTF[5];
LZZ[Pos] = SM[Pos];
}

void SZZCalc(const int Pos, const int bars, const double& Open[])
{
int i, RBar, LBar, ZZ = 0, NZZ, NZig, NZag;
i = Pos – 1;
NZig = 0;
NZag = 0;
while ((i <= LBZZ) && (ZZ == 0))
{
i++;
pDn[i] = 0;
pUp[i] = 0;
Dn[i] = 0;
Up[i] = 0;
Lmt[i] = 0;
RBar = i – SRZZ;
if (RBar < Pos) RBar = Pos;
LBar = i + SRZZ;
if (i == ArrayMinimum(SM, RBar, LBar – RBar + 1))
{
ZZ = -1;
NZig = i;
}
if (i == ArrayMaximum(SM, RBar, LBar – RBar + 1))
{
ZZ = 1;
NZag = i;
}
}
if (ZZ == 0) return;

NZZ = 0;
if (i > Pos)
{
if (SM[i] > SM[Pos])
{
if (ZZ == 1)
{
if ((i >= Pos + SRZZ) && (NZZ < 4))
{
NZZ++;
STF[NZZ] = i;
}
NZag = i;
Dn[i – 1] = Open[i – 1];
}
}
else
{
if (ZZ == -1)
{
if ((i >= Pos + SRZZ) && (NZZ < 4))
{
NZZ++;
STF[NZZ] = i;
}
NZig = i;
Up[i – 1] = Open[i – 1];
}
}
}
while ((i <= LBZZ) || (NZZ < 4))
{
pDn[i] = 0;
pUp[i] = 0;
Dn[i] = 0;
Up[i] = 0;
Lmt[i] = 0;
RBar = i – SRZZ;
if (RBar < Pos) RBar = Pos;
LBar = i + SRZZ;
if (i == ArrayMinimum(SM, RBar, LBar – RBar + 1))
{
if ((ZZ == -1) && (SM[i] < SM[NZig]))
{
if ((i >= Pos + SRZZ) && (NZZ < 4)) STF[NZZ] = i;
Up[NZig – 1] = 0;
Up[i – 1] = Open[i – 1];
NZig = i;
}
if (ZZ == 1)
{
if ((i >= Pos + SRZZ) && (NZZ < 4))
{
NZZ++;
STF[NZZ] = i;
}
Up[i – 1] = Open[i – 1];
ZZ = -1;
NZig = i;
}
}
if (i == ArrayMaximum(SM, RBar, LBar – RBar + 1))
{
if ((ZZ == 1) && (SM[i] > SM[NZag]))
{
if ((i >= Pos + SRZZ) && (NZZ < 4)) STF[NZZ] = i;
Dn[NZag – 1] = 0;
Dn[i – 1] = Open[i – 1];
NZag = i;
}
if (ZZ == -1)
{
if ((i >= Pos + SRZZ) && (NZZ < 4))
{
NZZ++;
STF[NZZ] = i;
}
Dn[i – 1] = Open[i – 1];
ZZ = 1;
NZag = i;
}
}
i++;
if (i > LBZZ) return;
}
nSBZZ = bars – STF[4];
}

void ArrCalc(const double& Open[])
{
int i, j, k, n, z = 0;
double p;
i = LBZZ;
while (LZZ[i] == 0) i–;
j = i;
p = LZZ[i];
i–;
while (LZZ[i] == 0) i–;

if (LZZ[i] > p) z = 1;
if ((LZZ[i] > 0) && (LZZ[i] < p)) z = -1;
p = LZZ[j];
i = j – 1;
while (i > 0)
{
if (LZZ[i] > p)
{
z = -1;
p = LZZ[i];
}
if ((LZZ[i] > 0) && (LZZ[i] < p))
{
z = 1;
p = LZZ[i];
}
if ((z > 0) && (Dn[i] > 0))
{
Lmt[i] = Open[i];
Dn[i] = 0;
}
if ((z < 0) && (Up[i] > 0))
{
Lmt[i] = Open[i];
Up[i] = 0;
}
if ((z > 0) && (Up[i] > 0))
{
if (i > 1)
{
j = i – 1;
k = j – SRZZ + 1;
if (k < 0) k = 0;
n = j;
while ((n >= k) && (Dn[n] == 0))
{
pUp[n] = Up[i];
pDn[n] = 0;
n–;
}
}
if (i == 1) pUp[0] = Up[i];
}
if ((z < 0) && (Dn[i] > 0))
{
if (i > 1)
{
j = i – 1;
k = j – SRZZ + 1;
if (k < 0) k = 0;
n = j;
while ((n >= k) && (Up[n] == 0))
{
pDn[n] = Dn[i];
pUp[n] = 0;
n–;
}
}
if (i == 1) pDn[0] = Dn[i];
}
i–;
}
}

int OnInit()
{
SetIndexBuffer(0, Lmt, INDICATOR_DATA);
PlotIndexSetInteger(0, PLOT_ARROW, 167);
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0);
ArraySetAsSeries(Lmt, true);

SetIndexBuffer(1, LZZ, INDICATOR_DATA);
if (DrawZZ)
{
PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_SECTION);
PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, 0);
}
else PlotIndexSetInteger(1, PLOT_DRAW_TYPE, DRAW_NONE);
ArraySetAsSeries(LZZ, true);

SetIndexBuffer(2, Up, INDICATOR_DATA);
PlotIndexSetInteger(2, PLOT_ARROW, 233); // Green up arrow
PlotIndexSetDouble(2, PLOT_EMPTY_VALUE, 0);
ArraySetAsSeries(Up, true);

SetIndexBuffer(3, Dn, INDICATOR_DATA);
PlotIndexSetInteger(3, PLOT_ARROW, 234); // Green up arrow
PlotIndexSetDouble(3, PLOT_EMPTY_VALUE, 0);
ArraySetAsSeries(Dn, true);

SetIndexBuffer(4, pUp, INDICATOR_DATA);
PlotIndexSetInteger(4, PLOT_ARROW, 104); // Green up markers
PlotIndexSetDouble(4, PLOT_EMPTY_VALUE, 0);
ArraySetAsSeries(pUp, true);

SetIndexBuffer(5, pDn, INDICATOR_DATA);
PlotIndexSetInteger(5, PLOT_ARROW, 104); // Red down markers
PlotIndexSetDouble(5, PLOT_EMPTY_VALUE, 0);
ArraySetAsSeries(pDn, true);

SetIndexBuffer(6, SA, INDICATOR_CALCULATIONS);
ArraySetAsSeries(SA, true);
SetIndexBuffer(7, SM, INDICATOR_CALCULATIONS);
ArraySetAsSeries(SM, true);

if (SR < 2) SR = 2;
if (SRZZ <= SR)
{
Alert(“SRZZ should be greater than SR (“, SR, “)”);
return(INIT_FAILED);
}

switch(PriceConst)
{
case PRICE_CLOSE:
handle_ma = iMA(NULL, 0, SR + 1, 0, MODE_LWMA, PRICE_CLOSE);
break;
case PRICE_OPEN:
handle_ma = iMA(NULL, 0, SR + 1, 0, MODE_LWMA, PRICE_OPEN);
break;
case PRICE_HIGH:
handle_ma = iMA(NULL, 0, SR + 1, 0, MODE_LWMA, PRICE_HIGH);
break;
case PRICE_LOW:
handle_ma = iMA(NULL, 0, SR + 1, 0, MODE_LWMA, PRICE_LOW);
break;
case PRICE_MEDIAN:
handle_ma = iMA(NULL, 0, SR + 1, 0, MODE_LWMA, PRICE_MEDIAN);
break;
case PRICE_TYPICAL:
handle_ma = iMA(NULL, 0, SR + 1, 0, MODE_LWMA, PRICE_TYPICAL);
break;
case PRICE_WEIGHTED:
handle_ma = iMA(NULL, 0, SR + 1, 0, MODE_LWMA, PRICE_WEIGHTED);
break;
default:
handle_ma = iMA(NULL, 0, SR + 1, 0, MODE_LWMA, PRICE_OPEN);
}

return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime& time[],
const double& Open[],
const double& High[],
const double& Low[],
const double& Close[],
const long& tick_volume[],
const long& volume[],
const int& spread[])
{
ArraySetAsSeries(Open, true);
ArraySetAsSeries(High, true);
ArraySetAsSeries(Low, true);
ArraySetAsSeries(Close, true);

int counted_bars = prev_calculated > 0 ? prev_calculated – 1 : 0;
int limit, i;
if (counted_bars < 0) return(-1);
if (counted_bars > 0) counted_bars–;
if (First)
{
if (rates_total <= 2 * (MainRZZ + FP + SR + 2)) return(-1);
MaxBar = rates_total – (MainRZZ + FP + SR + 2);
LBZZ = MaxBar;
SBZZ = LBZZ;
prevBars = rates_total;
First = false;
}
limit = rates_total – counted_bars;
if (limit >= rates_total – (2 * SR + 2)) limit = rates_total – 1 – (2 * SR + 2);

for (i = limit; i >= 0; i–)
{
MainCalculation(i, rates_total, Open, High, Low, Close);
}
if (prevBars != rates_total)
{
SBZZ = rates_total – nSBZZ;
LBZZ = rates_total – nLBZZ;
prevBars = rates_total;
}
SZZCalc(0, rates_total, Open);
LZZCalc(0, rates_total);
ArrCalc(Open);

return(rates_total);
}
//+——————————————————————+

如果你对文件有了解,请帮助投票!

If you are familiar with the file, please help vote!

平均评分 0 / 5. 投票数: 0

到目前为止还没有投票!成为第一位投票人。

相关资源

暂无评论

none
暂无评论...