50% candle time frame

airgb

Member
I have a TOS indicator (I made) I would like someone to take a look at that paints a horizonal line next to the prior time frame candle which gives the 50% mark of that candle. This indicator only gives what ever time period the current chart is in (if time is changed the line will update to what ever time frame is selected). What I wish is that this indicator allowed for time frames to be locked in so if I am on a 30m chart and I change it to a 15m chart it still shows the 30m line plus the new 15m line). I have uploaded two images which highlight what I am looking for. The TOS image shows what my indicator shows and the Tradingview image shows their indicators which I have set up to give the results I am seeking on TOS. On the TV setup I have three of the same indicators loaded but set to the different timeframes I desire. That's exactly what I wish for with TOS. The script for my indicator is also posted below. Thank you for any help.
EqCeKft.png

XzddJY1.png


Here's the code:
addlabel(1,round(low[1]),color.red);
addlabel(1,round(hl2[1]),color.white);
addlabel(1,round(high[1]),color.light_green);
plot line = if !isnan(close) and isnan(close[-2000]) then HL2[1] else double.nan;
line.setpaintingstrategy(paintingstrategy.horizontal);
line.setlineweight(2);
line.setdefaultcolor(color.red);

Alert(close crosses line, "HL2 Cross", alert.bar, sound.ding);
 
Solution
I have a TOS indicator (I made) I would like someone to take a look at that paints a horizonal line next to the prior time frame candle which gives the 50% mark of that candle. This indicator only gives what ever time period the current chart is in (if time is changed the line will update to what ever time frame is selected). What I wish is that this indicator allowed for time frames to be locked in so if I am on a 30m chart and I change it to a 15m chart it still shows the 30m line plus the new 15m line). I have uploaded two images which highlight what I am looking for. The TOS image shows what my indicator shows and the Tradingview image shows their indicators which I have set up to give the results I am seeking on TOS. On...
I have a TOS indicator (I made) I would like someone to take a look at that paints a horizonal line next to the prior time frame candle which gives the 50% mark of that candle. This indicator only gives what ever time period the current chart is in (if time is changed the line will update to what ever time frame is selected). What I wish is that this indicator allowed for time frames to be locked in so if I am on a 30m chart and I change it to a 15m chart it still shows the 30m line plus the new 15m line). I have uploaded two images which highlight what I am looking for. The TOS image shows what my indicator shows and the Tradingview image shows their indicators which I have set up to give the results I am seeking on TOS. On the TV setup I have three of the same indicators loaded but set to the different timeframes I desire. That's exactly what I wish for with TOS. The script for my indicator is also posted below. Thank you for any help.
EqCeKft.png

XzddJY1.png


Here's the code:
addlabel(1,round(low[1]),color.red);
addlabel(1,round(hl2[1]),color.white);
addlabel(1,round(high[1]),color.light_green);
plot line = if !isnan(close) and isnan(close[-2000]) then HL2[1] else double.nan;
line.setpaintingstrategy(paintingstrategy.horizontal);
line.setlineweight(2);
line.setdefaultcolor(color.red);

Alert(close crosses line, "HL2 Cross", alert.bar, sound.ding);

This has 3 line plots.

The default Line uses the Chart Timeframe's aggregation period as it's basis.
Line1 is user defined aggregation period at input agg1
Line2 is user defined aggregation period at input agg2

The last lines for each are extended to the right edge of the chart

Screenshot-2022-12-19-080044.png
Ruby:
AddLabel(1, Round(low[1]), Color.RED);
AddLabel(1, Round(hl2[1]), Color.WHITE);
AddLabel(1, Round(high[1]), Color.LIGHT_GREEN);

#Chart Timeframe
def ln0   = if IsNaN(close) then ln0[1]
            else if !IsNaN(close) and IsNaN(close[-2000])
            then HL2[1]
            else Double.NaN;
plot line = ln0;
line.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
line.SetLineWeight(2);
line.SetDefaultColor(Color.YELLOW);

Alert(close crosses line, "HL2 Cross", Alert.BAR, Sound.Ding);

#Aggregation Input #1
input agg1 = AggregationPeriod.THIRTY_MIN;
def  ln1   = if IsNaN(close) then ln1[1]
             else if !IsNaN(close) and IsNaN(close[-2000])
             then hl2(period = agg1)[1]
             else Double.NaN;
plot line1 = ln1;
line1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
line1.SetLineWeight(2);
line1.SetDefaultColor(Color.CYAN);

Alert(close crosses line1, "HL2 Cross", Alert.BAR, Sound.Ding);

#Aggregation Input #2
input agg2 = AggregationPeriod.HOUR;
def  ln2   = if IsNaN(close) then ln2[1]
             else if !IsNaN(close) and IsNaN(close[-2000])
             then hl2(period = agg2)[1]
             else Double.NaN;
plot line2 = ln2;
line2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
line2.SetLineWeight(2);
line2.SetDefaultColor(Color.RED);

Alert(close crosses line2, "HL2 Cross", Alert.BAR, Sound.Ding);
 
Solution
Outstanding SleepyZ. This is exactly want I wanted but I just could not get it to work with the Condition Wizard. I really appreciate you taking your time to write this for me. You may have noticed that the Tradingview copy also paints the line off the current candle all the way to the right. Is there any option to stop this and have it print the shorter line like the candle before?
 

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
493 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