Here is the description: https://www.multicharts.com/support/base/predictors-gt-zero-balance/
There is a TOS version of it, but I don't know if it is correct or not: https://tos.mx/JsVskf
There is a TOS version of it, but I don't know if it is correct or not: https://tos.mx/JsVskf
Ruby:
#Predict - Zero Balance type:
#0 - Current Zero Balance
#1 - Tomorrow's Zero Balance
#2 - Zero Balance 2 day forcast
input Predict = 0;
input Labels = Yes;
input Debug1 = no;
input Debug2 = no;
input Debug3 = yes;
def Length = 7;
def na = Double.NaN;
#################################################################################
# Simple array
def data1;
def data2;
def data3;
def data4;
def data5;
def data6;
def data7;
def data8;
################################################################################
def IRHIGH;
def IRLOW;
def IRHIGHBAR;
def IRLOWBAR;
def HIGHBAR;
def LOWBAR;
def ZEROBAL;
def ZEROBAL1;
def ZEROBAL2;
def OFFSET;
def OFFSET2;
def condition1;
def condition2;
def BN = BarNumber();
################################################################################
if BN > Length
then {
condition1 = if high > Highest(high, Length)[1] then 1 else 0;
condition2 = if low < Lowest(low, Length)[1] then 1 else 0;
}
else {
condition1 = 0;
condition2 = 0;
};
#################################################################################
script LowLogic {
input BN = 1;
input IRHighBar = 1;
input Offset = 1;
def L = low;
def Length = BN - IRHighBar + Offset;
def L2 = fold i = 1 to Length
with p
do if p > (GetValue( L, i, 0)) or p == 0
then low else p;
def Bar = fold i2 = 1 to Length
with p2
do if p2 > (GetValue( L, i2, 0)) or p2 == 0
then BN - i2 else p2;
plot TheLow = L2;
plot TheBar = Bar;
} # End script
##################################################################################
script HighLogic {
input BN = 1;
input IRLOWBar = 1;
input Offset = 1;
def H = High;
def Length = BN - IRLOWBar + Offset;
def H2 = fold i3 = 1 to Length
with p3
do if p3 < (GetValue( H, i3, 0))
then H else p3;
def Bar = fold i4 = 1 to Length
with p4
do if p4 < (GetValue( H, i4, 0))
then BN - i4 else p4;
plot TheHigh = H2;
plot TheBar = Bar;
} # End script
##################################################################################
def FLAG = if BN <= Length then 1
else if condition1 == 1 and FLAG[1] == 1 then 2
else if condition2 == 1 and FLAG[1] == 2 then 1
else FLAG[1];
Offset = Offset2[1];
if condition1 == 1 and FLAG == 2
then {
IRLOWBAR = BN;
LOWBAR = LowLogic(BN, IRHighBar, Offset).TheBar;
IRLOW = LowLogic(BN, IRHighBar, Offset).TheLow;
IRHighBar = IRHighBar[1];
HIGHBAR = HIGHBAR[1];
IRHIGH = IRHIGH[1];
Offset2 = LOWBAR;
}
else if condition2 == 1 and FLAG == 1
then {
IRLOWBAR = IRLOWBAR[1];
LOWBAR = LOWBAR[1];
IRLOW = IRLOW[1];
IRHighBar = BN;
HIGHBAR = HighLogic(BN, IRLOWBar, Offset).TheBar;
IRHIGH = HighLogic(BN, IRLOWBar, Offset).TheHigh;
Offset2 = HIGHBAR;
}
else {
IRLOWBAR = IRLOWBAR[1];
LOWBAR = LOWBAR[1];
IRLOW = IRLOW[1];
IRHighBar = IRHighBar[1];
HIGHBAR = HIGHBAR[1];
IRHIGH = IRHIGH[1];
Offset2 = 0;
};
if FLAG != FLAG[1]
then {
data1 = data2[1];
data2 = data3[1];
data3 = data4[1];
data4 = data5[1];
data5 = data6[1];
data6 = data7[1];
data7 = data8[1];
data8 = data8[1];
}
else if FLAG == 2
then {
data1 = data1[1];
data2 = data2[1];
data3 = data3[1];
data4 = data4[1];
data5 = data5[1];
data6 = data6[1];
data7 = data7[1];
data8 = IRLOW;
}
else {
data1 = data1[1];
data2 = data2[1];
data3 = data3[1];
data4 = data4[1];
data5 = data5[1];
data6 = data6[1];
data7 = data7[1];
data8 = IRHIGH;
};
if data1 != 0
then {
ZEROBAL = data6 + data5 - data3;
ZEROBAL1 = data7 + data6 - data4;
ZEROBAL2 = data8 + data7 - data5;
}
else {
ZEROBAL = ZEROBAL[1];
ZEROBAL1 = ZEROBAL1[1];
ZEROBAL2 = ZEROBAL2[1];
};
#plot IrLowP = if IRLOW != 0 then IRLOW else na;
plot IrLowP = if GetValue(IRLOW,Lowbar) != 0
then GetValue(IRLOW,Lowbar)
else na;
IrLowP.SetDefaultColor(Color.Green);
#plot LowBarP = LOWBAR;
plot IrHighP = if GetValue(IRHIGH,HighBar) != 0
then GetValue(IRHIGH,HighBar)
else na;
IrHighP.SetDefaultColor(Color.red);
def Plot3 = if Predict == 0 then GetValue(ZEROBAL,OffSet2)
else if Predict == 1 then GetValue(ZEROBAL1,OffSet2)
else if Predict == 2 then GetValue(ZEROBAL2,OffSet2)
else GetValue(ZEROBAL,OffSet2);
plot PredictP = if Plot3 != 0 then Plot3 else na;
PredictP.SetDefaultColor(Color.Yellow);
###############################################################################
# Debug labels and plots to the end of study
###############################################################################
AddLabel(1,"IRLOW", Color.Green);
AddLabel(1,"IRHIGH", Color.Red);
AddLabel(1,"Predict", Color.Yellow);
plot ValuesAbove = if Debug1 then Condition1 else na;
ValuesAbove.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
plot ValuesBelow = if Debug1 then Condition2 else na;
ValuesBelow.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
plot ValuesAbove2 = if Debug2 then flag else na;
ValuesAbove2.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
plot ValuesBelow2 = if Debug2 then Offset else na;
ValuesBelow2.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
plot ValuesAbove3 = if Debug3 then IRHigh else na;
ValuesAbove3.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
plot ValuesBelow3 = if Debug3 then IRLowP else na;
ValuesBelow3.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
AddLabel(Labels, data1,color.cyan);
AddLabel(Labels, data2,color.cyan);
AddLabel(Labels, data3,color.cyan);
AddLabel(Labels, data4,color.cyan);
AddLabel(Labels, data5,color.cyan);
AddLabel(Labels, data6,color.cyan);
AddLabel(Labels, data7,color.cyan);
AddLabel(Labels, data8,color.cyan);
Last edited by a moderator: