Active Price Line

powerhousescott

New member
VIP
I have looked all over TOS for a way to display the price line. I could not find that setting in their software. I was working on placing a close line in another indicator and then came up with this. I have placed how I am using it in a description of the code. If you do not desire all the other lines. Just either delete those lines from the code or turn their plots off. I currently have it set to work in the 1 min, 1 hour, 1 day as default. In the end I still have confliction in the other indicator that I am working on. I will figure it out, I thought I would share this in case others prefer to have an active price line to help with support and resistance trading. Happy trading to all.

Code:
#Active Price Line by Alfred Scott Jordan  09/18/22
#This study plots a close or open line according to then aggregation periods desired. 
#If you have the Day close activated and the lowest time frame close activated it will in effect, give you a price line across the chart until that days final close. 
#I have found that by using the open and close for the middle time frame that it will show an accurate support and resistance for the lowest time frame.
#You will need to make adjustments to the various time frames that you trade in.  Set the lowest period for the one you use the most, then middle time frame a few up from that and then set the highest time frame accordingly. 
#For the Day chart set Day to the lowest, then week for the middle and month for the highest.  #

declare upper;
input aggregationPeriodMinute = AggregationPeriod.MIN;
input aggregationPeriodhour = AggregationPeriod.HOUR;
input aggregationPeriodDay = AggregationPeriod.DAY;
input length = 1;
input showOnlyLastPeriod = no;


#Minute Settings
plot PrevMinuteClose; if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriodMinute) [-1]) {PrevMinuteClose = Double.NaN;} else {PrevMinuteClose = Highest(close(period = aggregationPeriodMinute), length);}

PrevMinuteClose.SetLineWeight(5);
PrevMinuteClose.SetDefaultColor(Color.CYAN);
PrevMinuteClose.SetPaintingStrategy(PaintingStrategy.Horizontal);

plot PrevMinuteOpen; if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriodMinute) [-1]){PrevMinuteOpen = Double.NaN;} else {PrevMinuteOpen = Highest(open(period = aggregationPeriodMinute), length);}

PrevMinuteOpen.SetLineWeight(3);
PrevMinuteOpen.SetDefaultColor(Color.PINK);
PrevMinuteOpen.SetPaintingStrategy(PaintingStrategy.Horizontal);


#Hour Settings
plot PrevHourClose; if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriodhour) [-1])
{PrevHourClose = Double.NaN;} else {PrevHourClose = Highest(close(period = aggregationPeriodhour), length);}

PrevHourClose.SetLineWeight(5);
PrevHourClose.SetDefaultColor(Color.CYAN);
PrevHourClose.SetPaintingStrategy(PaintingStrategy.line);


plot PrevHourOpen; if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriodhour) [-1])
 {PrevHourOpen = Double.NaN;} else {PrevHourOpen = Highest(open(period = aggregationPeriodhour), length);}

PrevHourOpen.SetLineWeight(3);
PrevHourOpen.SetDefaultColor(Color.yellow);
PrevHourOpen.SetPaintingStrategy(PaintingStrategy.line); 

#Day Chart
plot PrevDayClose; if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriodDay) [-1])
 {PrevDayClose = Double.NaN;} else {PrevDayClose = Highest(close(period = aggregationPeriodDay), length);}

PrevDayClose.SetLineWeight(2);
PrevDayClose.SetDefaultColor(Color.White);
PrevDayClose.SetPaintingStrategy(PaintingStrategy.line);

plot PrevDayOpen; if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriodhour) [-1])
 {PrevDayOpen = Double.NaN;} else {PrevDayOpen = Highest(open(period = aggregationPeriodhour), length);} 

PrevDayOpen.SetLineWeight(3);
PrevDayOpen.SetDefaultColor(Color.light_GRAY);
PrevDayOpen.SetPaintingStrategy(PaintingStrategy.line);

#End of Active Price Line
 
Solution
What if I just needed to place that line above the close of one candle with extensions for the next 4 or 5 candles? Here is where I am currently at with this process.
#BullHi Plot and bubbles (This is where I believe that my problem lies)
#I want a line placed at top of the BullHi Candle with extensions
# for up to 4 or 5 candles.

all, please post the complete code, when asking for help in fixing your code.
you will get a faster response if you do.

i copied the code from post6, and was going to try an idea, when i realized there were several variables that were missing, because it was a partial code.
now i had no trigger signals to test my idea... so i had to create new code, before i could test it...
I have looked all over TOS for a way to display the price line. I could not find that setting in their software. I was working on placing a close line in another indicator and then came up with this. I have placed how I am using it in a description of the code. If you do not desire all the other lines. Just either delete those lines from the code or turn their plots off. I currently have it set to work in the 1 min, 1 hour, 1 day as default. In the end I still have confliction in the other indicator that I am working on. I will figure it out, I thought I would share this in case others prefer to have an active price line to help with support and resistance trading. Happy trading to all.

Code:
#Active Price Line by Alfred Scott Jordan  09/18/22
#This study plots a close or open line according to then aggregation periods desired.
#If you have the Day close activated and the lowest time frame close activated it will in effect, give you a price line across the chart until that days final close.
#I have found that by using the open and close for the middle time frame that it will show an accurate support and resistance for the lowest time frame.
#You will need to make adjustments to the various time frames that you trade in.  Set the lowest period for the one you use the most, then middle time frame a few up from that and then set the highest time frame accordingly.
#For the Day chart set Day to the lowest, then week for the middle and month for the highest.  #

