Horizontal Line at High, Low, and Mid Point

SHJ

Member
VIP
Hi Team,

Can somebody help me with a MTF script that plots a horizontal line at the HIGH, LOW, and MID POINT of Candle[1] and get the horizontal lines extended to Candle[-4] only?
 
Solution
Hi Team,

Can somebody help me with a MTF script that plots a horizontal line at the HIGH, LOW, and MID POINT of Candle[1] and get the horizontal lines extended to Candle[-4] only?

i try to start with the simplest version first.
so my first version is not a MTF version

enter a number (bars back) for an offset from the last bar, to pick the start bar.
enter a number for an offset from last bar to some bar placeholder after the last bar, that will be where the lines end.


Code:
#hi_lo_mid_from_barx
#https://usethinkscript.com/threads/horizontal-line-at-high-low-and-mid-point.21496/
#Horizontal Line at High, Low, and Mid Point

def na = Double.NaN;
def bn = BarNumber();

def chartagg = GetAggregationPeriod();
input agg =...
Every candle on the chart is going to be Candle[1]. The only exception is the right most bar, but even then, only until a new bar opens. It seems you would need some sort of condition to initiate the process, unless, perhaps, you only want it to appear on the latest grouping of bars on the edge of the chart?

I get the impression that the answer to your question is probably very easy, but I am struggling to make sense of the question itself. Would it be possible for you to take a screen shot of a chart, and draw on it what you're talking about?
 
Hi Team,

Can somebody help me with a MTF script that plots a horizontal line at the HIGH, LOW, and MID POINT of Candle[1] and get the horizontal lines extended to Candle[-4] only?

i try to start with the simplest version first.
so my first version is not a MTF version

enter a number (bars back) for an offset from the last bar, to pick the start bar.
enter a number for an offset from last bar to some bar placeholder after the last bar, that will be where the lines end.


Code:
#hi_lo_mid_from_barx
#https://usethinkscript.com/threads/horizontal-line-at-high-low-and-mid-point.21496/
#Horizontal Line at High, Low, and Mid Point

def na = Double.NaN;
def bn = BarNumber();

def chartagg = GetAggregationPeriod();
input agg = AggregationPeriod.HOUR;
def aggmin = agg / 60000;


input bars_back = 1;
#def bb = !IsNaN(close[-(bars_back - 1)]) and IsNaN(close[-bars_back]);
def bb = !IsNaN(close[-(bars_back - 0)]) and IsNaN(close[-(bars_back + 1)]);
def rng1 = !IsNaN(close) and IsNaN(close[-bars_back]);

input bars_forward = 4;
def rng2 = !IsNaN(close[bars_forward]) and IsNaN(close);

def x = rng1 or rng2;


def hi;
def mid;
def lo;
if bn == 1 then {
    hi = 0;
    mid = 0;
    lo = 0;
} else if bb then {
    hi = high;
    mid = (high + low) / 2;
    lo = low;
} else if x then {
    hi = hi[1];
    mid = mid[1];
    lo = lo[1];
} else {
    hi = 0;
    mid = 0;
    lo = 0;
}


plot z1 = if hi > 0 then hi else na;
plot z2 = if mid > 0 then mid else na;
plot z3 = if lo > 0 then lo else na;
z1.SetDefaultColor(Color.LIGHT_GRAY);
z2.SetDefaultColor(Color.LIGHT_GRAY);
z3.SetDefaultColor(Color.LIGHT_GRAY);

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

input test1 = no;
AddVerticalLine(test1 and bb, "-", Color.CYAN);

input test2 = no;
AddVerticalLine(test2 and rng1, "-", Color.BLUE);

input test3 = no;
AddVerticalLine(test3 and rng2, "-", Color.GREEN);

#
 

Attachments

  • img1.JPG
    img1.JPG
    39.3 KB · Views: 132
Last edited:
Solution
i try to start with the simplest version first.
so my first version is not a MTF version

enter a number (bars back) for an offset from the last bar, to pick the start bar.
enter a number for an offset from last bar to some bar placeholder after the last bar, that will be where the lines end.


Code:
#hi_lo_mid_from_barx
#https://usethinkscript.com/threads/horizontal-line-at-high-low-and-mid-point.21496/
#Horizontal Line at High, Low, and Mid Point

def na = Double.NaN;
def bn = BarNumber();

def chartagg = GetAggregationPeriod();
input agg = AggregationPeriod.HOUR;
def aggmin = agg / 60000;


