nitrotrader
New member
Hello, I'm new to thinkscript and trying to build out a watchlist scanner with visual indicators for 2 criteria...(1) above/between/below the prior days range, and also (2) if price is above/below an hourly EMA. Here is a screenshot of what I'm attempting to visualize but running into issues:
1. Previous Day Range ("PDR")
The code I'm using works as expected, but only during the pre-market session. Once the regular session starts all the values change (I'm sure it has to do with the -1 in the displace input). I'd like this to work so that regardless of premarket/regular session/after hours, it correctly colors.
Here's the code I mismashed together:
2. EMA
Similar to range plot above, I'd like to display green/red if the price is above/below the EMA (hourly, length of 80, on close)
My code isn't even close to working so I'll spare you the headache of troubleshoot my stuff (although I'm sure I'm robbing you of a good laugh). I'm hoping the calculation of above/below an EMA is simple enough to quickly code that out.
Thanks in advance!
1. Previous Day Range ("PDR")
The code I'm using works as expected, but only during the pre-market session. Once the regular session starts all the values change (I'm sure it has to do with the -1 in the displace input). I'd like this to work so that regardless of premarket/regular session/after hours, it correctly colors.
Here's the code I mismashed together:
Code:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = yes;
def PrevDayHigh = Highest(high(period = aggregationPeriod)[-displace], length) ;
def PrevDayLow = Highest(low(period = aggregationPeriod)[-displace], length); ;
def PrevDayClose = Highest(close(period = aggregationPeriod)[-displace], length);
plot pdr = PrevDayHigh;
assignBackgroundColor(if bid > prevDayHigh then Color.GREEN else if bid < prevDayLow then Color.RED else Color.GRAY);
pdr.assignValueColor (if bid > prevDayHigh then Color.GREEN else if bid < prevDayLow then Color.LIGHT_RED else Color.GRAY);
2. EMA
Similar to range plot above, I'd like to display green/red if the price is above/below the EMA (hourly, length of 80, on close)
My code isn't even close to working so I'll spare you the headache of troubleshoot my stuff (although I'm sure I'm robbing you of a good laugh). I'm hoping the calculation of above/below an EMA is simple enough to quickly code that out.
Thanks in advance!