declare upper;
input aggregationPeriodMinute = AggregationPeriod.MIN;
input aggregationPeriodhour = AggregationPeriod.HOUR;
input aggregationPeriodDay = AggregationPeriod.DAY;
input length = 1;
input showOnlyLastPeriod = no;


#Minute Settings
plot PrevMinuteClose; if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriodMinute) [-1]) {PrevMinuteClose = Double.NaN;} else {PrevMinuteClose = Highest(close(period = aggregationPeriodMinute), length);}

PrevMinuteClose.SetLineWeight(5);
PrevMinuteClose.SetDefaultColor(Color.CYAN);
PrevMinuteClose.SetPaintingStrategy(PaintingStrategy.Horizontal);

plot PrevMinuteOpen; if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriodMinute) [-1]){PrevMinuteOpen = Double.NaN;} else {PrevMinuteOpen = Highest(open(period = aggregationPeriodMinute), length);}

PrevMinuteOpen.SetLineWeight(3);
PrevMinuteOpen.SetDefaultColor(Color.PINK);
PrevMinuteOpen.SetPaintingStrategy(PaintingStrategy.Horizontal);


#Hour Settings
plot PrevHourClose; if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriodhour) [-1])
{PrevHourClose = Double.NaN;} else {PrevHourClose = Highest(close(period = aggregationPeriodhour), length);}

PrevHourClose.SetLineWeight(5);
PrevHourClose.SetDefaultColor(Color.CYAN);
PrevHourClose.SetPaintingStrategy(PaintingStrategy.line);


plot PrevHourOpen; if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriodhour) [-1])
 {PrevHourOpen = Double.NaN;} else {PrevHourOpen = Highest(open(period = aggregationPeriodhour), length);}

PrevHourOpen.SetLineWeight(3);
PrevHourOpen.SetDefaultColor(Color.yellow);
PrevHourOpen.SetPaintingStrategy(PaintingStrategy.line);

#Day Chart
plot PrevDayClose; if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriodDay) [-1])
 {PrevDayClose = Double.NaN;} else {PrevDayClose = Highest(close(period = aggregationPeriodDay), length);}

PrevDayClose.SetLineWeight(2);
PrevDayClose.SetDefaultColor(Color.White);
PrevDayClose.SetPaintingStrategy(PaintingStrategy.line);

plot PrevDayOpen; if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriodhour) [-1])
 {PrevDayOpen = Double.NaN;} else {PrevDayOpen = Highest(open(period = aggregationPeriodhour), length);}

PrevDayOpen.SetLineWeight(3);
PrevDayOpen.SetDefaultColor(Color.light_GRAY);
PrevDayOpen.SetPaintingStrategy(PaintingStrategy.line);

#End of Active Price Line
If you just need a price line on the chart all you need is this:
Code:
plot priceLine = highestAll(if isNan(close[-1]) and !isNAN(close) then close else double.nan);
 

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

I have looked all over TOS for a way to display the price line. I could not find that setting in their software. I was working on placing a close line in another indicator and then came up with this. I have placed how I am using it in a description of the code. If you do not desire all the other lines. Just either delete those lines from the code or turn their plots off. I currently have it set to work in the 1 min, 1 hour, 1 day as default. In the end I still have confliction in the other indicator that I am working on. I will figure it out, I thought I would share this in case others prefer to have an active price line to help with support and resistance trading. Happy trading to all.

Code:
#Active Price Line by Alfred Scott Jordan  09/18/22
#This study plots a close or open line according to then aggregation periods desired.
#If you have the Day close activated and the lowest time frame close activated it will in effect, give you a price line across the chart until that days final close.
#I have found that by using the open and close for the middle time frame that it will show an accurate support and resistance for the lowest time frame.
#You will need to make adjustments to the various time frames that you trade in.  Set the lowest period for the one you use the most, then middle time frame a few up from that and then set the highest time frame accordingly.
#For the Day chart set Day to the lowest, then week for the middle and month for the highest.  #

declare upper;
input aggregationPeriodMinute = AggregationPeriod.MIN;
input aggregationPeriodhour = AggregationPeriod.HOUR;
input aggregationPeriodDay = AggregationPeriod.DAY;
input length = 1;
input showOnlyLastPeriod = no;


#Minute Settings
plot PrevMinuteClose; if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriodMinute) [-1]) {PrevMinuteClose = Double.NaN;} else {PrevMinuteClose = Highest(close(period = aggregationPeriodMinute), length);}

PrevMinuteClose.SetLineWeight(5);
PrevMinuteClose.SetDefaultColor(Color.CYAN);
PrevMinuteClose.SetPaintingStrategy(PaintingStrategy.Horizontal);

plot PrevMinuteOpen; if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriodMinute) [-1]){PrevMinuteOpen = Double.NaN;} else {PrevMinuteOpen = Highest(open(period = aggregationPeriodMinute), length);}

PrevMinuteOpen.SetLineWeight(3);
PrevMinuteOpen.SetDefaultColor(Color.PINK);
PrevMinuteOpen.SetPaintingStrategy(PaintingStrategy.Horizontal);


#Hour Settings
plot PrevHourClose; if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriodhour) [-1])
{PrevHourClose = Double.NaN;} else {PrevHourClose = Highest(close(period = aggregationPeriodhour), length);}

PrevHourClose.SetLineWeight(5);
PrevHourClose.SetDefaultColor(Color.CYAN);
PrevHourClose.SetPaintingStrategy(PaintingStrategy.line);


plot PrevHourOpen; if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriodhour) [-1])
 {PrevHourOpen = Double.NaN;} else {PrevHourOpen = Highest(open(period = aggregationPeriodhour), length);}

