Help drawing straight lines automatically

Learnbot

Active member
VIP
Hello,
I am using TOS engulfing candle code to find bullish and bearish engulfing candles (arrow in the image below). What I need help with is the candle right before the engulfing candle (indicated by the circle in the image below). I wanted to figure out a way to draw a horizontal line from the close of the candle to the top wick of the candle. I hope I explained it clearly, I tried using the PaintingStrategy but I am not familiar enough to make it work.

I really appreciate your help,

Thank you,

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2011-2020
#
#wizard plots
#wizard text: Inputs: length:
#wizard input: length
#wizard text: trend setup:
#wizard input: trendSetup

input length = 20;
input trendSetup = 3;

def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
    BodyMin < BodyMin[1];
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length)[1];

plot Bearish = IsAscending(close, trendSetup)[1] and
    (IsWhite[1] or IsPrevDoji) and
    IsBlack and
    IsEngulfing;

plot Bullish = IsDescending(close, trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing;

Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bearish.SetDefaultColor(GetColor(1));
Bearish.SetLineWeight(2);
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(2));
Bullish.SetLineWeight(2);

Screen-Shot-2020-12-10-at-6-24-11-PM.png
 

Learnbot

Active member
VIP
Why not research Patterns in the Learning Center... The detection for most patterns are there, otherwise you can create your own... Built right into TOS...
Yup thats what I am doing, the code above is TOS's pattern recognition code. so what I am trying to do is draw major price action moving areas. So basically TOS code identifies bullish or bearing engulfing candle right and then what I do is I look at the candle before it and then manually draw lines, so u can imagine looking at 1hr, 4hr, 45 min and so on takes me forever to draw these lines so wanted to automate the process. I tried adding this
Code:
Bullish.SetPaintingStrategy(PaintingStrategy.squares);
at the end of the script but for some reason I cant get lines to appear. Thank you
 

BenTen

Administrative
Staff
VIP
Like this?

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2011-2020
#
#wizard plots
#wizard text: Inputs: length:
#wizard input: length
#wizard text: trend setup:
#wizard input: trendSetup

input length = 20;
input trendSetup = 3;

def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
    BodyMin < BodyMin[1];
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length)[1];

plot Bearish = IsAscending(close, trendSetup)[1] and
    (IsWhite[1] or IsPrevDoji) and
    IsBlack and
    IsEngulfing;

plot Bullish = IsDescending(close, trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing;

Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bearish.SetDefaultColor(GetColor(1));
Bearish.SetLineWeight(2);
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(2));
Bullish.SetLineWeight(2);

def condition = bullish or bearish;

def b_high = if condition then high[1] else b_high[1];
def b_low = if condition then close[1] else b_low[1];

plot hh = b_high[1];
plot ll = b_low[1];

hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh.SetDefaultColor(Color.YELLOW);
ll.SetDefaultColor(Color.YELLOW);
 

Learnbot

Active member
VIP
@BenTen Thats exactly what I am looking for, two tweaks if it's not too much to ask plz. I would like the lines to start at the candle (if possible), plz refer to the yellow arrows in the image below. and also for bear engulfing candle, the lines are not plotted at the right level. For bear flag lines should be at open of the candle and the highest wick as shown in the image below in red circle and red lines...Also is there a way to extend the lines all the way to the right so I can spot over laps between different areas?

I really appreciate it and thank you for your time

Screen-Shot-2020-12-10-at-7-16-14-PM.png
 

BenTen

Administrative
Staff
VIP
@Learnbot Partial fix below. Not sure how to make the start line starts at the candle before the engulfing pattern, so you would have to live it that for now.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2011-2020
#
#wizard plots
#wizard text: Inputs: length:
#wizard input: length
#wizard text: trend setup:
#wizard input: trendSetup

input length = 20;
input trendSetup = 3;

def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
    BodyMin < BodyMin[1];
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length)[1];

plot Bearish = IsAscending(close, trendSetup)[1] and
    (IsWhite[1] or IsPrevDoji) and
    IsBlack and
    IsEngulfing;

plot Bullish = IsDescending(close, trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing;

Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bearish.SetDefaultColor(GetColor(1));
Bearish.SetLineWeight(2);
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(2));
Bullish.SetLineWeight(2);

def bu_high = if bullish then high[1] else bu_high[1];
def bu_low = if bullish then close[1] else bu_low[1];
def be_high = if bearish then high[1] else be_high[1];
def be_low = if bearish then open[1] else be_low[1];

