#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Red
#define SIGNAL_BAR 1
extern int KPeriod = 3;
extern int DPeriod = 3;
extern int Slowing = 1;
extern int UpLevel=80;
extern int DnLevel=20;
double b0[];
double b1[];
double b2[];
double b3[];
double b4[];
double b5[];
double b6[];
int A = 0;
int B = 0;
int init() {
IndicatorBuffers(7);
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0,b0);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,b1);
SetIndexBuffer(2,b2);
SetIndexBuffer(3,b3);
SetIndexBuffer(4,b4);
SetIndexBuffer(5,b5);
SetIndexBuffer(6,b6);
string sto = "Binary STO(" + KPeriod + "," + DPeriod + "," + Slowing + ")";
IndicatorShortName(sto);
SetIndexLabel(0,sto);
SetIndexLabel(1,"Signal");
A = KPeriod + Slowing;
B = A + DPeriod;
SetIndexDrawBegin(0,A);
SetIndexDrawBegin(1,B);
return (0);
}
int start() {
double Ld_12;
double ima;
double Ld_28;
double Ld_36;
int counted_bars = IndicatorCounted();
if (Bars <= B)
return (0);
if (counted_bars < 1) {
for (int i = 1; i <= A; i++)
b0[Bars - i] = 0;
for (i = 1; i <= B; i++)
b1[Bars - i] = 0;
}
i = Bars - KPeriod;
if (counted_bars > KPeriod)
i = Bars - counted_bars - 1;
while (i >= 0) {
Ld_28 = 1000000;
for (int Li_4 = i + KPeriod - 1;
Li_4 >= i; Li_4--) {
Ld_12 = Low[Li_4];
if (Ld_28 > Ld_12)
Ld_28 = Ld_12;
}
b3 = Ld_28;
i--;
}
i = Bars - KPeriod;
if (counted_bars > KPeriod)
i = Bars - counted_bars - 1;
while (i >= 0) {
Ld_36 = -1000000;
for (Li_4 = i + KPeriod - 1;
Li_4 >= i;
Li_4--) {
Ld_12 = High[Li_4];
if (Ld_36 < Ld_12)
Ld_36 = Ld_12;
}
b2 = Ld_36;
i--;
}
i = Bars - A;
if (counted_bars > A)i = Bars - counted_bars - 1;
while (i >= 0) {
if (!f0_0(b2 - b3, 0.0))
b4 = 100.0 * ((Close - b3) / (b2 - b3));
i--;
}
if (counted_bars > 0) counted_bars--;
int Li_44 = Bars - counted_bars;
for (i = 0; i< Li_44; i++)
b5 = iMAOnArray(b4, Bars, Slowing, 0, MODE_SMA, i);
for (i = 0; i < Li_44; i++) {
ima = iMAOnArray(b5, Bars, Slowing, 0, MODE_SMA,i);
b0 = b5 + b5 - ima;
}
for (i = 0; i < Li_44; i++)
b6 = iMAOnArray(b0, Bars, DPeriod, 0, MODE_SMA,i);
for (i = 0; i < Li_44; i++) {
ima = iMAOnArray(b6, Bars, DPeriod, 0, MODE_SMA,i);
b1 = b6 + b6 - ima;
}
return (0);
}
bool f0_0(double Ad_0, double Ad_8) {
bool bool_16 = NormalizeDouble(Ad_0 - Ad_8, 8) == 0.0;
return (bool_16);
}