PrevHourOpen.SetLineWeight(3);
PrevHourOpen.SetDefaultColor(Color.yellow);
PrevHourOpen.SetPaintingStrategy(PaintingStrategy.line);

#Day Chart
plot PrevDayClose; if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriodDay) [-1])
 {PrevDayClose = Double.NaN;} else {PrevDayClose = Highest(close(period = aggregationPeriodDay), length);}

PrevDayClose.SetLineWeight(2);
PrevDayClose.SetDefaultColor(Color.White);
PrevDayClose.SetPaintingStrategy(PaintingStrategy.line);

plot PrevDayOpen; if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriodhour) [-1])
 {PrevDayOpen = Double.NaN;} else {PrevDayOpen = Highest(open(period = aggregationPeriodhour), length);}

PrevDayOpen.SetLineWeight(3);
PrevDayOpen.SetDefaultColor(Color.light_GRAY);
PrevDayOpen.SetPaintingStrategy(PaintingStrategy.line);

#End of Active Price Line
very helpful display.....are you overlaying any scalping or volume indicators
 
If you just need a price line on the chart all you need is this:
Code:
plot priceLine = highestAll(if isNan(close[-1]) and !isNAN(close) then close else double.nan);
Thanks, I went about it the long way. That snippet will help me a lot. I have not done any coding since back in the 80's and early 90's so my style may be a bit antiquated.
 
very helpful display.....are you overlaying any scalping or volume indicators

Yes, I have been working up a mockup version utilizing the PSAR indicator showing a bubble countdown and percentages. I found that the code while is very accurate most of the time it has a couple of hiccups here and there. I posted it the other day asking for help but got admonished by an administrator for not using the TOS share chart instead of just posting a picture with the imugr app as used in the example. I figured that I would just operate in this fashion until I get the indicator totally done for myself. Sometimes the struggle to overcome will make one even more successful in the long run.
 
If you just need a price line on the chart all you need is this:
Code:
plot priceLine = highestAll(if isNan(close[-1]) and !isNAN(close) then close else double.nan);
What if I just needed to place that line above the close of one candle with extensions for the next 4 or 5 candles? Here is where I am currently at with this process.
Code:
#BullHi Plot and bubbles (This is where I believe that my problem lies)
#I want a line placed at top of the BullHi Candle with extensions
# for up to 4 or 5 candles.

plot bullHi = close >= hLine and transitionBull [PSAR_Cross];
bullHi.setLineWeight (5);
bullHi.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullHi.SetDefaultColor(Color.LIGHT_GREEN);

#I was trying a variation of the snippet you gave me here

Plot BullHiCloseLine= if close(period=BullHi)[-1] then double.nan else Highest(close(period=BullHi));
BullHiCloseLine.setLineWeight (5);
BullHiCloseLine.SetPaintingStrategy (PaintingStrategy.line);
BullHiCloseLine.SetDefaultColor (Color.Violet);

plot BHiClose = close and bullHi;
BHiClose.setLineWeight (5);
BHiClose.SetPaintingStrategy(PaintingStrategy.Boolean_WEDGE_UP);
BHiClose.SetDefaultColor(Color.LIGHT_GREEN);

plot BHmark = bullhi;


def bullHi1 =  close > hline and BHiClose from Candle_Count_1 bars ago;
AddChartBubble(bullHi1,(open + close)/2, Candle_Count_1 , Color.LIGHT_GREEN);

def bullHi2 =  close > hline and BHiClose from Candle_Count_2 bars ago;
AddChartBubble(bullHi2, close, Candle_Count_2, Color.LIGHT_GREEN);

def bullHi3 =  close > hline and BHiClose from Candle_Count_3 bars ago;
AddChartBubble(bullHi3, close, Candle_Count_3, Color.LIGHT_GREEN);
 
What if I just needed to place that line above the close of one candle with extensions for the next 4 or 5 candles? Here is where I am currently at with this process.
#BullHi Plot and bubbles (This is where I believe that my problem lies)
#I want a line placed at top of the BullHi Candle with extensions
# for up to 4 or 5 candles.

all, please post the complete code, when asking for help in fixing your code.
you will get a faster response if you do.

i copied the code from post6, and was going to try an idea, when i realized there were several variables that were missing, because it was a partial code.
now i had no trigger signals to test my idea... so i had to create new code, before i could test it.

----------------------------

this draws a white horizontal line from a bar when trigger is true , for some quantity of bars.

can enter how many bars you want the line to be.
if 2 triggers happen in less bars than the line length, the first line stops and a new line starts. there is no overlap of 2 lines. that would require 2 plot formulas.


Ruby:
# ma1_ma2_ext_line_xbars_01

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

#/////////////////////////////////////
# test data, to create triggers , to draw horizontal lines from

def price = close;
#input ma1_len = 11;
def ma1_len = 11;
#input ma1_type =  AverageType.EXPONENTIAL;
def ma1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(ma1_type, price, ma1_len);
#input ma2_len = 44;
def ma2_len = 44;
#input ma2_type =  AverageType.EXPONENTIAL;
def ma2_type =  AverageType.EXPONENTIAL;
def ma2 = MovingAverage(ma2_type, price, ma2_len);

#input show_lines = yes;
def show_lines = 1;
plot z1 = if show_lines then ma1 else na;
z1.setdefaultcolor(getcolor(1));
#z1.setlineweight(1);
z1.hidebubble();
plot z2 = if show_lines then ma2 else na;
z2.setdefaultcolor(getcolor(2));
#z2.setlineweight(1);
z2.hidebubble();

#---------------------------------
#input show_cloud = no;
#addcloud((if show_cloud then ma1 else na), ma2, color.light_green, color.magenta);
#addcloud((if show_cloud then ma2 else na), ma1, color.light_red, color.magenta);

#/////////////////////////////////////

# trigger is true on the bar to start drawing a line
# change trigger formula, to be equal to your trigger variable
def trigger = (ma1 crosses ma2);
addverticalline( trigger, "-", color.blue);

#===================================


# extend a line from some bar, for x bars

input extend_line_for_xbars = 6;
input price2 = high;

def start_bn;
def end_bn;
def line_level;
if bn == 1 then {
  start_bn = 0;
  end_bn = 0;
  line_level = 0;
} else if trigger then {
  start_bn = bn;
  end_bn = (bn + extend_line_for_xbars - 1);
  line_level = price2;
} else if (bn >= start_bn[1] and bn <= end_bn[1]) then {
  start_bn = start_bn[1];
  end_bn = end_bn[1];
  line_level =  line_level[1];
} else {
  start_bn = 0;
  end_bn = 0;
  line_level = 0;
}

plot zh = if line_level == 0 then na else line_level;
zh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zh.setdefaultcolor(color.white);
zh.setlineweight(3);
#
 
Solution
all, please post the complete code, when asking for help in fixing your code.
you will get a faster response if you do.

i copied the code from post6, and was going to try an idea, when i realized there were several variables that were missing, because it was a partial code.
now i had no trigger signals to test my idea... so i had to create new code, before i could test it.

----------------------------

this draws a white horizontal line from a bar when trigger is true , for some quantity of bars.

can enter how many bars you want the line to be.
if 2 triggers happen in less bars than the line length, the first line stops and a new line starts. there is no overlap of 2 lines. that would require 2 plot formulas.


Ruby:
# ma1_ma2_ext_line_xbars_01

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

#/////////////////////////////////////
# test data, to create triggers , to draw horizontal lines from

def price = close;
#input ma1_len = 11;
def ma1_len = 11;
#input ma1_type =  AverageType.EXPONENTIAL;
def ma1_type =  AverageType.EXPONENTIAL;
def ma1 = MovingAverage(ma1_type, price, ma1_len);
#input ma2_len = 44;
def ma2_len = 44;
#input ma2_type =  AverageType.EXPONENTIAL;
def ma2_type =  AverageType.EXPONENTIAL;
def ma2 = MovingAverage(ma2_type, price, ma2_len);

#input show_lines = yes;
def show_lines = 1;
plot z1 = if show_lines then ma1 else na;
z1.setdefaultcolor(getcolor(1));
#z1.setlineweight(1);
z1.hidebubble();
plot z2 = if show_lines then ma2 else na;
z2.setdefaultcolor(getcolor(2));
#z2.setlineweight(1);
z2.hidebubble();

#---------------------------------
#input show_cloud = no;
#addcloud((if show_cloud then ma1 else na), ma2, color.light_green, color.magenta);
#addcloud((if show_cloud then ma2 else na), ma1, color.light_red, color.magenta);

#/////////////////////////////////////

# trigger is true on the bar to start drawing a line
# change trigger formula, to be equal to your trigger variable
def trigger = (ma1 crosses ma2);
addverticalline( trigger, "-", color.blue);

#===================================


# extend a line from some bar, for x bars

input extend_line_for_xbars = 6;
input price2 = high;

def start_bn;
def end_bn;
def line_level;
if bn == 1 then {
  start_bn = 0;
  end_bn = 0;
  line_level = 0;
} else if trigger then {
  start_bn = bn;
  end_bn = (bn + extend_line_for_xbars - 1);
  line_level = price2;
} else if (bn >= start_bn[1] and bn <= end_bn[1]) then {
  start_bn = start_bn[1];
  end_bn = end_bn[1];
  line_level =  line_level[1];
} else {
  start_bn = 0;
  end_bn = 0;
  line_level = 0;
}

plot zh = if line_level == 0 then na else line_level;
zh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zh.setdefaultcolor(color.white);
zh.setlineweight(3);
#
You are correct I should have sent the whole code over. I don't know what I was thinking.
Code:
# Pars Contraction Box
# draw a box from the last dot on the old ParabolicSar Trend to the current dot?


# PSAR Transition Indicator
# tomsk
# 11.20.2019

# V1.0 - 11.20.2019 - tomsk - Initial release of PSAR Transition Indicator

# This study looks for a PSAR state transition (either from bullish to bearish
# or vice versa) and plots a horizontal price line into the expansion area. If
# the state transition already triggered, it calculates the number of bars ago
# the event happened. I've included labels, alerts as well as chart bubbles

declare upper;

input show_bubbles = yes;
input count_labels = yes;
input Candle_Count_1 = 3;
input Candle_Count_2 = 4;
input Candle_Count_3 = 5;
input PSAR_Cross = 1;
input show_price_color = yes;
input accelerationFactor = 0.02;
input accelerationLimit = 0.2;
input offSet = 2;

#PSAR Code
Assert(accelerationFactor > 0, "'acceleration factor' must be positive: " + accelerationFactor);
Assert(accelerationLimit >= accelerationFactor, "'acceleration limit' (" + accelerationLimit + ") must be greater than or equal to 'acceleration factor' (" + accelerationFactor + ")");

def bar = BarNumber();
def state = {default init, long, short};
def extreme;
def SAR;
def acc;

