Help drawing straight lines automatically

Learnbot

Active member
@generic quick question, so per your script provided above I can change current_agg to plot the lines on different aggregation however, I do have a question. is there a way to plot the 15 min aggregation lines on 5 min chart? What this script does for me is it plots major moves and then I go down into smaller time frame to further refine those areas to find future supply and demand zones.
 

Learnbot

Active member
@Learnbot It will show but if you're doing this for live trading then it can repaint because you're using higher aggregation.
oh ok.. I just use it to draw key levels on chart before the market opens so I don't think repainting would affect it (I think ) I use a higher time frame because little noise aka false signals u know what I mean.. thank you buddy for your time
 

Learnbot

Active member
@BenTen @generic
@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);
one more question plz, so this indicator is working well for me however I do have a quick question. So currently I check 1hr time frame then 45min and then 15 min time frame, to draw my levels however i wanted to see if there is a way to plot 1hr and 45min levels along with 15 min levels all on one chart so i don't have to mark every single levels in each time frame rather i would see them all on 15 min chart.
 

Learnbot

Active member
@Learnbot Just load the script 3 times and change the agg.

So I added the studies two times and in one I kept the agg to fifteen min and the other I changed to 1 hour, 15 mins plotted on 15 min chart however, 1 hour did not. then I tried changing to code to following but still same issue, only 15 min plots on 15 min chart not 15 min and 1 hour not sure why.
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 hour = AggregationPeriod.hour;
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);





def bu_high1 = if bullish and hour then high[1] else bu_high1[1];
def bu_low1 = if bullish and hour then close[1] else bu_low1[1];
def be_high1 = if bearish and hour then high[1] else be_high1[1];
def be_low1 = if bearish and hour then open[1] else be_low1[1];

def buhh1 = if IsNaN(close) then buhh1[1] else bu_high1;
def bull1 = if IsNaN(close) then bull1[1] else bu_low1;
def behh1 = if IsNaN(close) then behh1[1] else be_high1;
def bell1 = if IsNaN(close) then bell1[1] else be_low1;

plot bu_hh1 = buhh1;
plot bu_ll1 = bull1;
plot be_hh1 = behh1;
plot be_ll1 = bell1;

bu_hh1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bu_ll1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
bu_hh1.SetDefaultColor(Color.red);
bu_ll1.SetDefaultColor(Color.red);
be_hh1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
be_ll1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
be_hh1.SetDefaultColor(Color.red);
be_ll1.SetDefaultColor(Color.red);
 

generic

Active member
@Learnbot Load this twice for 15 and 1 hr. Can't do 45 min since its TOS doesn't have it. If you really want 45 then you have to custom code it but its too much work.
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 agg = AggregationPeriod.FIFTEEN_MIN;

def open = open(period = agg);
def high = high(period = agg);
def low = low(period = agg);
def close = close(period = agg);

def nan = Double.NaN;
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];

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);
 

Learnbot

Active member
Hello,
I was wondering if someone here can help me figure out a way to draw a box around a specific pattern I am interested in (this makes it easy for me to spot the pattern while I am looking at multiple chart at the same time). I used TOS's pattern section to obtain the below code for the pattern but I cant figure out how to draw a box around it.

Code:
# Generation time: 2021-03-30T17:26:20.467Z

def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
plot PatternPlot =
    IsDown[4] and
    IsDown[3] and
    IsDown[2] and

I did try figuring this out by using script posted by @BenTen here but alas no luck:

https://usethinkscript.com/threads/...kout-breakdown-indicator-for-thinkorswim.103/

thank you for any help and appreciate your time.
 

Learnbot

Active member
@Learnbot Apply what you learned from this thread and use AddCloud function to connect the two lines.
You are a genius! I didnt even think abt this way of solving the problem! THANK YOU! so my problem is mostly solved but I wanted to make it a little bit cleaner if possible. Here is the script I came up with:
Code:
# Generation time: 2021-03-30T17:26:20.467Z
input hidecloud = no;
def IsUp = close > open;
def IsDown = close < open;
def IsDoji = IsDoji();
def avgRange = 0.05 * Average(high - low, 20);
def PatternPlot =
    IsDown[4] and
    IsDown[3] and
    IsDown[2] and
    IsUp[1] and
    IsUp[0] and
    open[4] > open[3] and
    close[1] < close[0] and
    close[4] > close[3] and
    close[3] > close[2] and
    open[3] > open[2];

def b_h = if PatternPlot then open[1] else b_h[1];
def B_l = if PatternPlot then close[1] else b_l[1];

plot hh = b_H;
plot ll = b_l;
hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hh.SetDefaultColor(Color.YELLOW);
ll.SetDefaultColor(Color.YELLOW);


addcloud(if !HideCloud then hh else double.nan, ll, color.gray, color.gray);



so everything is working fine however the only issue I have is this: how can I limit this could? As you can see in the image below the clods keeps extending. The red rectangle(ish) is where the condition is met and the cloud highs and lows are set correctly the only issue is the length, I was wondering if there is a way to limit the cloud to just the red rectangle(ish) like in your consolidation script.

again your idea worked like a charm I just want to clean it up a little to declutter my chart (if possible). THANK YOU!!!

Screen-Shot-2021-03-30-at-2-53-12-PM.png
 

Learnbot

Active member
@Learnbot would you mind sharing your final code? This looks interesting.

Thanks
Here you go:

This is general code, meaning whatever time frame you are on this code with plot for that specific time fram.
Code:
#Englufing Supply and Demand:

# 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(2));
Bearish.SetLineWeight(2);
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Bullish.SetDefaultColor(GetColor(1));
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.cyan);
bu_ll.SetDefaultColor(Color.cyan);
be_hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
be_ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
be_hh.SetDefaultColor(Color.pink);
be_ll.SetDefaultColor(Color.pink);

AddCloud(bu_hh, bu_ll, Color.cyan, Color.cyan);
AddCloud(be_hh,Be_ll, Color.pink, Color.PINK);
 

Learnbot

Active member
@Learnbot would you mind sharing your final code? This looks interesting.

Thanks
Here is code for 1 Hr time frame
Code:
#Engulfing Sup/Dem 1Hr
#
# 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 agg = AggregationPeriod.hour;

def open = open(period = agg);
def high = high(period = agg);
def low = low(period = agg);
def close = close(period = agg);

def nan = Double.NaN;
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];

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.red);
bu_ll.SetDefaultColor(Color.red);
be_hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
be_ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
be_hh.SetDefaultColor(Color.red);
be_ll.SetDefaultColor(Color.red);



Here is code for 15 min time frame:

Code:
#Engulfing Sup/Dem 15 min
#
# 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 agg = aggregationPeriod.FIFTEEN_MIN;

def open = open(period = agg);
def high = high(period = agg);
def low = low(period = agg);
def close = close(period = agg);

def nan = Double.NaN;
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];

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.cyan);
bu_ll.SetDefaultColor(Color.cyan);
be_hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
be_ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
be_hh.SetDefaultColor(Color.pink);
be_ll.SetDefaultColor(Color.pink);


AddCloud(bu_hh, bu_ll, Color.cyan, Color.cyan);
AddCloud(be_hh,Be_ll, Color.pink, Color.PINK);


I am learning daytrading, so what I do is i use the 1 HR and 15 min script along with the original script i posted in #39 on 5 min chart. This way i can see supply and demand zones for three different time frames on one chart (5min, 15min and 1 hour). Hope this helps.
 

Similar threads

Top