Opening Range Breakout Indicator with Fibs

ken_trades

New member
Hi guys, i have a ORB indicator with Fibs, but i need help with adding chart labels on the levels. I tried myself but it showed me this many chart bubbles
JXQ0aL8.png


Code:
# Automatic Opening Range and Fibonacci Levels
def na=double.nan;

# Define time that OR begins (in hhmm format,
# 0930 is the default):
input ORBegin = 0930;

# Define time that OR is finished (in hhmm format,
# 10:00 is the default):
input OREnd = 1000;

# Input first and second fib extension levels
# (default 1.382, 1.621):
Input FibExt1=1.382;
Input FibExt2=1.621;
Input FibExt3=2.0;
Input FibExt4=2.618;

# Show Today only? (Default Yes)
input ShowTodayOnly={"No", default "Yes"};
def s=ShowTodayOnly;

# Show Second fib extension? (Default No)
input ShowFibExt2={default "No", "Yes"};
def sf2=ShowFibExt2;

# Create logic for OR definition:
def ORActive = if secondstilltime(OREnd)>0 AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Create logic to paint only current day post-open:
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;

# Track OR High:
rec ORHigh = if ORHigh[1]==0 or ORActive[1]==0 AND ORActive==1 then high else if ORActive AND high>ORHigh[1] then high else ORHigh[1];

# Track OR Low:
rec ORLow = if ORLow[1]==0 or ORActive[1]==0 AND ORActive==1 then low else if ORActive AND low<ORLow[1] then low else ORLow[1];

# Calculate OR width:
def ORWidth = ORHigh - ORLow;

# Calculate fib levels:
def fib_mid = (ORHigh+ORLow)/2;
def fib_ext_up1 = ORHigh + ORWidth*(FibExt1 - 1);
def  fib_ext_down1 = ORLow - ORWidth*(FibExt1 - 1);
def fib_ext_up2= ORHigh + ORWidth*(FibExt2 - 1);
def fib_ext_down2 = ORLow - ORWidth*(FibExt2 - 1);
def fib_ext_up3 = ORHigh + ORWidth*(FibExt3 - 1);
def fib_ext_down3 = ORLow - ORWidth*(FibExt3 - 1);
def fib_ext_up4= ORHigh + ORWidth*(FibExt4 - 1);
def fib_ext_down4 = ORLow - ORWidth*(FibExt4 - 1);

# Define all the plots:
plot ORH=if ORActive OR today<1 then na else ORHigh;
plot ORL=if ORActive OR today<1 then na else ORLow;
plot FibMid=if ORActive OR today<1 then na else fib_mid;
plot FibExtUp1=if ORActive OR today<1 then na else fib_ext_up1;
plot FibExtDown1=if ORActive OR today<1 then na else fib_ext_down1;
plot lot FibExtUp2=if ORActive OR today<1 OR sf2<1 then na else fib_ext_up2;
plot FibExtDown2=if ORActive OR today<1 OR sf2<1 then na else fib_ext_down2;
plot FibExtUp3=if ORActive OR today<1 then na else fib_ext_up3;
plot FibExtDown3=if ORActive OR today<1 then na else fib_ext_down3;
plot FibExtUp4=if ORActive OR today<1 OR sf2<1 then na else fib_ext_up4;
plot FibExtDown4=if ORActive OR today<1 OR sf2<1 then na else fib_ext_down4;

# Formatting:
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Long_DASH);
ORH.setlineweight(3);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Long_DASH);
ORL.setlineweight(3);
AddChartBubble(ORHigh, ORH, "ORH", color.green, yes);

FibMid.setdefaultcolor(color.gray);
FibMid.setStyle(curve.SHORT_DASH);
FibMid.setlineweight(3);
FibExtUp1.setdefaultcolor(color.green);
FibExtUp1.setStyle(curve.SHORT_DASH);
FibExtUp1.setlineweight(2);
FibExtDown1.setdefaultcolor(color.red);
FibExtDown1.setStyle(curve.SHORT_DASH);
FibExtDown1.setlineweight(2);
FibExtUp2.setdefaultcolor(color.green);
FibExtUp2.setStyle(curve.SHORT_DASH);
FibExtUp2.setlineweight(1);
FibExtDown2.setdefaultcolor(color.red);
FibExtDown2.setStyle(curve.SHORT_DASH);
FibExtDown2.setlineweight(1);
FibExtUp3.setdefaultcolor(color.green);
FibExtUp3.setStyle(curve.SHORT_DASH);
FibExtUp3.setlineweight(2);
FibExtDown3.setdefaultcolor(color.red);
FibExtDown3.setStyle(curve.SHORT_DASH);
FibExtDown3.setlineweight(2);
FibExtUp4.setdefaultcolor(color.green);
FibExtUp4.setStyle(curve.SHORT_DASH);
FibExtUp4.setlineweight(1);
FibExtDown4.setdefaultcolor(color.red);
FibExtDown4.setStyle(curve.SHORT_DASH);
FibExtDown4.setlineweight(1);
 
Last edited by a moderator:
Solution
@ken_trades Try something like this, and make sure you have Time Axis, Expansion area configured for at-least 5 bars.

Ruby:
AddChartBubble(IsNaN(close), ORHigh[1], Concat("ORH ", ORHigh[1]), Color.GREEN, yes);

Similar threads

Top