different moving average without extended hours

Code:
#RTH_EMA_withExtendedHoursON
#20180104 BLT
#Used code for Pivots based upon RTHs only with extended hours on chart to make a moving average of just RTH's on chart with extended hours on chart

input rthstart   = 0930; #Allows the first candle to form befor determining direction
input rthend     = 1600;
def active       = if SecondsFromTime(rthstart) >= 0 and SecondsTillTime(rthend) > 0
                   then 1
                   else 0;
def activeclose   = if active
                   then close else activeclose[1];

plot RTH_ema      = expaverage(activeclose,9);

Code:
input price = close;
input length = 9;
input aggregationPeriod = AggregationPeriod.FIVE_MIN;


def MyPrice = ExpAverage(close(period = AggregationPeriod), 1);
plot AvgExp = ExpAverage(myprice, length);

AvgExp.SetDefaultColor(GetColor(1));

I have code for showing 5 minute time frame ema on a 1 min chart. to save space.
also a code found in this forum for ema excluding extended hour.
yet i still want to see extended hour price action.
is there anyone can help to combine them 2 to get a

1.different time frame ema
2. exclude extended hours
3. able to see extended hour price action.

thanks a lot
 
Code:
input aggregationPeriod = AggregationPeriod.FIVE_MIN;
input AvgType = averageType.EXPONENTIAL;
input price = close;

input length = 9;
input rthstart   = 0930; #Allows the first candle to form befor determining direction
input rthend     = 1600;
def active       = if SecondsFromTime(rthstart) >= 0 and SecondsTillTime(rthend) > 0
                   then 1
                   else 0;

def activeclose   = if active
                   then close(period = aggregationPeriod) else activeclose[1];



plot AVG = MovingAverage(AvgType, activeclose, Length);
AVG.setdefaultcolor(color.yellow);

Any help ?
thank you. the result produced seem off.
 
Code:
input aggregationPeriod = AggregationPeriod.FIVE_MIN;
input AvgType = averageType.EXPONENTIAL;
input price = close;

input length = 9;
input rthstart   = 0930; #Allows the first candle to form befor determining direction
input rthend     = 1600;
def active       = if SecondsFromTime(rthstart) >= 0 and SecondsTillTime(rthend) > 0
                   then 1
                   else 0;

def activeclose   = if active
                   then close(period = aggregationPeriod) else activeclose[1];



plot AVG = MovingAverage(AvgType, activeclose, Length);
AVG.setdefaultcolor(color.yellow);

Any help ?
thank you. the result produced seem off.

your formula uses
else activeclose[1];
so in the first few bars of the day, it is using many copies of the same number, which will throw off the average.

so with a length of 9, the first 7 bars of the day will have at least 1 repeat price, instead of pulling multiple prices from the end of the previous day.

if you want an average , using just prices from normal trading hours, while skipping over after hours, that will be tricky.
after hours will always have a different quantity of bars.
will have to figure out how to save the last 'length' bar prices from the end of each day. then combine those price with some prices from the start of the next day, to calculate an average.

i'm experimenting , but no guarantees...
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
326 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top