For practicing purposes I want to create 2 alertconditions inside a pre-made indicator I use, like RSI. I apply it on the 15 minute timeframe. Basically comparing the 10 and 20 period SMA on the 15 minute, 1 hour, and 4 hour timeframes Long alert, if on the 15 minute chart the 10sma > 20 sma, and on the 1hour chart again the 10sma > 20 sma, and on the 4 hour chart again the 10sma > 20 sma.
I want alert in the exact moment when all these conditions are met. But my code is not working properly, I receive alerts even though on the 1hour and 4 hour charts conditions are not met. It is analyzing correctly the conditions on the timeframe I apply it to: 15 minute. But not the higher timeframes: 1hour and 4hour.
Anyone knows why the 1 hour and 4 hour conditions are not working properly?
I tried it with the barmerge.lookahead_off as well.
Do I even need the barmerge.lookahead_on?
oneHourTenSma = request.security(syminfo.tickerid, "60", ta.sma(close, 10), barmerge.gaps_off, barmerge.lookahead_on)
oneHourTwentySma = request.security(syminfo.tickerid, "60", ta.sma(close, 20), barmerge.gaps_off, barmerge.lookahead_on)
fourHourTenSma = request.security(syminfo.tickerid, "240", ta.sma(close, 10), barmerge.gaps_off, barmerge.lookahead_on)
fourHourTwentySma = request.security(syminfo.tickerid, "240", ta.sma(close, 20), barmerge.gaps_off, barmerge.lookahead_on)
Long = fourHourTenSma > fourHourTwentySma and oneHourTenSma > oneHourTwentySma and ta.sma(close, 10) > ta.sma(close, 20)
Short = fourHourTenSma < fourHourTwentySma and oneHourTenSma < oneHourTwentySma and ta.sma(close, 10) < ta.sma(close, 20)
alertcondition(Long, title="Long Signal", message="Long Alert")
alertcondition(Short, title="Short Signal", message="Short Alert")
Can I use the f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)
function to reference previous candles' open and close prices or I have to change it like this?
oneHourPreviousOpen = f_secureSecurity(syminfo.tickerid, "60", open[1])
oneHourPreviousPreviousOpen = f_secureSecurity(syminfo.tickerid, "60", open[2])
oneHourPreviousClose = f_secureSecurity(syminfo.tickerid, "60", close[1])
oneHourPreviousPreviousClose = f_secureSecurity(syminfo.tickerid, "60", close[2])
I would like to set a condition for a lower timeframe's RSI value as well, the 5 minute RSI < 60. Is this how I should define this function for this case?:
f_secureSecurity(_symbol, _res, _src) => request.security_lower_timeframe(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)
Use the f_secureSecurity
function from this library
something like this:
f_secureSecurity(_symbol, _res, _src) =>
request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)
oneHourTenSma = f_secureSecurity(syminfo.tickerid, '60', ta.sma(close, 10))