switch (state[1])
{case init:
    state = state.long;
    acc = accelerationFactor;
    extreme = high;
    SAR = low;
case short:
    if (SAR[1] < high)
    then {
        state = state.long;
        acc = accelerationFactor;
        extreme = high;
        SAR = extreme[1];}
 else
       {state = state.short;
        if (low < extreme[1])
        then {acc = Min(acc[1] + accelerationFactor, accelerationLimit);
            extreme = low;}
 else  {acc = acc[1];
        extreme = extreme[1];}
        SAR = Max(Max(high, high[1]), SAR[1] + acc * (extreme - SAR[1]));}

case long:
    if (SAR[1] > low)
    then {
        state = state.short;
        acc = accelerationFactor;
        extreme = low;
        SAR = extreme[1];}
    else
       {state = state.long;
        if (high > extreme[1])
    then
       {acc = Min(acc[1] + accelerationFactor, accelerationLimit);
        extreme = high;}
 else
       {acc = acc[1];
        extreme = extreme[1];}
        SAR = Min(Min(low, low[1]), SAR[1] + acc * (extreme - SAR[1]));}}

plot parSAR = SAR;
parSAR.SetLineWeight(2);
parSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
parSAR.AssignValueColor(if state == state.short then Color.MAGENTA else Color.GREEN);

plot parsar2 = SAR;
parsar2.SetLineWeight(5);
parsar2.SetPaintingStrategy(PaintingStrategy.SQUARES);
parsar2.SetDefaultColor(Color.WHITE);

#---------------------------
#Contraction Zone---------------------------

def bn = barnumber();
def na = double.nan;
def lastbar = !isnan(close[0]) and isnan(close[-1]);
def lastbn = HighestAll(If(IsNaN(close), 0, bn));

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

# last bar in trend series
def Bull2 = state[0] == state.short and state[-1] == state.long;
def Bear2 = state[0] == state.long and state[-1] == state.short;

# bn of last bar in trend
def chg_bn2 = if bn == 1 then 1
  else if bull2 or bear2 then bn
  else chg_bn2[1];

def last_chg_bn2 = highestall(chg_bn2);

#def prev_sar = if bn == 1 or isnan(close) then 0
def prev_sar = if bn == 1 then 0
  else if bn == last_chg_bn2 then sar
  else prev_sar[1];

def last_trend = (bn >= highestall(chg_bn2) and !isnan(close));

input draw_cloud_on_bars = yes;
plot p = if draw_cloud_on_bars and last_trend then prev_sar else na;
#p.SetStyle(Curve.MEDIUM_DASH);
p.SetDefaultColor(Color.light_gray);
p.setlineweight(2);
p.hidebubble();

def last_sar = highestall(if lastbn == bn then sar else 0);
def issarup = ( last_sar > prev_sar);

plot L = if draw_cloud_on_bars and last_trend then last_sar else na;
#l.SetStyle(Curve.MEDIUM_DASH);
L.AssignValueColor(if issarup then color.light_green else color.light_red);
L.setlineweight(1);
L.hidebubble();

addcloud(p,l,color.light_RED,color.light_GREEN);

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



def transitionBull = state[1] == state.short and state == state.long;
def transitionBear = state[1] == state.long and state == state.short;
def transitionBar = if transitionBull or transitionBear
                    then bar
                    else transitionBar[1];
def transitionPrice = if bar == (transitionBar)
                      then close
                      else transitionPrice[1];
def transitionBarsAgo = if bar != transitionBar
                 then bar - transitionBar
                 else if bar == transitionBar
                      then Double.NaN
                 else transitionBarsAgo[1];

#PSAR Transition Labels
AddLabel(transitionBull or transitionBear, "PSAR Trans Now!!!", Color.YELLOW);
AddLabel(!(transitionBull or transitionBear), "PSAR Trans " + transitionBarsAgo + " bars ago", Color.CYAN);
Alert(transitionBull, "PSAR Transition Bull", Alert.BAR, Sound.Ding);
Alert(transitionBear, "PSAR Transition Bear", Alert.BAR, Sound.Ring);

#Time Axis, Highline, Lowline
def timeAxis = if IsNaN(close[-1]) and !IsNaN(close) then bar else timeAxis[1];

def highline = if GetTime() <= RegularTradingEnd(GetYYYYMMDD()) and
                 transitionBar == (transitionBar)
                 then transitionPrice
                 else highline[1];

def lowline = if GetTime() <= RegularTradingEnd(GetYYYYMMDD()) and
                 transitionBar == (transitionBar)
                 then  (transitionPrice)
                 else lowline[1];

#Bull and Highline Plots
def bull = if transitionBull then 1 else if bull[1] == 1 and !transitionBear then 1 else 0;
def Bear = if transitionBear then 1 else if Bear[1] == 1 and !transitionBull then 1 else 0;


plot hLine = highline;
hLine.SetLineWeight(4);
hLine.AssignValueColor(if bull then Color.GREEN else Color.RED);
hLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot LLine = lowline;
LLine.SetLineWeight(4);
LLine.AssignValueColor(if Bear then Color.RED else Color.CYAN);
LLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#BullHi Plot and bubbles (This is where I believe that my problem lies)
#I want a line placed at top of the BullHi Candle with extensions
# for up to 4 or 5 candles. Then I only want the bubbles to show when
#their close is higher than BullHi or Lower than BullLo.

plot bullHi = close >= hline and transitionBull [PSAR_Cross];
bullHi.setLineWeight (5);
bullHi.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullHi.SetDefaultColor(Color.LIGHT_GREEN);

