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?
#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 =...
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?
#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.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); #
@Joshua, thank you for looking into this, too!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?
@halcyonguy, could you please inform if you had a chance to get the script above formatted to MTF?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); #
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.