Hello everyone,
I’m looking to apply the ‘HalfTrend’ indicator on a normal candlestick chart using Heikin Ashi data to generate buy/sell signals. Specifically, I want to use the ‘open/high/low/close’ data from Heikin Ashi charts to calculate the signals, but have them displayed on a normal candlestick chart.
While the following script works fine without the ‘HAdata’ parameter, it fails to work when I use the ‘request.security’ function to obtain the Heikin Ashi data with ‘HAdata’ set to true.
Could someone please help me identify the issue?
//@version=5
indicator(“Uncle-script”)
isHA = input.bool(true, “HA Candles”)
HAdata = isHA ? ticker.heikinashi(syminfo.tickerid) : syminfo.tickerid
HAopen = request.security(HAdata, timeframe.period, open)
HAhigh = request.security(HAdata, timeframe.period, high)
HAlow = request.security(HAdata, timeframe.period, low)
HAclose = request.security(HAdata, timeframe.period, close)
var int trend = 0
var int nextTrend = 0
var float maxLowPrice = nz(HAlow[1], HAlow)
var float minHighPrice = nz(HAhigh[1], HAhigh)
// --------------
var nexttrend1 = 0, nexttrend1if =0
var nexttrend0 = 0, nexttrend0if =0
// --------------
highPrice = HAhigh[math.abs(ta.highestbars(HAhigh,2))]
lowPrice = HAlow[math.abs(ta.lowestbars(HAlow,2))]
highma = ta.sma(HAhigh, 2)
lowma = ta.sma(HAlow, 2)
if nextTrend == 1
maxLowPrice := math.max(lowPrice, maxLowPrice)
// --------------
nexttrend1 := 20
nexttrend1if := 0
nexttrend0 := 0
nexttrend0if := 0
if highma < maxLowPrice and HAclose < nz(HAlow[1], HAlow)
trend := 1
nextTrend := 0
minHighPrice := highPrice
// --------------
nexttrend1if := 15
else
minHighPrice := math.min(highPrice, minHighPrice)
// --------------
nexttrend1 := 0
nexttrend1if := 0
nexttrend0 := 10
nexttrend0if := 0
// --------------
if lowma > minHighPrice and HAclose > nz(HAhigh[1], HAhigh)
trend := 0
nextTrend := 1
maxLowPrice := lowPrice
// --------------
nexttrend0if := 5
plot(HAopen, title=‘HAopen’, color=color.black)
plot(HAhigh, title=‘HAhigh’, color=color.black)
plot(HAlow, title=‘HAlow’, color=color.black)
plot(HAclose, title=‘HAclose’, color=color.green, linewidth=3)
plot(highPrice, title=‘highPrice’, color=color.navy)
plot(lowPrice, title=‘lowPrice’, color=color.navy)
plot(lowma, title=‘lowma’, color=color.blue)
plot(highma, title=‘highma’, color=color.blue)
plot(nexttrend1),plot(nexttrend1if),plot(nexttrend0),plot(nexttrend0if)
plot(maxLowPrice),plot(minHighPrice)