prime90
prime90

Reputation: 959

Color bars on daily chart based on 3hr time frame

I'm trying to color the bars on a daily chart when price is above the 200sma on a 3hr time frame. This is what I have come up with but it doesn't seem to be working. It only highlights when the daily price is above the 200sma and not when the price is above the 200sma on a 3hr chart when looking at a daily chart.

study(title="SMA Gradient Grey", overlay=true)

// Compute SMA
smaValue_30 = sma(close, 30)
smaValue_50 = sma(close, 50)
smaValue_200 = sma(close, 200)

//grabs 3hr 200 day sma
timeFrame = input(title="Other time frame", type=resolution,
     defval="180")

smaClose = sma(security(tickerid, timeFrame, close),
     200)

threehr_price = security(tickerid, timeFrame, close)

semi_grey  = (threehr_price >= smaClose)

// Colour price bars
barColour = (semi_grey) ? #e7e7e7 : na

barcolor(color=barColour)

Upvotes: 0

Views: 96

Answers (1)

AnyDozer
AnyDozer

Reputation: 2568

study(title="SMA Gradient Grey", overlay=true)

// Compute SMA
smaValue_30 = sma(close, 30)
smaValue_50 = sma(close, 50)
smaValue_200 = sma(close, 200)

//grabs 3hr 200 day sma
timeFrame = input(title="Other time frame", type=resolution,
     defval="180")

smaClose = security(tickerid, timeFrame, sma(close,200))

threehr_price = security(tickerid, timeFrame, close) //the price is the same for any timeframe, it can be removed

semi_grey  = (threehr_price >= smaClose)

// Colour price bars
barColour = (semi_grey) ? #e7e7e7 : na

barcolor(color=barColour)

The script has not been tested, but it should work as you need.

Upvotes: 1

Related Questions