new_spy123
New member
Hello All,
I am on a quest to work around the problem of referencing secondary aggregation in scan custom alerts.
What I am trying to solve: Receive alert when hourly candle crosses below 150 day ema in scan alert.
This is what I am doing in the below script without referencing aggregation constants and calculating the ema manually. I feel like I am close but missing something hence the values are not matching. Appreciate any input on this.
Here is the chart, showing the gap with what I am computing vs what the actual value should be.
I am on a quest to work around the problem of referencing secondary aggregation in scan custom alerts.
What I am trying to solve: Receive alert when hourly candle crosses below 150 day ema in scan alert.
This is what I am doing in the below script without referencing aggregation constants and calculating the ema manually. I feel like I am close but missing something hence the values are not matching. Appreciate any input on this.
Ruby:
def smoothing = (2/150 + 1);
def today = GetDay() == GetLastDay();
def ydayClose = if today then ydayClose[1] else close;
input n = 150;
def emaForLast150Days = fold index = 1 to 150 with p = ydayClose do if index == 1 then ydayClose else (smoothing*ydayClose[index] + (1 - smoothing)*p);
plot emaForLast150DaysPlot = if today then emaForLast150Days else close;
Here is the chart, showing the gap with what I am computing vs what the actual value should be.