Nirvana Holy Grail Inside Bar Outside Bar For ThinkOrSwim

halcyonguy

Moderator - Expert
VIP
Lifetime
This looks for 4 patterns,
. Nirvana - cyan , 3 bars, middle bar is smaller
. HolyGrail - magenta , 3 bars, middle bar is bigger
. Inside bar - yellow , 2 bars , right bar is smaller
. Outside bar - white , 2 bars , right bar is bigger

each pattern is drawn in a different color.
a colored label is shown for each pattern that is turned on.

the last bar in a pattern has a different color, i left it that way from the original.
the high and low of the last bar in a pattern, are the levels that are compared to price.
up arrow , when price is above a high.
down arrow , when price is below a low.

setting this to yes, will plot only the arrows that change direction. when an arrow is different that the last one.
input show_only_first_changed_arrows = yes;

the arrows for the 4 patterns are drawn at different distances from the candles, so if all 4 are drawn, they are visible and stacked, not covered up.
there are 3 variables that affect how the arrows are placed.
def arrow_size = 1;
def arrow_sp_fac = 0.1;
def sizex = 0.8;

can show horizontal lines from the high and low.
can turn any of the 4 patterns on or off.


Ruby:
 #Nirvana Holy Grail Inside Bar Outside Bar For ThinkOrSwim
#@halcyonguy 2/2022
# hilite_bars_higherlower_02

def na = double.nan;
def bn = barnumber();

input show_Nirvana = yes;
input show_HolyGrail = yes;
input show_Inside_bar = yes;
input show_Outside_bar = yes;

# Nirvana - color.CYAN
# HolyGrail - color.magenta
# Inside bar   - color.yellow
# Outside bar  - color.WHITE

input show_only_first_changed_arrows = yes;

input show_bar_level_lines = yes;

def arrow_size = 1;
def arrow_sp_fac = 0.1;
def sizex = 0.8;


# ----------------------------------------------
##NIRVANA - Color.cyan

#def nirvana = low[1] > low[2] and low < low[1] and high[1] < high[2] and high > high[1];
def nirvana = if !show_Nirvana then 0 else
 high[2] > high[1] and high[1] < high[0]
and
 low[2] < low[1]  and low[1] > low[0];

# keep hi/lo of last signal bar
def nirvana_hi = if bn == 1 or nirvana[-1] then na else if nirvana then high else nirvana_hi[1];
def nirvana_lo = if bn == 1 or nirvana[-1] then na else if nirvana then low else nirvana_lo[1];

plot z1 = if (!show_NIRVANA or !show_bar_level_lines) then na else nirvana_hi;
z1.SetDefaultColor(Color.cyan);
#z1.hidebubble();
plot z2 = if (!show_NIRVANA or !show_bar_level_lines) then na else nirvana_lo;
z2.SetDefaultColor(Color.cyan);
#z2.hidebubble();

def narrows = if bn == 1 then 0
  else if nirvana then 0
  else if close > nirvana_hi then 1
  else if close < nirvana_lo then -1
  else narrows[1];

def nuparrow_en = if (show_only_first_changed_arrows and (close > nirvana_hi and narrows[1] <> 1)) then 1
 else if (!show_only_first_changed_arrows and close > nirvana_hi) then 1
  else 0;

def ndwnarrow_en = if (show_only_first_changed_arrows and (close < nirvana_lo and narrows[1] <> -1)) then 1
 else if (!show_only_first_changed_arrows and close < nirvana_lo) then 1
  else 0;

# row 1 of arrows
plot nirup = if (show_NIRVANA and nuparrow_en) then (low - (arrow_sp_fac * (arrow_size * sizex) * 0)) else na;
nirup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
nirup.SetDefaultColor(Color.cyan);
nirup.SetLineWeight(arrow_size);
nirup.hidebubble();

plot nirdwn = if (show_NIRVANA and ndwnarrow_en) then (high + (arrow_sp_fac * (arrow_size * sizex) * 0)) else na;
nirdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
nirdwn.SetDefaultColor(Color.cyan);
nirdwn.SetLineWeight(arrow_size);
nirdwn.hidebubble();

addchartbubble(0, low*0.997,
bn + "\n" +
nirvana + " n\n" +
nirvana_hi + " hi\n" +
nirvana_lo + " lo\n" +
narrows + " arr\n" +
nuparrow_en + " up\n" +
ndwnarrow_en + " dwn"
, color.yellow, no);

# ----------------------------------------------
# HolyGrail - magenta

#plot holyGrail = low[1] < low[2] and high[1] > high[2] and low > low[1] and high < high[1];
def holyGrail = if !show_holygrail then 0 else
 high[2] < high[1] and high[1] > high[0]
