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.
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: