I am writing an indicator that will mark the last swing low within 100 bars and swing high after it. Right now I have the following code. It kinda outputs what I wanted so far, but the warning on the chart says "Folding: integer 'to' is expected: NaN", which makes me wonder if there is anything wrong I did. Can anyone please help?
Code:
def condition;
def swingLowOffset;
def swingHighOffset;
def swingHigh;
def currentLow; # lowest in the last 3 bars
def currentHigh; # highest in the last 3 bars
if (IsNaN(close[-1] and !IsNaN(close[0]))) {
# Only run this in the last bar.
# Find the lowest bar in the last 100 bars excluding the current 3 bars
swingLowOffset = GetMinValueOffset(low[3], 100) + 3;
currentLow = Lowest(low, 3);
currentHigh = Highest(high, 3);
swingHigh = fold i = 0 to swingLowOffset with tempHigh = high[0] do Max(tempHigh, GetValue(high, i));
swingHighOffset = 0;
if (swingHighOffset == swingLowOffset or swingHighOffset <= 2) {
condition = no;
}
else {
condition = yes;
}
}
else {
condition = no;
swingLowOffset = 0;
swingHighOffset = 0;
swingHigh = 0;
currentLow = 0;
currentHigh = 0;
}
AddChartBubble(1, low, BarNumber(), Color.WHITE, no);
AddChartBubble(swingLowOffset != 0, high, swingLowOffset + ":" + swingHighOffset + ":" + swingHigh, Color.WHITE, no);
plot data = condition;
Last edited: