I am trying to create a Pine script which with alert for an hourly basis - but want to check every hour if daily MACD is more than 40- how can I do that? Below is the script that I created but it is not exeucting - I am not genreating alert as expected.

`// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © hemantsancheti
//@version=5

indicator("Commodities", overlay=true)

//indicator(title="Stochastic", shorttitle="Stoch", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
periodK = input.int(14, title="%K Length", minval=1)
smoothK = input.int(3, title="%K Smoothing", minval=1)
periodD = input.int(3, title="%D Smoothing", minval=1)
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)

timeframe = input.timeframe(defval = "D", title=" select timeframe")
fast_length=input(title = "fast_length", defval = 12)
slow_length=input(title = "slow_length_length", defval = 26)
signal_length=input(title = "signal_smoothing", defval = 9)

fast_ma =ta.sma(close,fast_length)
slow_ma =ta.sma(close,slow_length)
macd= fast_ma - slow_ma
signal= ta.sma(macd, signal_length)

highertfMACD_previouscandle = request.security(syminfo.tickerid,timeframe, macd[1], barmerge.gaps_on, lookahead = barmerge.lookahead_on)

highertimeframeMACD = request.security(syminfo.tickerid,timeframe, macd,gaps= barmerge.gaps_on, lookahead = barmerge.lookahead_on)
highertimeframeSingal = request.security(syminfo.tickerid,timeframe, signal,gaps= barmerge.gaps_on, lookahead = barmerge.lookahead_on)

hist = highertimeframeMACD - highertimeframeSingal

rsi = ta.rsi(close, 14)

stoc_PCO_with_MACD_uptick = k < 30 and  k > d and   highertimeframeMACD > highertimeframeSingal and rsi > 40 and highertimeframeMACD > highertfMACD_previouscandle  
stoc_NCO_with_MACD_downtick = k > 80 and  k < d and   highertimeframeMACD < highertimeframeSingal and rsi < 60 and highertimeframeMACD < highertfMACD_previouscandle  

alertcondition(stoc_PCO_with_MACD_uptick, 'Stoch PCO with MACD uptick', 'commodities -DS - stoch PCO MACD up side-buy ')
alertcondition(stoc_NCO_with_MACD_downtick, 'Stoch NCO with MACD downtick', 'commodities -DS - stoch NCO MACD down side-sell ')
plotchar(k,"stock K", char = "")
plotchar(d,"stock d", char = "")
plotchar(highertimeframeMACD,"highertimeframeMACD", char = "")
plotchar(highertimeframeSingal,"highertimeframeSingal", char = "")
plotchar(rsi,"rsi", char = "")
plotchar(highertfMACD_previouscandle,"highertfMACD_previouscandle", char = "")

Shared in problem details

0

There are 0 best solutions below