Hi All,
Anytime a condition is met, I'm trying to calculate a value which I want to add on top of the prior value. I am able to get this to work with using counter[1] + 1 else counter[1] however I want the + 1 to be a variable instead of the constant 1. In my code below, the code is not adding the variable to the prior but instead just using the last value it found. Can anyone advise what I may be missing so that the yellow bubbles are adding on top of the prior values? Thanks!!
Anytime a condition is met, I'm trying to calculate a value which I want to add on top of the prior value. I am able to get this to work with using counter[1] + 1 else counter[1] however I want the + 1 to be a variable instead of the constant 1. In my code below, the code is not adding the variable to the prior but instead just using the last value it found. Can anyone advise what I may be missing so that the yellow bubbles are adding on top of the prior values? Thanks!!
Code:
def H = high;
def L = low;
def C = close;
def O = open;
input WillingToLose = 10;
input InitialStopLoss_Pct = .3;
def spread = close(priceType = PriceType.ASK) - close(priceType = PriceType.BID);
def Stop_Calc = ((InitialStopLoss_Pct / 100) + 1) * close - close + spread;
def SharesCalc = WillingToLose / Stop_Calc;
def insidebar = (H <= H[1] and L >= L[1]);
def twodown = H <= H[1] and L < L[1];
def Cross_Up = H > H[1];
def Mag_UP = H >= H[2];
def Two_One_UP = twodown[2] and insidebar[1] and Cross_Up;
def Two_One_Up_Mag_FTCUp = if Two_One_UP and Mag_UP then Two_One_Up_Mag_FTCUp[1] + 1 else Two_One_Up_Mag_FTCUp[1];
def total21up = if Two_One_UP and Mag_UP then total21up[1] + (H[2] - H[1]) else total21up[1];
def avgmag21u = total21up / Two_One_Up_Mag_FTCUp;
AddLabel(yes, "avg mag " + Round(avgmag21u), Color.GREEN);
AddLabel(yes, "total " + total21up, Color.GREEN);
AddLabel(yes, "count " + Two_One_Up_Mag_FTCUp, Color.GREEN);
AddChartBubble(if Two_One_UP and Mag_UP then H[2] - H[1] else Double.NaN, low, total21up, Color.yellow);
AddLabel(yes, " avg profit " + avgmag21u * SharesCalc + " | " + SharesCalc, Color.GREEN);