and
 low[2] > low[1] and low[1] < low[0];

# keep hi/lo of last signal bar
def holygrail_hi = if bn == 1 or holygrail[-1] then na else if holygrail then high else holygrail_hi[1];
def holygrail_lo = if bn == 1 or holygrail[-1] then na else if holygrail then low else holygrail_lo[1];

plot z3 = if (!show_holygrail or !show_bar_level_lines) then na else holygrail_hi;
z3.SetDefaultColor(Color.magenta);
#z3.hidebubble();
plot z4 = if (!show_holygrail or !show_bar_level_lines) then na else holygrail_lo;
z4.SetDefaultColor(Color.magenta);
#z4.hidebubble();

def harrows = if bn == 1 then 0
  else if holygrail then 0
  else if close > holygrail_hi then 1
  else if close < holygrail_lo then -1
  else harrows[1];

def huparrow_en = if (show_only_first_changed_arrows and (close > holygrail_hi and harrows[1] <> 1)) then 1
 else if (!show_only_first_changed_arrows and close > holygrail_hi) then 1
  else 0;

def hdwnarrow_en = if (show_only_first_changed_arrows and (close < holygrail_lo and harrows[1] <> -1)) then 1
 else if (!show_only_first_changed_arrows and close < holygrail_lo) then 1
  else 0;


# row 2 of arrows
plot holup = if (show_holygrail and huparrow_en) then (low - (arrow_sp_fac * (arrow_size * sizex) * 1)) else na;
holup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
holup.SetDefaultColor(Color.magenta);
holup.SetLineWeight(arrow_size);
holup.hidebubble();

plot holdwn = if (show_holygrail and hdwnarrow_en) then (high + (arrow_sp_fac* (arrow_size * sizex) * 1)) else na;
holdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
holdwn.SetDefaultColor(Color.magenta);
holdwn.SetLineWeight(arrow_size);
holdwn.hidebubble();

# ----------------------------------------------
# Inside_bar - yellow

#plot inBar = low > low[1] and high < high[1];
def inBar2 = if !show_inside_bar then 0 else
low[1] < low[0] and high[1] > high[0];

# insidebar is same as 2nd half of  HolyGrail
# if bar is a HolyGrail , then disable insidebar
def inside_bar = if HolyGrail then 0 else inbar2;


# keep hi/lo of last signal bar
def inside_bar_hi = if bn == 1 or inside_bar[-1] then na else if inside_bar then high else inside_bar_hi[1];
def inside_bar_lo = if bn == 1 or inside_bar[-1] then na else if inside_bar then low else inside_bar_lo[1];


plot z5 = if (!show_inside_bar or !show_bar_level_lines) then na else inside_bar_hi;
z5.SetDefaultColor(Color.yellow);
#z5.hidebubble();
plot z6 = if (!show_inside_bar or !show_bar_level_lines) then na else inside_bar_lo;
z6.SetDefaultColor(Color.yellow);
#z6.hidebubble();


def iarrows = if bn == 1 then 0
  else if inside_bar then 0
  else if close > inside_bar_hi then 1
  else if close < inside_bar_lo then -1
  else iarrows[1];


def iuparrow_en = if (show_only_first_changed_arrows and (close > inside_bar_hi and iarrows[1] <> 1)) then 1
 else if (!show_only_first_changed_arrows and close > inside_bar_hi) then 1
  else 0;

def idwnarrow_en = if (show_only_first_changed_arrows and (close < inside_bar_lo and iarrows[1] <> -1)) then 1
 else if (!show_only_first_changed_arrows and close < inside_bar_lo) then 1
  else 0;


# row 3 of arrows
plot insup = if (show_inside_bar and iuparrow_en) then (low - (arrow_sp_fac * (arrow_size * sizex) * 2)) else na;
insup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
insup.SetDefaultColor(Color.yellow);
insup.SetLineWeight(arrow_size);
insup.hidebubble();

plot insdwn = if (show_inside_bar and idwnarrow_en) then (high + (arrow_sp_fac * (arrow_size * sizex) * 2)) else na;
insdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
insdwn.SetDefaultColor(Color.yellow);
insdwn.SetLineWeight(arrow_size);
insdwn.hidebubble();

# ----------------------------------------------
# Outside_Bar - white

#plot outBar2 = low < low[1] and high > high[1];
def outBar2 = if !show_outside_bar then 0 else
  low[1] > low[0] and high[1] < high[0];

# outsidebar is same as 2nd half of nirvana
# if bar is a nirvana , then disable outsidebar
def outside_bar = if nirvana then 0 else outbar2;

# keep hi/lo of last signal bar
def outside_bar_hi = if bn == 1 or outside_bar[-1] then na else if outside_bar then high else outside_bar_hi[1];
def outside_bar_lo = if bn == 1 or outside_bar[-1] then na else if outside_bar then low else outside_bar_lo[1];