plot BHiClose = close and bullHi;
BHiClose.setLineWeight (5);
BHiClose.SetPaintingStrategy(PaintingStrategy.Boolean_wedge_UP);
BHiClose.SetDefaultColor(Color.LIGHT_GREEN);

plot BHmark = bullhi * 2;


def bullHi1 =  close > hline and BHiClose from Candle_Count_1 bars ago ;
AddChartBubble(bullHi1, close, Candle_Count_1 , Color.LIGHT_GREEN);

def bullHi2 =  close > hline and BHiClose from Candle_Count_2 bars ago;
AddChartBubble(bullHi2, close, Candle_Count_2, Color.LIGHT_GREEN);

def bullHi3 =  close > hline and BHiClose from Candle_Count_3 bars ago;
AddChartBubble(bullHi3, close, Candle_Count_3, Color.LIGHT_GREEN);

#Bull_high Counts and Labels
def CountBH = if bar == !bullHi then 0 else if bullHi then (CountBH [1] + 1) else CountBH [1];

def CountBH1 = if bar == !bullHi1 then 0 else if bullHi1  then (CountBH1[1] + 1) else CountBH1[1];

def CountBH2 = if bar == !bullHi2 then 0 else if bullHi2  then (CountBH2[1] + 1) else CountBH2[1];

def CountBH3 = if bar + 1 == !bullHi3 then 0 else if bullHi3  then (CountBH3[1] + 1) else CountBH3[1];

AddLabel(count_labels, "PSAR Hi Cnt " + CountBH + "  [CC " + Candle_Count_1 + "] " + Round(CountBH1 / CountBH * 100, 0) + "%" + "  [CC " + Candle_Count_2 + "] " + Round(CountBH2 / CountBH * 100, 0) + "%" + "  [CC " + Candle_Count_3 + "] " + Round(CountBH3 / CountBH * 100, 0) + "%", Color.LIGHT_GREEN);

#Bear Low Plot and bubbles
plot BearLo = close <= LLine and transitionBear [PSAR_Cross];
BearLo.setLineWeight (5);
BearLo.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
BearLo.SetDefaultColor(Color.LIGHT_ORANGE);

Plot BLoClose = close and BearLo;
BLoClose.setLineWeight (5);
BLoClose.SetPaintingStrategy(PaintingStrategy.Boolean_WEDGE_DOWN);
BLoClose.SetDefaultColor(Color.LIGHT_orange);

Plot BLoMark= BLoClose * 2;


def BearLo1 = close < LLine and BLoClose from Candle_Count_1 bars ago;
AddChartBubble(BearLo1, close, Candle_Count_1, Color.LIGHT_ORANGE);

def BearLo2 = close < LLine and BLoClose from Candle_Count_2 bars ago;
AddChartBubble(BearLo2, close, Candle_Count_2, Color.LIGHT_ORANGE);

def BearLo3 = close < LLine and BLoClose from Candle_Count_3 bars ago;
AddChartBubble(BearLo3, close, Candle_Count_3, Color.LIGHT_ORANGE);

#Bull_Low Counts and Labels
def CountBL = if bar == !BearLo then 0 else if BearLo  then (CountBL[1] + 1) else CountBL[1];

def CountBL1 = if bar == !BearLo1 then 0 else if BearLo1  then (CountBL1[1] + 1) else CountBL1[1];

def CountBL2 = if bar == !BearLo2 then 0 else if BearLo2  then (CountBL2[1] + 1) else CountBL2[1];

def CountBL3 = if bar == !BearLo3 then 0 else if BearLo3  then (CountBL3[1] + 1) else CountBL3[1];

AddLabel(count_labels, "PSAR Lo Cnt " + CountBL + "  [CC " + Candle_Count_1 + "] " + Round(CountBL1 / CountBL * 100, 0) + "%" + "  [CC " + Candle_Count_2 + "] " + Round(CountBL2 / CountBL * 100, 0) + "%" + "  [CC " + Candle_Count_3 + "] " + Round(CountBL3 / CountBL * 100, 0) + "%", Color.LIGHT_ORANGE);


# End PARS Transition Indicator

http://tos.mx/75cLTpu


I put the whole code in for your review. I also installed a link for the chart view but the TOS program eliminated the marker lines. So I added a picture for you as well using the imgur app. This is the way I have this figured that if I can get the bubble count and percentages to display more accurately. Then I can adjust the candle count to find the highest probability in each trade. If I can get this to function properly with 3,4 or 5, mins in the minute time frame then it will also work on others as well. Charts without statistics alongside of them are almost like a crap shoot. The same holds true in reverse,
Here is the basic problem that I am having. Some bubbles print according to the desires and what I believe that I have coded them to do. They are to only print when their close is above the up signal and the hline. In reverse they are to only print when their close is below the down signal and the LLine. Anything else throws the percentage count off. I am not concerned about getting more trades, just more accurate ones.

Thanks for any assistance halcyonguy
 
I ended up not needing to place an additional line as I first thought. It just took me a little while to figure out how to tell the TOS script what I wanted it to do. So here is the finished script that I updated.
Code:
# PSAR Transition Indicator
# tomsk
# 11.20.2019

# V1.0 - 11.20.2019 - tomsk - Initial release of PSAR Transition Indicator

# This study looks for a PSAR state transition (either from bullish to bearish
# or vice versa) and plots a horizontal price line into the expansion area. If
# the state transition already triggered, it calculates the number of bars ago
# the event happened. I've included labels, alerts as well as chart bubbles

# Update 09/21/22 by powerhousescott
# I have added price lines that you can turn on and off.  If working with upper charts you will #have to adjust the aggregation up by a couple of time frames as desired.
# I have added an adjustable candle count and bubbles with win percentage labels