plot bu_hh = bu_high[1];
plot bu_ll = bu_low[1];
plot be_hh = be_high[1];
plot be_ll = be_low[1];

bu_hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bu_ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bu_hh.SetDefaultColor(Color.YELLOW);
bu_ll.SetDefaultColor(Color.YELLOW);
be_hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
be_ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
be_hh.SetDefaultColor(Color.YELLOW);
be_ll.SetDefaultColor(Color.YELLOW);
 

generic

Active member
@Learnbot Change the [1] from the 4 plots to [-1] and they'll draw from the candle you want. This will make the study repaint by 1 bar but I think in your case it shouldn't be a problem for what you're trying to do with it.
 

Learnbot

Active member
VIP
@generic and @BenTen One more question plz, I want the arrows to show only on 15min time frame how can I do that? The current script i came up with shows arrows on 15min, 5 min and on 1 min, but does show on higher than 15 min time frames so i am missing something but i don't know what... i tried to add IF..ELSE as u can see in my code but i don't know what veriabe would go after else lol

thank you both
Code:
def fifteen_min_bool;
# Set Chart for 15mm
if GetAggregationPeriod() == AggregationPeriod.FIFTEEN_MIN {
    fifteen_min_bool = 1;
} else {
    fifteen_min_bool = 0;
}
#def ltDay = if GetAggregationPeriod() == AggregationPeriod.fifteen_min then 1 else Double.NaN;

input length = 20;
input trendSetup = 3;


def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and BodyMin < BodyMin[1];
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length)[1];




#if GetAggregationPeriod() <= AggregationPeriod.fifteen_min {
    plot Bearish_15 = IsAscending(close(period = AggregationPeriod.FIFTEEN_MIN), trendSetup)[1] and
    (IsWhite[1] or IsPrevDoji) and
    IsBlack and
    IsEngulfing;

    plot Bullish_15 = IsDescending(close(period = AggregationPeriod.FIFTEEN_MIN), trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing;

    Bearish_15.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
    Bearish_15.SetDefaultColor(GetColor(1));
    Bearish_15.SetLineWeight(2);
    Bullish_15.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
    Bullish_15.SetDefaultColor(GetColor(2));
    Bullish_15.SetLineWeight(2);
#} else {#}
 

generic

Active member
@Learnbot Change the current_agg to make it show up on different aggs.
Code:
#
#
# TD Ameritrade IP Company, Inc. (c) 2011-2020
#
#wizard plots
#wizard text: Inputs: length:
#wizard input: length
#wizard text: trend setup:
#wizard input: trendSetup

input length = 20;
input trendSetup = 3;
input current_agg = AggregationPeriod.FIFTEEN_MIN;

def nan = Double.NaN;
def fifteen = GetAggregationPeriod() == current_agg;
def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
    BodyMin < BodyMin[1];
def IsWhite = open < close;
def IsBlack = open > close;
def IsPrevDoji = IsDoji(length)[1];

plot Bearish = IsAscending(close, trendSetup)[1] and
    (IsWhite[1] or IsPrevDoji) and
    IsBlack and
    IsEngulfing and
    fifteen;

plot Bullish = IsDescending(close, trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing and
    fifteen;

Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Bearish.SetDefaultColor(GetColor(1));
Bearish.SetLineWeight(2);
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(2));
Bullish.SetLineWeight(2);

def bu_high = if bullish and fifteen then high[1] else bu_high[1];
def bu_low = if bullish and fifteen then close[1] else bu_low[1];
def be_high = if bearish and fifteen then high[1] else be_high[1];
def be_low = if bearish and fifteen then open[1] else be_low[1];

def buhh = if IsNaN(close) then buhh[1] else bu_high; 
def bull = if IsNaN(close) then bull[1] else bu_low;
def behh = if IsNaN(close) then behh[1] else be_high;
def bell = if IsNaN(close) then bell[1] else be_low;

plot bu_hh = buhh;
plot bu_ll = bull;
plot be_hh = behh;
plot be_ll = bell;

bu_hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bu_ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bu_hh.SetDefaultColor(Color.YELLOW);
bu_ll.SetDefaultColor(Color.YELLOW);
be_hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
be_ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
be_hh.SetDefaultColor(Color.YELLOW);
be_ll.SetDefaultColor(Color.YELLOW);
 

Similar threads

Top