Hi All,
I've ran into an issue with my code. By design, my code repaints however I need to hold the value of the prior occurrence. In particular, the code below is what I need help with. Is there a way to record the values of AP1_ReversingDown1ago and AP1_ReversingDown before they repaint?
Thanks in advance as always!
def AP1_ReversingDown = if H_AP1 < HighAfterWeakHighBreak and H_AP1 < AP1_weakhigh and H_AP1 < AP1_stronghigh and H_AP1 < H_AP1[1] and H_AP1[1] < H_AP1[2] and H_AP1[3] < H_AP1[2] then H_AP1[2] else AP1_ReversingDown[1];
def AP1_ReversingDown1ago = if AP1_ReversingDown != AP1_ReversingDown[1] then AP1_ReversingDown[1] else AP1_ReversingDown1ago[1];
* Put the code below on a 1 minute chart.*
I've ran into an issue with my code. By design, my code repaints however I need to hold the value of the prior occurrence. In particular, the code below is what I need help with. Is there a way to record the values of AP1_ReversingDown1ago and AP1_ReversingDown before they repaint?
Thanks in advance as always!
def AP1_ReversingDown = if H_AP1 < HighAfterWeakHighBreak and H_AP1 < AP1_weakhigh and H_AP1 < AP1_stronghigh and H_AP1 < H_AP1[1] and H_AP1[1] < H_AP1[2] and H_AP1[3] < H_AP1[2] then H_AP1[2] else AP1_ReversingDown[1];
def AP1_ReversingDown1ago = if AP1_ReversingDown != AP1_ReversingDown[1] then AP1_ReversingDown[1] else AP1_ReversingDown1ago[1];
* Put the code below on a 1 minute chart.*
Code:
##Strat_Market_Structure_Dashboard
declare lower;
input LBPeriod = 6;
input Show1m = yes;
input Show3m = yes;
input Show5m = yes;
input Show15m = yes;
input Show30m = yes;
input Show60m = yes;
input ShowDay = yes;
input ShowPriceLabels = yes; #Hint labels show for the current chart's TF
def AP1 = AggregationPeriod.MIN;
def AP2 = AggregationPeriod.THREE_MIN;
def AP3 = AggregationPeriod.FIVE_MIN;
def AP4 = AggregationPeriod.FIFTEEN_MIN;
def AP5 = AggregationPeriod.THIRTY_MIN;
def AP6 = AggregationPeriod.HOUR;
def AP7 = AggregationPeriod.DAY;
def bn = BarNumber();
def dn = Double.NaN;
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then bn else firstBarOfDay[1];
def dayopen = if bn == firstBarOfDay then open else dayopen[1];
def DayTrendLong = close > dayopen;
def DayTrendShort = close < dayopen;
#&&&&&&&&&&&&&&&
### 1m timeframe ###
def tf1m = AggregationPeriod.MIN;
def valid1m = GetAggregationPeriod() <= AggregationPeriod.MIN;
def H_AP1;
def L_AP1;
def O_AP1;
def C_AP1;
if valid1m {
H_AP1 = high (period = tf1m);
L_AP1 = low (period = tf1m);
O_AP1 = open (period = tf1m);
C_AP1 = close(period = tf1m);
} else {
H_AP1 = 0;
L_AP1 = 0;
O_AP1 = 0;
C_AP1 = 0;
}
#&&&&&&&&&&&&&&&
#--------------------------------------------------------------
def HH_AP1 = Highest(H_AP1, LBPeriod);
def LL_AP1 = Lowest(L_AP1, LBPeriod);
#--------------------------------------------------------------
def AP1_marketLow1 = if LL_AP1 < LL_AP1[-LBPeriod] then LL_AP1 else LL_AP1[-LBPeriod];
def AP1_markedLow1 = L_AP1 == AP1_marketLow1;
def AP1_lastMarkedLow1 = CompoundValue(1, if IsNaN(AP1_markedLow1) then AP1_lastMarkedLow1[1] else if AP1_markedLow1 then L_AP1 else AP1_lastMarkedLow1[1], L_AP1);
#--------------------------------------------------------------
def AP1_marketHigh1 = if HH_AP1 > HH_AP1[-LBPeriod] then HH_AP1 else HH_AP1[-LBPeriod];
def AP1_markedHigh1 = H_AP1 == AP1_marketHigh1;
def AP1_lastMarkedHigh1 = CompoundValue(1, if IsNaN( AP1_markedHigh1) then AP1_lastMarkedHigh1[1] else if AP1_markedHigh1 then H_AP1 else AP1_lastMarkedHigh1[1], H_AP1);
#--------------------------------------------------------------
def AP1_Support1 = AP1_lastMarkedLow1 ;
def AP1_stronglow = if AP1_Support1 < AP1_Support1[1] then L_AP1 else AP1_stronglow[1];
def AP1_weaklow = if L_AP1 > AP1_stronglow and AP1_Support1 != AP1_stronglow then AP1_Support1 else AP1_weaklow[1];
def AP1_BrkoMStructureBullish = DayTrendLong and low < AP1_stronglow;
def AP1_PullbackBullish = DayTrendLong and low < AP1_weaklow and low > AP1_stronglow;
def AP1_Resistance1 = AP1_lastMarkedHigh1;
def AP1_strongHigh = if AP1_Resistance1 > AP1_Resistance1[1] then H_AP1 else AP1_strongHigh[1];
def AP1_weakHigh = if H_AP1 < AP1_strongHigh and AP1_Resistance1 != AP1_strongHigh then AP1_Resistance1 else AP1_weakHigh[1];
def AP1_BrkoMStructureBearish = DayTrendShort and high > AP1_strongHigh;
def AP1_PullbackBearish = DayTrendShort and high > AP1_weakHigh and high < AP1_strongHigh;
def AP1_weakhighBN = if H_AP1 == AP1_weakHigh then bn else AP1_weakhighBN[1];
def AP1_TTOlowbreak = if bn > AP1_weakhighBN then Lowest(L_AP1) else AP1_TTOlowbreak[1];
def AP1_NearTTOBreakShort = if close < AP1_TTOlowbreak then Double.NaN else DayTrendShort and close < AP1_TTOlowbreak * 1.0015;
def CrossAbove = Crosses(H_AP1, AP1_weakHigh, CrossingDirection.ABOVE);
def HighAfterWeakHighBreak = if bn > AP1_weakhighBN and CrossAbove then Highest(H_AP1) else HighAfterWeakHighBreak[1];
def AP1_ReversingDown = if H_AP1 < HighAfterWeakHighBreak and H_AP1 < AP1_weakhigh and H_AP1 < AP1_stronghigh and H_AP1 < H_AP1[1] and H_AP1[1] < H_AP1[2] and H_AP1[3] < H_AP1[2] then H_AP1[2] else AP1_ReversingDown[1];
def AP1_ReversingDown1ago = if AP1_ReversingDown != AP1_ReversingDown[1] then AP1_ReversingDown[1] else AP1_ReversingDown1ago[1];
def AP1_RevDownOK = DayTrendShort and C_AP1 < AP1_ReversingDown;
###TROUBLESHOOTING LABLES###
addlabel(yes, "In My Favor? : " + AP1_RevDownOK , COLOR.magenta);
addlabel(yes, "Last Peak: " + AP1_ReversingDown, COLOR.cyan);
addlabel(yes, "Previous Peak: " + AP1_ReversingDown1ago, COLOR.green);
#*********************