declare upper;

#Price lines  will plot a horizontal bar at each close and and Active price line from a larger #time frame as desired.
input ShowPrice = yes;
input ShowPrevClose= yes;
input PriceAgg = AggregationPeriod.THREE_DAYS;

plot PrevClose = if !ShowPrevClose then double.NaN else close;
PrevClose.SetLineWeight(5);
PrevClose.SetDefaultColor(Color.CYAN);
PrevClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot ActivePriceLine=
if  !ShowPrice then Double.NaN else Highest(close(period = AggregationPeriod.TWO_DAYS), 1);
ActivePriceLine.SetLineWeight(5);
ActivePriceLine.SetDefaultColor(Color.White);
ActivePriceLine.SetPaintingStrategy(PaintingStrategy.LINE);



#PSAR Code

input accelerationFactor = 0.02;
input accelerationLimit = 0.2;



Assert(accelerationFactor > 0, "'acceleration factor' must be positive: " + accelerationFactor);
Assert(accelerationLimit >= accelerationFactor, "'acceleration limit' (" + accelerationLimit + ") must be greater than or equal to 'acceleration factor' (" + accelerationFactor + ")");

def bar = BarNumber();
def state = {default init, long, short};
def extreme;
def SAR;
def acc;

switch (state[1])
{
case init:
    state = state.long;
    acc = accelerationFactor;
    extreme = high;
    SAR = low;
case short:
    if (SAR[1] < high)
    then {
        state = state.long;
        acc = accelerationFactor;
        extreme = high;
        SAR = extreme[1];
    }
    else
    {
        state = state.short;
        if (low < extreme[1])
        then {
            acc = Min(acc[1] + accelerationFactor, accelerationLimit);
            extreme = low;
        }
        else  {
            acc = acc[1];
            extreme = extreme[1];
        }
        SAR = Max(Max(high, high[1]), SAR[1] + acc * (extreme - SAR[1]));
    }
case long:
    if (SAR[1] > low)
    then {
        state = state.short;
        acc = accelerationFactor;
        extreme = low;
        SAR = extreme[1];
    }
    else
    {
        state = state.long;
        if (high > extreme[1])
        then
        {
            acc = Min(acc[1] + accelerationFactor, accelerationLimit);
            extreme = high;
        }
        else
        {
            acc = acc[1];
            extreme = extreme[1];
        }
        SAR = Min(Min(low, low[1]), SAR[1] + acc * (extreme - SAR[1]));
    }
}

plot parSAR = SAR;
parSAR.SetLineWeight(2);
parSAR.SetPaintingStrategy(PaintingStrategy.POINTS);
parSAR.AssignValueColor(if state == state.short then Color.MAGENTA else Color.GREEN);

plot parsar2 = SAR;
parsar2.SetLineWeight(5);
parsar2.SetPaintingStrategy(PaintingStrategy.SQUARES);
parsar2.SetDefaultColor(Color.WHITE);

def transitionBull = state[1] == state.short and state == state.long;
def transitionBear = state[1] == state.long and state == state.short;
def transitionBar = if transitionBull or transitionBear
                    then bar
                    else (transitionBar[1]);
def transitionPrice = if bar == transitionBar
                      then close
                      else transitionPrice[1];
def transitionBarsAgo = if bar != transitionBar
                 then bar - transitionBar
                 else if bar ==  transitionBar
                      then Double.NaN
                 else transitionBarsAgo[1];

#PSAR Transition Labels
AddLabel(transitionBull or transitionBear, "PSAR Trans Now!!!", Color.YELLOW);
AddLabel(!(transitionBull or transitionBear), "PSAR Trans " + transitionBarsAgo + " bars ago", Color.CYAN);
Alert(transitionBull, "PSAR Transition Bull", Alert.BAR, Sound.Ding);
Alert(transitionBear, "PSAR Transition Bear", Alert.BAR, Sound.Ring);

#Time Axis, Highline, Lowline
def timeAxis = if IsNaN(close[-1]) and !IsNaN(close) then bar else timeAxis[1];

def highline = if transitionBar == Highest(transitionBar)
                 then transitionPrice
                 else highline[1];

def lowline = if transitionBar == LowestAll(transitionBar)
                 then  (transitionPrice)
                 else lowline[1];

#Bull and Highline Plots
def bull = if transitionBull then 1 else if bull[1] == 1 and !transitionBear then 1 else 0;
def Bear = if transitionBear then 1 else if Bear[1] == 1 and !transitionBull then 1 else 0;


plot hLine = highline;
hLine.SetLineWeight(4);
hLine.AssignValueColor(if bull then Color.GREEN else Color.RED);
hLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot LLine = lowline;
LLine.SetLineWeight(4);
LLine.AssignValueColor(if Bear then Color.RED else Color.CYAN);
LLine.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#BullHi Plot, Bubbles, Marker

input show_bubbles = yes;
input count_labels = yes;
input markers=yes;
input Candle_Count_1 = 3;
input Candle_Count_2 = 4;
input Candle_Count_3 = 5;
input Pars_Cross = 1;

plot bullHi = close >= hLine and transitionBull [Pars_Cross] ;
bullHi.SetLineWeight (5);
bullHi.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullHi.SetDefaultColor(Color.LIGHT_GREEN);

plot BHmark = if !markers then double.nan else bullHi * 2;