plot z7 = if (!show_outside_bar or !show_bar_level_lines) then na else outside_bar_hi;
z7.SetDefaultColor(Color.white);
#z7.hidebubble();
plot z8 = if (!show_outside_bar or !show_bar_level_lines) then na else outside_bar_lo;
z8.SetDefaultColor(Color.white);
#z8.hidebubble();


def oarrows = if bn == 1 then 0
  else if outside_bar then 0
  else if close > outside_bar_hi then 1
  else if close < outside_bar_lo then -1
  else oarrows[1];


def ouparrow_en = if (show_only_first_changed_arrows and (close > outside_bar_hi and oarrows[1] <> 1)) then 1
 else if (!show_only_first_changed_arrows and close > outside_bar_hi) then 1
  else 0;

def odwnarrow_en = if (show_only_first_changed_arrows and (close < outside_bar_lo and oarrows[1] <> -1)) then 1
 else if (!show_only_first_changed_arrows and close < outside_bar_lo) then 1
  else 0;


# row 4 of arrows
plot outsup = if (show_outside_bar and ouparrow_en) then (low - (arrow_sp_fac * (arrow_size * sizex) * 3)) else na;
outsup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
outsup.SetDefaultColor(Color.white);
outsup.SetLineWeight(arrow_size);
outsup.hidebubble();

plot outsdwn = if (show_outside_bar and odwnarrow_en) then (high + (arrow_sp_fac * (arrow_size * sizex) * 3)) else na;
outsdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
outsdwn.SetDefaultColor(Color.white);
outsdwn.SetLineWeight(arrow_size);
outsdwn.hidebubble();

# ----------------------------------------------

addlabel(show_NIRVANA, "Nirvana", Color.CYAN);
addlabel(show_HolyGrail, "HolyGrail", color.magenta);
addlabel(show_Inside_bar, "Inside bar", Color.yellow);
addlabel(show_Outside_bar, "Outside bar", Color.WHITE);

AssignPriceColor(
 if Nirvana then Color.CYAN
 else if HolyGrail then color.magenta
 else if inside_bar then Color.yellow
 else if outside_Bar then Color.WHITE
 else Color.CURRENT);
#


settings
UWFLsvv.jpg


nirvana - zoomed in , first changed arrows
GapDRXl.jpg


nirvana - zoom out, multiple triggers
HxxW1Bt.jpg


all 4 signals - all arrows
each signal arrow has a different price factor, so they appear stacked, not on top of each other.
T35dLux.jpg
 
Last edited by a moderator:

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

Is there anyway we could get an addition to this script that highlights both of the candles that make up the Holygrail and Nirvana pattern? As of right now I have all the lines and arrows turned so just the candle highlights are showing. With that, I would like for the new script to color BOTH candles that make up the "holygrail" and "nirvana" instead of just the one. Thanks in advance. Love this script. Been having fantastic results recently with the Nirvana and Holygrails!
 
Is there anyway we could get an addition to this script that highlights both of the candles that make up the Holygrail and Nirvana pattern? As of right now I have all the lines and arrows turned so just the candle highlights are showing. With that, I would like for the new script to color BOTH candles that make up the "holygrail" and "nirvana" instead of just the one. Thanks in advance. Love this script. Been having fantastic results recently with the Nirvana and Holygrails!
Sorry, no idea what you are asking.
Help us help you:
  • Include an image and shared chart link. This will help others understand the context of your question and allow them to replicate the conditions that you are describing.
  • Annotate your image, highlighting the confluence that you're trying to achieve, This will provide specific information to work with.
  • Try to use concise language that's heavy on logic. We need to understand what you're trying to convey.
If you're unsure of how to share chart links or upload screenshots to the forum, don't worry, we've included some easy-to-follow directions for you.
How to create a shared chart link:
https://usethinkscript.com/threads/how-to-share-a-chart-in-thinkorswim.14221/
How to upload screenshots to the forum:
https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-58714
 
Last edited:
This looks for 4 patterns,
. Nirvana - cyan , 3 bars, middle bar is smaller
. HolyGrail - magenta , 3 bars, middle bar is bigger
. Inside bar - yellow , 2 bars , right bar is smaller
. Outside bar - white , 2 bars , right bar is bigger

each pattern is drawn in a different color.
a colored label is shown for each pattern that is turned on.

the last bar in a pattern has a different color, i left it that way from the original.
the high and low of the last bar in a pattern, are the levels that are compared to price.
up arrow , when price is above a high.
down arrow , when price is below a low.

setting this to yes, will plot only the arrows that change direction. when an arrow is different that the last one.
input show_only_first_changed_arrows = yes;

the arrows for the 4 patterns are drawn at different distances from the candles, so if all 4 are drawn, they are visible and stacked, not covered up.
there are 3 variables that affect how the arrows are placed.
def arrow_size = 1;
def arrow_sp_fac = 0.1;
def sizex = 0.8;

can show horizontal lines from the high and low.
can turn any of the 4 patterns on or off.


Ruby:
 #Nirvana Holy Grail Inside Bar Outside Bar For ThinkOrSwim
#@halcyonguy 2/2022
# hilite_bars_higherlower_02

def na = double.nan;
def bn = barnumber();

input show_Nirvana = yes;
input show_HolyGrail = yes;
input show_Inside_bar = yes;
input show_Outside_bar = yes;

# Nirvana - color.CYAN
# HolyGrail - color.magenta
# Inside bar   - color.yellow
# Outside bar  - color.WHITE

input show_only_first_changed_arrows = yes;

input show_bar_level_lines = yes;

def arrow_size = 1;
def arrow_sp_fac = 0.1;
def sizex = 0.8;


# ----------------------------------------------
##NIRVANA - Color.cyan

#def nirvana = low[1] > low[2] and low < low[1] and high[1] < high[2] and high > high[1];
def nirvana = if !show_Nirvana then 0 else
 high[2] > high[1] and high[1] < high[0]
and
 low[2] < low[1]  and low[1] > low[0];

# keep hi/lo of last signal bar
def nirvana_hi = if bn == 1 or nirvana[-1] then na else if nirvana then high else nirvana_hi[1];
def nirvana_lo = if bn == 1 or nirvana[-1] then na else if nirvana then low else nirvana_lo[1];

plot z1 = if (!show_NIRVANA or !show_bar_level_lines) then na else nirvana_hi;
z1.SetDefaultColor(Color.cyan);
#z1.hidebubble();
plot z2 = if (!show_NIRVANA or !show_bar_level_lines) then na else nirvana_lo;
z2.SetDefaultColor(Color.cyan);
#z2.hidebubble();

def narrows = if bn == 1 then 0
  else if nirvana then 0
  else if close > nirvana_hi then 1
  else if close < nirvana_lo then -1
  else narrows[1];

def nuparrow_en = if (show_only_first_changed_arrows and (close > nirvana_hi and narrows[1] <> 1)) then 1
 else if (!show_only_first_changed_arrows and close > nirvana_hi) then 1
  else 0;

def ndwnarrow_en = if (show_only_first_changed_arrows and (close < nirvana_lo and narrows[1] <> -1)) then 1
 else if (!show_only_first_changed_arrows and close < nirvana_lo) then 1
  else 0;

# row 1 of arrows
plot nirup = if (show_NIRVANA and nuparrow_en) then (low - (arrow_sp_fac * (arrow_size * sizex) * 0)) else na;
nirup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
nirup.SetDefaultColor(Color.cyan);
nirup.SetLineWeight(arrow_size);
nirup.hidebubble();

plot nirdwn = if (show_NIRVANA and ndwnarrow_en) then (high + (arrow_sp_fac * (arrow_size * sizex) * 0)) else na;
nirdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
nirdwn.SetDefaultColor(Color.cyan);
nirdwn.SetLineWeight(arrow_size);
nirdwn.hidebubble();

addchartbubble(0, low*0.997,
bn + "\n" +
nirvana + " n\n" +
nirvana_hi + " hi\n" +
nirvana_lo + " lo\n" +
narrows + " arr\n" +
nuparrow_en + " up\n" +
ndwnarrow_en + " dwn"
, color.yellow, no);

# ----------------------------------------------
# HolyGrail - magenta

#plot holyGrail = low[1] < low[2] and high[1] > high[2] and low > low[1] and high < high[1];
def holyGrail = if !show_holygrail then 0 else
 high[2] < high[1] and high[1] > high[0]
and
 low[2] > low[1] and low[1] < low[0];

# keep hi/lo of last signal bar
def holygrail_hi = if bn == 1 or holygrail[-1] then na else if holygrail then high else holygrail_hi[1];
def holygrail_lo = if bn == 1 or holygrail[-1] then na else if holygrail then low else holygrail_lo[1];

plot z3 = if (!show_holygrail or !show_bar_level_lines) then na else holygrail_hi;
z3.SetDefaultColor(Color.magenta);
#z3.hidebubble();
plot z4 = if (!show_holygrail or !show_bar_level_lines) then na else holygrail_lo;
z4.SetDefaultColor(Color.magenta);
#z4.hidebubble();

def harrows = if bn == 1 then 0
  else if holygrail then 0
  else if close > holygrail_hi then 1
  else if close < holygrail_lo then -1
  else harrows[1];

def huparrow_en = if (show_only_first_changed_arrows and (close > holygrail_hi and harrows[1] <> 1)) then 1
 else if (!show_only_first_changed_arrows and close > holygrail_hi) then 1
  else 0;

def hdwnarrow_en = if (show_only_first_changed_arrows and (close < holygrail_lo and harrows[1] <> -1)) then 1
 else if (!show_only_first_changed_arrows and close < holygrail_lo) then 1
  else 0;


# row 2 of arrows
plot holup = if (show_holygrail and huparrow_en) then (low - (arrow_sp_fac * (arrow_size * sizex) * 1)) else na;
holup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
holup.SetDefaultColor(Color.magenta);
holup.SetLineWeight(arrow_size);
holup.hidebubble();

plot holdwn = if (show_holygrail and hdwnarrow_en) then (high + (arrow_sp_fac* (arrow_size * sizex) * 1)) else na;
holdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
holdwn.SetDefaultColor(Color.magenta);
holdwn.SetLineWeight(arrow_size);
holdwn.hidebubble();

# ----------------------------------------------
# Inside_bar - yellow

#plot inBar = low > low[1] and high < high[1];
def inBar2 = if !show_inside_bar then 0 else
low[1] < low[0] and high[1] > high[0];

# insidebar is same as 2nd half of  HolyGrail
# if bar is a HolyGrail , then disable insidebar
def inside_bar = if HolyGrail then 0 else inbar2;


# keep hi/lo of last signal bar
def inside_bar_hi = if bn == 1 or inside_bar[-1] then na else if inside_bar then high else inside_bar_hi[1];
def inside_bar_lo = if bn == 1 or inside_bar[-1] then na else if inside_bar then low else inside_bar_lo[1];


plot z5 = if (!show_inside_bar or !show_bar_level_lines) then na else inside_bar_hi;
z5.SetDefaultColor(Color.yellow);
#z5.hidebubble();
plot z6 = if (!show_inside_bar or !show_bar_level_lines) then na else inside_bar_lo;
z6.SetDefaultColor(Color.yellow);
#z6.hidebubble();


def iarrows = if bn == 1 then 0
  else if inside_bar then 0
  else if close > inside_bar_hi then 1
  else if close < inside_bar_lo then -1
  else iarrows[1];


def iuparrow_en = if (show_only_first_changed_arrows and (close > inside_bar_hi and iarrows[1] <> 1)) then 1
 else if (!show_only_first_changed_arrows and close > inside_bar_hi) then 1
  else 0;

def idwnarrow_en = if (show_only_first_changed_arrows and (close < inside_bar_lo and iarrows[1] <> -1)) then 1
 else if (!show_only_first_changed_arrows and close < inside_bar_lo) then 1
  else 0;


# row 3 of arrows
plot insup = if (show_inside_bar and iuparrow_en) then (low - (arrow_sp_fac * (arrow_size * sizex) * 2)) else na;
insup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
insup.SetDefaultColor(Color.yellow);
insup.SetLineWeight(arrow_size);
insup.hidebubble();

plot insdwn = if (show_inside_bar and idwnarrow_en) then (high + (arrow_sp_fac * (arrow_size * sizex) * 2)) else na;
insdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
insdwn.SetDefaultColor(Color.yellow);
insdwn.SetLineWeight(arrow_size);
insdwn.hidebubble();

# ----------------------------------------------
# Outside_Bar - white

#plot outBar2 = low < low[1] and high > high[1];
def outBar2 = if !show_outside_bar then 0 else
  low[1] > low[0] and high[1] < high[0];

# outsidebar is same as 2nd half of nirvana
# if bar is a nirvana , then disable outsidebar
def outside_bar = if nirvana then 0 else outbar2;

# keep hi/lo of last signal bar
def outside_bar_hi = if bn == 1 or outside_bar[-1] then na else if outside_bar then high else outside_bar_hi[1];
def outside_bar_lo = if bn == 1 or outside_bar[-1] then na else if outside_bar then low else outside_bar_lo[1];

plot z7 = if (!show_outside_bar or !show_bar_level_lines) then na else outside_bar_hi;
z7.SetDefaultColor(Color.white);
#z7.hidebubble();
plot z8 = if (!show_outside_bar or !show_bar_level_lines) then na else outside_bar_lo;
z8.SetDefaultColor(Color.white);
#z8.hidebubble();


def oarrows = if bn == 1 then 0
  else if outside_bar then 0
  else if close > outside_bar_hi then 1
  else if close < outside_bar_lo then -1
  else oarrows[1];


def ouparrow_en = if (show_only_first_changed_arrows and (close > outside_bar_hi and oarrows[1] <> 1)) then 1
 else if (!show_only_first_changed_arrows and close > outside_bar_hi) then 1
  else 0;

def odwnarrow_en = if (show_only_first_changed_arrows and (close < outside_bar_lo and oarrows[1] <> -1)) then 1
 else if (!show_only_first_changed_arrows and close < outside_bar_lo) then 1
  else 0;


# row 4 of arrows
plot outsup = if (show_outside_bar and ouparrow_en) then (low - (arrow_sp_fac * (arrow_size * sizex) * 3)) else na;
outsup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
outsup.SetDefaultColor(Color.white);
outsup.SetLineWeight(arrow_size);
outsup.hidebubble();

plot outsdwn = if (show_outside_bar and odwnarrow_en) then (high + (arrow_sp_fac * (arrow_size * sizex) * 3)) else na;
outsdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
outsdwn.SetDefaultColor(Color.white);
outsdwn.SetLineWeight(arrow_size);
outsdwn.hidebubble();

# ----------------------------------------------

addlabel(show_NIRVANA, "Nirvana", Color.CYAN);
addlabel(show_HolyGrail, "HolyGrail", color.magenta);
addlabel(show_Inside_bar, "Inside bar", Color.yellow);
addlabel(show_Outside_bar, "Outside bar", Color.WHITE);

AssignPriceColor(
 if Nirvana then Color.CYAN
 else if HolyGrail then color.magenta
 else if inside_bar then Color.yellow
 else if outside_Bar then Color.WHITE
 else Color.CURRENT);
#


settings
UWFLsvv.jpg


nirvana - zoomed in , first changed arrows
GapDRXl.jpg


nirvana - zoom out, multiple triggers
HxxW1Bt.jpg


all 4 signals - all arrows
each signal arrow has a different price factor, so they appear stacked, not on top of each other.
T35dLux.jpg
Nirvana pattern is an outside bar after one inside bar
 
This looks for 4 patterns,
. Nirvana - cyan , 3 bars, middle bar is smaller
. HolyGrail - magenta , 3 bars, middle bar is bigger
. Inside bar - yellow , 2 bars , right bar is smaller
. Outside bar - white , 2 bars , right bar is bigger

each pattern is drawn in a different color.
a colored label is shown for each pattern that is turned on.

the last bar in a pattern has a different color, i left it that way from the original.
the high and low of the last bar in a pattern, are the levels that are compared to price.
up arrow , when price is above a high.
down arrow , when price is below a low.

setting this to yes, will plot only the arrows that change direction. when an arrow is different that the last one.
input show_only_first_changed_arrows = yes;

the arrows for the 4 patterns are drawn at different distances from the candles, so if all 4 are drawn, they are visible and stacked, not covered up.
there are 3 variables that affect how the arrows are placed.
def arrow_size = 1;
def arrow_sp_fac = 0.1;
def sizex = 0.8;

can show horizontal lines from the high and low.
can turn any of the 4 patterns on or off.


Ruby:
 #Nirvana Holy Grail Inside Bar Outside Bar For ThinkOrSwim
#@halcyonguy 2/2022
# hilite_bars_higherlower_02

def na = double.nan;
def bn = barnumber();

input show_Nirvana = yes;
input show_HolyGrail = yes;
input show_Inside_bar = yes;
input show_Outside_bar = yes;

# Nirvana - color.CYAN
# HolyGrail - color.magenta
# Inside bar   - color.yellow
# Outside bar  - color.WHITE

input show_only_first_changed_arrows = yes;

input show_bar_level_lines = yes;

def arrow_size = 1;
def arrow_sp_fac = 0.1;
def sizex = 0.8;


# ----------------------------------------------
##NIRVANA - Color.cyan

#def nirvana = low[1] > low[2] and low < low[1] and high[1] < high[2] and high > high[1];
def nirvana = if !show_Nirvana then 0 else
 high[2] > high[1] and high[1] < high[0]
and
 low[2] < low[1]  and low[1] > low[0];

# keep hi/lo of last signal bar
def nirvana_hi = if bn == 1 or nirvana[-1] then na else if nirvana then high else nirvana_hi[1];
def nirvana_lo = if bn == 1 or nirvana[-1] then na else if nirvana then low else nirvana_lo[1];

plot z1 = if (!show_NIRVANA or !show_bar_level_lines) then na else nirvana_hi;
z1.SetDefaultColor(Color.cyan);
#z1.hidebubble();
plot z2 = if (!show_NIRVANA or !show_bar_level_lines) then na else nirvana_lo;
z2.SetDefaultColor(Color.cyan);
#z2.hidebubble();

def narrows = if bn == 1 then 0
  else if nirvana then 0
  else if close > nirvana_hi then 1
  else if close < nirvana_lo then -1
  else narrows[1];

def nuparrow_en = if (show_only_first_changed_arrows and (close > nirvana_hi and narrows[1] <> 1)) then 1
 else if (!show_only_first_changed_arrows and close > nirvana_hi) then 1
  else 0;

def ndwnarrow_en = if (show_only_first_changed_arrows and (close < nirvana_lo and narrows[1] <> -1)) then 1
 else if (!show_only_first_changed_arrows and close < nirvana_lo) then 1
  else 0;

# row 1 of arrows
plot nirup = if (show_NIRVANA and nuparrow_en) then (low - (arrow_sp_fac * (arrow_size * sizex) * 0)) else na;
nirup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
nirup.SetDefaultColor(Color.cyan);
nirup.SetLineWeight(arrow_size);
nirup.hidebubble();

plot nirdwn = if (show_NIRVANA and ndwnarrow_en) then (high + (arrow_sp_fac * (arrow_size * sizex) * 0)) else na;
nirdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
nirdwn.SetDefaultColor(Color.cyan);
nirdwn.SetLineWeight(arrow_size);
nirdwn.hidebubble();

addchartbubble(0, low*0.997,
bn + "\n" +
nirvana + " n\n" +
nirvana_hi + " hi\n" +
nirvana_lo + " lo\n" +
narrows + " arr\n" +
nuparrow_en + " up\n" +
ndwnarrow_en + " dwn"
, color.yellow, no);

# ----------------------------------------------
# HolyGrail - magenta

#plot holyGrail = low[1] < low[2] and high[1] > high[2] and low > low[1] and high < high[1];
def holyGrail = if !show_holygrail then 0 else
 high[2] < high[1] and high[1] > high[0]
and
 low[2] > low[1] and low[1] < low[0];

# keep hi/lo of last signal bar
def holygrail_hi = if bn == 1 or holygrail[-1] then na else if holygrail then high else holygrail_hi[1];
def holygrail_lo = if bn == 1 or holygrail[-1] then na else if holygrail then low else holygrail_lo[1];

plot z3 = if (!show_holygrail or !show_bar_level_lines) then na else holygrail_hi;
z3.SetDefaultColor(Color.magenta);
#z3.hidebubble();
plot z4 = if (!show_holygrail or !show_bar_level_lines) then na else holygrail_lo;
z4.SetDefaultColor(Color.magenta);
#z4.hidebubble();

def harrows = if bn == 1 then 0
  else if holygrail then 0
  else if close > holygrail_hi then 1
  else if close < holygrail_lo then -1
  else harrows[1];

def huparrow_en = if (show_only_first_changed_arrows and (close > holygrail_hi and harrows[1] <> 1)) then 1
 else if (!show_only_first_changed_arrows and close > holygrail_hi) then 1
  else 0;

def hdwnarrow_en = if (show_only_first_changed_arrows and (close < holygrail_lo and harrows[1] <> -1)) then 1
 else if (!show_only_first_changed_arrows and close < holygrail_lo) then 1
  else 0;


# row 2 of arrows
plot holup = if (show_holygrail and huparrow_en) then (low - (arrow_sp_fac * (arrow_size * sizex) * 1)) else na;
holup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
holup.SetDefaultColor(Color.magenta);
holup.SetLineWeight(arrow_size);
holup.hidebubble();

plot holdwn = if (show_holygrail and hdwnarrow_en) then (high + (arrow_sp_fac* (arrow_size * sizex) * 1)) else na;
holdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
holdwn.SetDefaultColor(Color.magenta);
holdwn.SetLineWeight(arrow_size);
holdwn.hidebubble();

# ----------------------------------------------
# Inside_bar - yellow

#plot inBar = low > low[1] and high < high[1];
def inBar2 = if !show_inside_bar then 0 else
low[1] < low[0] and high[1] > high[0];

# insidebar is same as 2nd half of  HolyGrail
# if bar is a HolyGrail , then disable insidebar
def inside_bar = if HolyGrail then 0 else inbar2;


# keep hi/lo of last signal bar
def inside_bar_hi = if bn == 1 or inside_bar[-1] then na else if inside_bar then high else inside_bar_hi[1];
def inside_bar_lo = if bn == 1 or inside_bar[-1] then na else if inside_bar then low else inside_bar_lo[1];


plot z5 = if (!show_inside_bar or !show_bar_level_lines) then na else inside_bar_hi;
z5.SetDefaultColor(Color.yellow);
#z5.hidebubble();
plot z6 = if (!show_inside_bar or !show_bar_level_lines) then na else inside_bar_lo;
z6.SetDefaultColor(Color.yellow);
#z6.hidebubble();