input bars_back = 1;
#def bb = !IsNaN(close[-(bars_back - 1)]) and IsNaN(close[-bars_back]);
def bb = !IsNaN(close[-(bars_back - 0)]) and IsNaN(close[-(bars_back + 1)]);
def rng1 = !IsNaN(close) and IsNaN(close[-bars_back]);

input bars_forward = 4;
def rng2 = !IsNaN(close[bars_forward]) and IsNaN(close);

def x = rng1 or rng2;


def hi;
def mid;
def lo;
if bn == 1 then {
    hi = 0;
    mid = 0;
    lo = 0;
} else if bb then {
    hi = high;
    mid = (high + low) / 2;
    lo = low;
} else if x then {
    hi = hi[1];
    mid = mid[1];
    lo = lo[1];
} else {
    hi = 0;
    mid = 0;
    lo = 0;
}


plot z1 = if hi > 0 then hi else na;
plot z2 = if mid > 0 then mid else na;
plot z3 = if lo > 0 then lo else na;
z1.SetDefaultColor(Color.LIGHT_GRAY);
z2.SetDefaultColor(Color.LIGHT_GRAY);
z3.SetDefaultColor(Color.LIGHT_GRAY);

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

input test1 = no;
AddVerticalLine(test1 and bb, "-", Color.CYAN);

input test2 = no;
AddVerticalLine(test2 and rng1, "-", Color.BLUE);

input test3 = no;
AddVerticalLine(test3 and rng2, "-", Color.GREEN);

#
Thank you so much, @halcyonguy! This is powerful and, if you can make it MTF, it will be even better. I am visualizing it as a "rolling" indicator that immediately gives a frame of reference for price action in relation to Candle[1]. Then, if the frame of reference is set at a higher TF, it will be easier to understand the development of price action at the lower TF.
 
Every candle on the chart is going to be Candle[1]. The only exception is the right most bar, but even then, only until a new bar opens. It seems you would need some sort of condition to initiate the process, unless, perhaps, you only want it to appear on the latest grouping of bars on the edge of the chart?

I get the impression that the answer to your question is probably very easy, but I am struggling to make sense of the question itself. Would it be possible for you to take a screen shot of a chart, and draw on it what you're talking about?
@Joshua, thank you for looking into this, too!
 
i try to start with the simplest version first.
so my first version is not a MTF version

enter a number (bars back) for an offset from the last bar, to pick the start bar.
enter a number for an offset from last bar to some bar placeholder after the last bar, that will be where the lines end.


Code:
#hi_lo_mid_from_barx
#https://usethinkscript.com/threads/horizontal-line-at-high-low-and-mid-point.21496/
#Horizontal Line at High, Low, and Mid Point

def na = Double.NaN;
def bn = BarNumber();

def chartagg = GetAggregationPeriod();
input agg = AggregationPeriod.HOUR;
def aggmin = agg / 60000;


input bars_back = 1;
#def bb = !IsNaN(close[-(bars_back - 1)]) and IsNaN(close[-bars_back]);
def bb = !IsNaN(close[-(bars_back - 0)]) and IsNaN(close[-(bars_back + 1)]);
def rng1 = !IsNaN(close) and IsNaN(close[-bars_back]);

input bars_forward = 4;
def rng2 = !IsNaN(close[bars_forward]) and IsNaN(close);

def x = rng1 or rng2;


def hi;
def mid;
def lo;
if bn == 1 then {
    hi = 0;
    mid = 0;
    lo = 0;
} else if bb then {
    hi = high;
    mid = (high + low) / 2;
    lo = low;
} else if x then {
    hi = hi[1];
    mid = mid[1];
    lo = lo[1];
} else {
    hi = 0;
    mid = 0;
    lo = 0;
}


plot z1 = if hi > 0 then hi else na;
plot z2 = if mid > 0 then mid else na;
plot z3 = if lo > 0 then lo else na;
z1.SetDefaultColor(Color.LIGHT_GRAY);
z2.SetDefaultColor(Color.LIGHT_GRAY);
z3.SetDefaultColor(Color.LIGHT_GRAY);

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

input test1 = no;
AddVerticalLine(test1 and bb, "-", Color.CYAN);

input test2 = no;
AddVerticalLine(test2 and rng1, "-", Color.BLUE);

input test3 = no;
AddVerticalLine(test3 and rng2, "-", Color.GREEN);

#
@halcyonguy, could you please inform if you had a chance to get the script above formatted to MTF?
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
491 Online
Create Post

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