def bullHi1 =   bullhi  from Candle_Count_1 bars ago and close > close [Candle_Count_1];
AddChartBubble(if !Show_Bubbles then double.NaN else bullHi1, close, Candle_Count_1 , Color.LIGHT_GREEN);


def bullHi2 =  bullhi  from Candle_Count_2 bars ago and close > close [Candle_Count_2];
AddChartBubble(if !Show_Bubbles then double.Nan else bullHi2, close, Candle_Count_2, Color.LIGHT_GREEN);

def bullHi3 =  bullhi  from Candle_Count_3 bars ago and close > close [Candle_Count_3] ;;
AddChartBubble(if !Show_Bubbles then double.nan else bullHi3, close, Candle_Count_3, Color.LIGHT_GREEN);



#Bull_high Counts and Labels
def CountBH = if bar == !bullHi then 0 else if bullHi then (CountBH [1] + 1) else CountBH [1];

def CountBH1 = if bar == !bullHi1 then 0 else if bullHi1  then (CountBH1[1] + 1) else CountBH1[1];

def CountBH2 = if bar == !bullHi2 then 0 else if bullHi2  then (CountBH2[1] + 1) else CountBH2[1];

def CountBH3 = if bar + 1 == !bullHi3 then 0 else if bullHi3  then (CountBH3[1] + 1) else CountBH3[1];

AddLabel(count_labels, "PARS Hi Cnt " + CountBH + "  [CC " + Candle_Count_1 + "] " + Round(CountBH1 / CountBH * 100, 0) + "%" + "  [CC " + Candle_Count_2 + "] " + Round(CountBH2 / CountBH * 100, 0) + "%" + "  [CC " + Candle_Count_3 + "] " + Round(CountBH3 / CountBH * 100, 0) + "%", Color.LIGHT_GREEN);

#Bear Low Plot and bubbles
plot BearLo = close <= LLine and transitionBear [PARS_Cross];
BearLo.SetLineWeight (5);
BearLo.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
BearLo.SetDefaultColor(Color.LIGHT_ORANGE);

plot BLoClose = close and BearLo;
BLoClose.SetLineWeight (5);
BLoClose.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
BLoClose.SetDefaultColor(Color.LIGHT_ORANGE);

plot BLoMark = if !markers then double.nan else BLoClose * 2;


def BearLo1 = BearLo  from Candle_Count_1 bars ago and close < close [Candle_Count_1] ;
AddChartBubble(BearLo1, close, Candle_Count_1, Color.LIGHT_ORANGE);

def BearLo2 = BearLo  from Candle_Count_2 bars ago and close < close [Candle_Count_2] ;
AddChartBubble(BearLo2, close, Candle_Count_2, Color.LIGHT_ORANGE);

def BearLo3 = BearLo  from Candle_Count_3 bars ago and close < close [Candle_Count_3] ;
AddChartBubble(BearLo3, close, Candle_Count_3, Color.LIGHT_ORANGE);

#Bull_Low Counts and Labels
def CountBL = if bar == !BearLo then 0 else if BearLo  then (CountBL[1] + 1) else CountBL[1];

def CountBL1 = if bar == !BearLo1 then 0 else if BearLo1  then (CountBL1[1] + 1) else CountBL1[1];

def CountBL2 = if bar == !BearLo2 then 0 else if BearLo2  then (CountBL2[1] + 1) else CountBL2[1];

def CountBL3 = if bar == !BearLo3 then 0 else if BearLo3  then (CountBL3[1] + 1) else CountBL3[1];

AddLabel(count_labels, "PSAR Lo Cnt " + CountBL + "  [CC " + Candle_Count_1 + "] " + Round(CountBL1 / CountBL * 100, 0) + "%" + "  [CC " + Candle_Count_2 + "] " + Round(CountBL2 / CountBL * 100, 0) + "%" + "  [CC " + Candle_Count_3 + "] " + Round(CountBL3 / CountBL * 100, 0) + "%", Color.LIGHT_ORANGE);




# End PARS Transition Indicator

https://tos.mx/y3E7juD
 
If you just need a price line on the chart all you need is this:
Code:
plot priceLine = highestAll(if isNan(close[-1]) and !isNAN(close) then close else double.nan);

Greetings all and thank you to the original poster and the replies on this thread. I would like to ask if It is possible for TOS to mark the Price AT a specific time of day. My Idea is to specifically identify the price at a premarket level. I don't have any code to share; as opposed to seeing if this specific code can be expounded upon.

Thank you.
 
Greetings all and thank you to the original poster and the replies on this thread. I would like to ask if It is possible for TOS to mark the Price AT a specific time of day. My Idea is to specifically identify the price at a premarket level. I don't have any code to share; as opposed to seeing if this specific code can be expounded upon.

Thank you.

This might help.

It includes an approximation to plot the line if the chart timeframe you are using does not have that exact time.

For example, in the image below, if you want 0532, which exists on a 1min chart and switch to a 5min chart where that time does not exist, a line will be drawn from a bar approximating that time on a 5min chart.

Screenshot-2022-10-16-061050.png
Ruby:
input time = 0548;
def timeline = if secondsfromTime(time)[1]<=0 and secondstillTime(time)>=0 then high else timeline[1];
plot line = timeline;
line.setpaintingStrategy(paintingStrategy.HORIZONTAL);
 
This might help.

It includes an approximation to plot the line if the chart timeframe you are using does not have that exact time.

For example, in the image below, if you want 0532, which exists on a 1min chart and switch to a 5min chart where that time does not exist, a line will be drawn from a bar approximating that time on a 5min chart.
Thank you very much! this is what i had in mind! will attempt to use this moving forward.. Many thanks!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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