def iarrows = if bn == 1 then 0
  else if inside_bar then 0
  else if close > inside_bar_hi then 1
  else if close < inside_bar_lo then -1
  else iarrows[1];


def iuparrow_en = if (show_only_first_changed_arrows and (close > inside_bar_hi and iarrows[1] <> 1)) then 1
 else if (!show_only_first_changed_arrows and close > inside_bar_hi) then 1
  else 0;

def idwnarrow_en = if (show_only_first_changed_arrows and (close < inside_bar_lo and iarrows[1] <> -1)) then 1
 else if (!show_only_first_changed_arrows and close < inside_bar_lo) then 1
  else 0;


# row 3 of arrows
plot insup = if (show_inside_bar and iuparrow_en) then (low - (arrow_sp_fac * (arrow_size * sizex) * 2)) else na;
insup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
insup.SetDefaultColor(Color.yellow);
insup.SetLineWeight(arrow_size);
insup.hidebubble();

plot insdwn = if (show_inside_bar and idwnarrow_en) then (high + (arrow_sp_fac * (arrow_size * sizex) * 2)) else na;
insdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
insdwn.SetDefaultColor(Color.yellow);
insdwn.SetLineWeight(arrow_size);
insdwn.hidebubble();

# ----------------------------------------------
# Outside_Bar - white

#plot outBar2 = low < low[1] and high > high[1];
def outBar2 = if !show_outside_bar then 0 else
  low[1] > low[0] and high[1] < high[0];

# outsidebar is same as 2nd half of nirvana
# if bar is a nirvana , then disable outsidebar
def outside_bar = if nirvana then 0 else outbar2;

# keep hi/lo of last signal bar
def outside_bar_hi = if bn == 1 or outside_bar[-1] then na else if outside_bar then high else outside_bar_hi[1];
def outside_bar_lo = if bn == 1 or outside_bar[-1] then na else if outside_bar then low else outside_bar_lo[1];

plot z7 = if (!show_outside_bar or !show_bar_level_lines) then na else outside_bar_hi;
z7.SetDefaultColor(Color.white);
#z7.hidebubble();
plot z8 = if (!show_outside_bar or !show_bar_level_lines) then na else outside_bar_lo;
z8.SetDefaultColor(Color.white);
#z8.hidebubble();


def oarrows = if bn == 1 then 0
  else if outside_bar then 0
  else if close > outside_bar_hi then 1
  else if close < outside_bar_lo then -1
  else oarrows[1];


def ouparrow_en = if (show_only_first_changed_arrows and (close > outside_bar_hi and oarrows[1] <> 1)) then 1
 else if (!show_only_first_changed_arrows and close > outside_bar_hi) then 1
  else 0;

def odwnarrow_en = if (show_only_first_changed_arrows and (close < outside_bar_lo and oarrows[1] <> -1)) then 1
 else if (!show_only_first_changed_arrows and close < outside_bar_lo) then 1
  else 0;


# row 4 of arrows
plot outsup = if (show_outside_bar and ouparrow_en) then (low - (arrow_sp_fac * (arrow_size * sizex) * 3)) else na;
outsup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
outsup.SetDefaultColor(Color.white);
outsup.SetLineWeight(arrow_size);
outsup.hidebubble();

plot outsdwn = if (show_outside_bar and odwnarrow_en) then (high + (arrow_sp_fac * (arrow_size * sizex) * 3)) else na;
outsdwn.SetPaintingStrategy(PaintingStrategy.ARROW_down);
outsdwn.SetDefaultColor(Color.white);
outsdwn.SetLineWeight(arrow_size);
outsdwn.hidebubble();

# ----------------------------------------------

addlabel(show_NIRVANA, "Nirvana", Color.CYAN);
addlabel(show_HolyGrail, "HolyGrail", color.magenta);
addlabel(show_Inside_bar, "Inside bar", Color.yellow);
addlabel(show_Outside_bar, "Outside bar", Color.WHITE);

AssignPriceColor(
 if Nirvana then Color.CYAN
 else if HolyGrail then color.magenta
 else if inside_bar then Color.yellow
 else if outside_Bar then Color.WHITE
 else Color.CURRENT);
#


settings
UWFLsvv.jpg


nirvana - zoomed in , first changed arrows
GapDRXl.jpg


nirvana - zoom out, multiple triggers
HxxW1Bt.jpg


all 4 signals - all arrows
each signal arrow has a different price factor, so they appear stacked, not on top of each other.
T35dLux.jpg

Thanks for this, its been really helpful. I've been trying to learn some coding by taking apart and scavenging bits of code. I like how you have the breakout lines but was wondering what part of the code determines how long they are? If I only wanted to extend the lines for say 6 candles would it be possible?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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