Plot lines and bubbles not displaying correctly

jrwlkr

New member
I've put together this code from several samples I found here, but it's not quite working correctly. I know I've seen this before but can't quite get how to fix it. The plot lines do not start at 9:30 but premkt and at 0. Also when I try to display the bubble it creates one for each bar instead of just one. I'm also trying to position it about 5min before the open or at least the open. The code is supposed to plot the first 5 and 15min high/lows. it's also not displaying correctly if i'm displaying a timeframe of more than today. Any help would be appreciated. thanks.

Update:
Figured it out myself, so if anyone wants to use it, please go ahead. Only works for 5min and 15min high/lows and you can only set the time frame to 15min or below for them to display at all otherwise they will disappear.

Ruby:
input startTime = 0930;
input FiveminendTime = 0935;
input FifteenminendTime = 0945;
input DisplayTime = {default Day, Everyday};
input ShowChartBubbles = YES;

def bar = BarNumber();
def nan = Double.NaN;

#FIVE MINUTE LINES
def FivemintargetPeriod = SecondsFromTime(startTime) >= 0 and SecondsTillTime(FiveminendTime) > 0;
def FivemintargetPeriodLow = if FivemintargetPeriod and !FivemintargetPeriod[1] then low(period = AggregationPeriod.FIVE_MIN) else if FivemintargetPeriod and low(period = AggregationPeriod.FIVE_MIN) < FivemintargetPeriodLow[1] then low(period = AggregationPeriod.FIVE_MIN) else FivemintargetPeriodLow[1];

def FivemintargetPeriodHigh = if FivemintargetPeriod and !FivemintargetPeriod[1] then high(period = AggregationPeriod.FIVE_MIN) else if FivemintargetPeriod and low(period = AggregationPeriod.FIVE_MIN) < FivemintargetPeriodHigh[1] then high(period = AggregationPeriod.FIVE_MIN) else FivemintargetPeriodHigh[1];


#FIFTEEN MINUTE LINES
def FifteenmintargetPeriod = SecondsFromTime(startTime) >= 0 and SecondsTillTime(FifteenminendTime) > 0;
def FifteenmintargetPeriodHigh = if FivemintargetPeriod and !FifteenmintargetPeriod[1] then high(period = AggregationPeriod.FIFTEEN_MIN) else if FifteenmintargetPeriod and high(period = AggregationPeriod.FIFTEEN_MIN) < FifteenmintargetPeriodHigh[1] then high(period = AggregationPeriod.FIFTEEN_MIN) else FifteenmintargetPeriodHigh[1];

def FifteenmintargetPeriodLow = if FifteenmintargetPeriod and !FifteenmintargetPeriod[1] then low(period = AggregationPeriod.FIFTEEN_MIN) else if FifteenmintargetPeriod and low(period = AggregationPeriod.FIFTEEN_MIN) < FifteenmintargetPeriodHigh[1] then low(period = AggregationPeriod.FIFTEEN_MIN) else FifteenmintargetPeriodLow[1];

#plot lines

#-- define select plot periods
def today = if (GetDay() == GetLastDay()) and (SecondsFromTime(startTime) >= 0) then 1 else 0;

def LinePeriod;

switch (DisplayTime){
case Day:
LinePeriod = today;
case Everyday:
LinePeriod = startTime;
}

#Fivemin
plot FiveMinLow = if LinePeriod != 0 then FivemintargetPeriodLow else nan;
FiveMinLow.SetDefaultColor(Color.LIGHT_ORANGE);
FiveMinLow.SetStyle(Curve.SHORT_DASH);
FiveMinLow.SetLineWeight(4);

plot FiveMinHigh = if LinePeriod != 0 then FivemintargetPeriodHigh else nan;
FiveMinHigh.SetDefaultColor(Color.LIGHT_ORANGE);
FiveMinHigh.SetStyle(Curve.SHORT_DASH);
FiveMinHigh.SetLineWeight(4);

#fifteenMin
plot FifteenMinLow = if LinePeriod != 0 then FifteenmintargetPeriodLow else nan;
FifteenMinLow.SetDefaultColor(Color.LIGHT_ORANGE);
FifteenMinLow.SetStyle(Curve.SHORT_DASH);
FifteenMinLow.SetLineWeight(4);

plot FifteenMinHigh = if LinePeriod != 0 then FifteenmintargetPeriodHigh else nan;
FifteenMinHigh.SetDefaultColor(Color.LIGHT_ORANGE);
FifteenMinHigh.SetStyle(Curve.SHORT_DASH);
FifteenMinHigh.SetLineWeight(4);


#Bubble Placement and Movement------------------------------------
input bubblemover = -5;
def b = bubblemover;
def b1 = b + 1;

input bubblemethod = {default expansionbubbles, rightedgebubbles, leftbubbles};
def bubbletype;
switch (bubblemethod){
case expansionbubbles:
bubbletype = IsNaN(close) and !IsNaN(close[b1]);
case rightedgebubbles:
bubbletype = bar == HighestAll(bar);
case leftbubbles:
bubbletype = bar == HighestAll(bar);
}
#------------------------------------------------------------------------

#AddChartBubble(ShowChartBubbles and bubbletype,
# LinePeriod,
# LinePeriod,
# Color.BLUE,
# 1);

AddChartBubble(ShowChartBubbles and bubbletype,
FifteenMinHigh,
"15mh",
Color.BLUE,
1);

AddChartBubble(ShowChartBubbles and bubbletype,
FifteenMinLow,
"15ml",
Color.BLUE,
0);

AddChartBubble(ShowChartBubbles and bubbletype,
FiveMinHigh,
"5mh",
Color.BLUE,
1);

AddChartBubble(ShowChartBubbles and bubbletype,
FiveMinLow,
"5ml",
Color.BLUE,
0);
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
284 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