# Horizontal line from value/condition?

#### Prison Mike

##### Member
Hey,

Need some help, even more is I would love to learn, how to find a value/condition in the past, and draw a horizontal line from it. I understand how to plot a line from a high bar but haven't figured out how to in relation to time. What I want to do is based off a scan from stockfetcher. Ultimately I want to make a TOS scan from it but it think the study would be useful to visualize.

https://www.stockfetcher.com/sfforums/?mid=149271
The study will find a 10 days high within 10 days and the 20 day high within 60 days and calculates the value if a line connected the two highs to today. The scan would find when price crosses above that calculated value.

So from my little knowledge of coding I have been playing around with...

highest(high[10], 100); and
getvalue to find the point
Am I using these right, how off is this?
My other “tries” have included tweaking the Near_high_low scan from the condition wizard.

def price = close;
input period = 252;
input choice = {default High, Low};
input choice1 = 3;

def hi = high;
def lo = low;

plot scan;
switch (choice) {
case High:
scan = price >= highest(hi,period)* ((100 - choice1) /100);
case Low:
scan = price <= lowest(lo,period)* ((100 + choice1) /100);;
Would appreciate an explanation of how the code should be written. Or a tutorial or other script I could use.

Teach me how to fish.

input highestInXBars = 10;
input lookBackBars = 10;
def highestInBarsBack = Highest(high, highestInXBars);
def lastBar = !IsNaN(close) and IsNaN(close[-1]);
def targetHigh = if lastBar then highestInBarsBack[lookBackBars] else 0;
plot level = HighesT(targetHigh);

Last edited:

#### Prison Mike

##### Member
Pairing it with a squeeze study to find breakouts. But what I really want to try is to find the stocks that close X% below level2 with increased volume to try to get those good next day pops

Code:
``````input agg = AggregationPeriod.DAY;
input highestInXBars = 10;
input lookBackBars = 10;

input highestInXBars2 = 20;
input lookBackBars2 = 60;

input lowestInXBars = 5;
input lowlookBackBars = 5;

def hi = high(period = agg);
def price = close(period = agg);
def lo = low(period = agg);

def highestInBarsBack = Highest(hi, highestInXBars);
def lastBar = !IsNaN(price) and IsNaN(price[-1]);
def targetHigh = if lastBar then highestInBarsBack[lookBackBars] else 0;
plot level = HighestAll(targetHigh);

def highestInBarsBack2 = Highest(hi, highestInXBars2);
def lastBar2 = !IsNaN(price) and IsNaN(price[-1]);
def targetHigh2 = if lastBar2 then highestInBarsBack[lookBackBars2] else 0;
plot level2 = HighestAll(targetHigh2);

def lowestInBarsBack = Lowest(lo, lowestInXBars);
def lowlastBar = !IsNaN(price) and IsNaN(price[-1]);
def targetLow = if lowlastBar then lowestInBarsBack[lowlookBackBars] else Double.POSITIVE_INFINITY;
plot lowlevel = LowestAll(targetLow);

def risk = level - lowlevel;
def reward = level2 - level;

def RR = reward / risk;
def rr1=rr;

AddLabel(yes, "Risk/reward"+round(rr), if rr >= 2/1 then Color.green else Color.red);``````

scan
Code:
``````input price= close;

input highestInXBars = 10;
input lookBackBars = 10;
def highestInBarsBack = Highest(high, highestInXBars);
def lastBar = !IsNaN(close) and IsNaN(close[-1]);
def targetHigh = if lastBar then highestInBarsBack[lookBackBars] else 0;
def level = highestAll(targethigh);

input highestInXBars2 = 20;
input lookBackBars2 = 60;
def highestInBarsBack2 = Highest(high, highestInXBars2);
def lastBar2 = !IsNaN(close) and IsNaN(close[-1]);
def targetHigh2 = if lastBar2 then highestInBarsBack[lookBackBars2] else 0;
def level2 = highestAll(targethigh2);

input lowestInXBars = 5;
input lowlookBackBars = 5;
def lowestInBarsBack = Lowest(low, lowestInXBars);
def lowlastBar = !IsNaN(close) and IsNaN(close[-1]);
def targetLow = if lowlastBar then lowestInBarsBack[lowlookBackBars] else Double.POSITIVE_INFINITY;
def lowlevel = LowestAll(targetLow);

def risk= level- lowlevel;
def reward= level2- level;
def RR= reward/risk;

plot scan=
price <=level2 and level2 >=lowlevel and price >= lowlevel;``````

N

#### neurotic1234

##### New member
Is there a way to create a script to plot multiple price levels on a chart? For example, can I create a script to plot a horizontal price level line every 5 points on the chart?