• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

OHLC (open-high-low-close) Indicator for ThinkorSwim

bizzns

New member
Is there a way to have Daily OHLC lines plot on a short time frame chart that I use for a trigger? For instance, If I go and plot out my daily OHLC lines then I can see them on my short term (trigger chart). However, when I jump to a different ticker I have to re-evaluate and spend time plotting which takes away valuable time during trading. Any suggestions on how this can be done.

Much appreciated in advance.
 
Solution
Hi @iambkm01

It looks like there is an additional parameter that affects the display of the OHLC lines...I had to rework the code a little bit to accommodate this...

Below is the new code to replace the old OHLC code...
Code:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
#input displace = -1;
input displace_amount = {default zero, negative_one};

def displacement;
switch (displace_amount) {
case zero:
    displacement = 0;
case negative_one:
    displacement = -1;
}

input showOnlyLastPeriod = yes;

plot PrevDayOpen;
plot PrevDayHigh;
plot PrevDayLow;
plot PrevDayClose;

if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriod)[-1]) and !IsNaN(high(period = aggregationPeriod)[-1]) and...

bizzns

New member
I can't even find a study that plots OHLC on my charts to begin with... I wish I knew something about coding... unfortunately, I'm completely inept on the subject.
 

bizzns

New member
Well basically I’d like to have past few days (ie 10 days) plotted on my short term chart. I actually use a 200 tick chart for my trigger chart. Also use 1min and 2 min... they seem to correlate fairly close.

This is for a quick in/out scalping sort of trades.
 
Last edited:

inthefutures

Active member
Code:
#April 11th 2020
#last 10 days OHLC
#Inthefutures


def agg = AggregationPeriod.DAY;

plot open = open(period = agg)[1];
plot high = high(period = agg)[1];
plot low = low(period = agg)[1];
plot close = close(period = agg)[1];

plot open2 = open(period = agg)[2];
plot high2 = high(period = agg)[2];
plot low2 = low(period = agg)[2];
plot close2 = close(period = agg)[2];

plot open3 = open(period = agg)[3];
plot high3 = high(period = agg)[3];
plot low3 = low(period = agg)[3];
plot close3 = close(period = agg)[3];

plot open4 = open(period = agg)[4];
plot high4 = high(period = agg)[4];
plot low4 = low(period = agg)[4];
plot close4 = close(period = agg)[4];

plot open5 = open(period = agg)[5];
plot high5 = high(period = agg)[5];
plot low5 = low(period = agg)[5];
plot close5 = close(period = agg)[5];

plot open6 = open(period = agg)[6];
plot high6 = high(period = agg)[6];
plot low6 = low(period = agg)[6];
plot close6 = close(period = agg)[6];

plot open7 = open(period = agg)[7];
plot high77 = high(period = agg)[7];
plot low7 = low(period = agg)[7];
plot close7 = close(period = agg)[7];

plot open8 = open(period = agg)[8];
plot high8 = high(period = agg)[8];
plot low8 = low(period = agg)[8];
plot close8 = close(period = agg)[8];

plot open9 = open(period = agg)[9];
plot high9 = high(period = agg)[9];
plot low9 = low(period = agg)[9];
plot close9 = close(period = agg)[9];

plot open10 = open(period = agg)[10];
plot high10 = high(period = agg)[10];
plot low10 = low(period = agg)[10];
plot close10 = close(period = agg)[10];
 

bizzns

New member
Appreciate you putting your time in for this. However, its not plotting. The name of the indicator is highlighted red after I add it to my studies. Not sure if that means its missing something?
 

bizzns

New member
yes! I appreciate this so much. It'll save me loads of time. thank you so much.

Hey buddy. You wouldn't be familiar with Tradestation code system by chance would you? TOS has been very unreliable lately so i have an alternative but this code helps so much...
 

MrDrB

New member
Looking for thinkscript code that can return/plot the OHLC for a user-configurable group of days on an hourly chart (the period) for a user-configurable max number of days (the lookback).

Example: assume the user sets lookback equal to 12; this means that only today plus the 11 prior days are to be considered in the output. Assume the user sets the period to 3; this means that all days in the lookback period should be broken into groups of 3 days, starting the count at the oldest/first day. Each period will have plots of the OHLC from the prior period. See this example:

IwO3S0s.png


Higher time-frame aggregations cannot be used as the script will be used in hourly scans and other time frames are not allowed in TOS. Willing to pay via paypal. Thanks!
 

iambkm01

New member
Hello,

I am looking for an indicator to plot lines of the prior day OHLC on the 5 minute chart. I found a few of them here, however, they show different values for futures and stocks and I have to manually change the "Prior Days Ago" from 1 > 2 to work on futures, and 1 for stocks. Is there any other way to do this to have 1 study working for all instruments?
 

Investingtogive

New member
VIP
Try this code. It has been working for me. It does HLC of the previous day and seems to work on all instruments.

Code:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = yes;
plot PrevDayHigh;
plot PrevDayLow;
plot PrevDayClose;

if showOnlyLastPeriod and !IsNaN(high(period = aggregationPeriod)[-1]) and !IsNaN(low(period = aggregationPeriod)[-1]) and !IsNaN(close(period = aggregationPeriod)[-1])
{
    PrevDayHigh = Double.NaN;
    PrevDayLow = Double.NaN;
    PrevDayClose = Double.NaN;
}
else
{
    PrevDayHigh = Highest(high(period = aggregationPeriod)[-displace], length);
    PrevDayLow = Highest(low(period = aggregationPeriod)[-displace], length);
    PrevDayClose = Highest(close(period = aggregationPeriod)[-displace], length);
}
PrevDayHigh.SetDefaultColor(CreateColor(0,255,255));
PrevDayHigh.SetPaintingStrategy(PaintingStrategy.LINE);

PrevDayLow.SetDefaultColor(CreateColor(0,255,255));
PrevDayLow.SetPaintingStrategy(PaintingStrategy.LINE);

PrevDayClose.SetDefaultColor(CreateColor(116,189,239));
PrevDayClose.SetPaintingStrategy(PaintingStrategy.LINE);
PrevDayClose.SetStyle(Curve.LONG_DASH);
 

netarchitech

Well-known member
VIP
@iambkm01 As requested, the Open should be added as well:

Code:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = yes;

plot PrevDayOpen;
plot PrevDayHigh;
plot PrevDayLow;
plot PrevDayClose;

if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriod)[-1]) and !IsNaN(high(period = aggregationPeriod)[-1]) and !IsNaN(low(period = aggregationPeriod)[-1]) and !IsNaN(close(period = aggregationPeriod)[-1])
{
    PrevDayOpen = Double.NaN;
    PrevDayHigh = Double.NaN;
    PrevDayLow = Double.NaN;
    PrevDayClose = Double.NaN;
}
else
{
    PrevDayOpen = Highest(open(period = aggregationPeriod)[-displace], length);
    PrevDayHigh = Highest(high(period = aggregationPeriod)[-displace], length);
    PrevDayLow = Highest(low(period = aggregationPeriod)[-displace], length);
    PrevDayClose = Highest(close(period = aggregationPeriod)[-displace], length);
}
PrevDayOpen.SetDefaultColor(CreateColor(116,189,239));
PrevDayOpen.SetPaintingStrategy(PaintingStrategy.LINE);
PrevDayOpen.SetStyle(Curve.LONG_DASH);

PrevDayHigh.SetDefaultColor(CreateColor(0,255,255));
PrevDayHigh.SetPaintingStrategy(PaintingStrategy.LINE);

PrevDayLow.SetDefaultColor(CreateColor(0,255,255));
PrevDayLow.SetPaintingStrategy(PaintingStrategy.LINE);

PrevDayClose.SetDefaultColor(CreateColor(116,189,239));
PrevDayClose.SetPaintingStrategy(PaintingStrategy.LINE);
PrevDayClose.SetStyle(Curve.LONG_DASH);

Hope this helps...

Good Luck and Good Trading :)
 

iambkm01

New member
@netarchitech This is amazing, exactly what I needed. May the trading gods send profits down your way man. THANKS!!!!

Hi Man, quick question...sorry for the follow up. Futures are displaying fine but for stocks, it is keeping yesterdays lines and todays in the graphics:

G4AioOy.png
 

netarchitech

Well-known member
VIP
Hi @iambkm01

It looks like there is an additional parameter that affects the display of the OHLC lines...I had to rework the code a little bit to accommodate this...

Below is the new code to replace the old OHLC code...
Code:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
#input displace = -1;
input displace_amount = {default zero, negative_one};

def displacement;
switch (displace_amount) {
case zero:
    displacement = 0;
case negative_one:
    displacement = -1;
}

input showOnlyLastPeriod = yes;

plot PrevDayOpen;
plot PrevDayHigh;
plot PrevDayLow;
plot PrevDayClose;

if showOnlyLastPeriod and !IsNaN(open(period = aggregationPeriod)[-1]) and !IsNaN(high(period = aggregationPeriod)[-1]) and !IsNaN(low(period = aggregationPeriod)[-1]) and !IsNaN(close(period = aggregationPeriod)[-1])
{
    PrevDayOpen = Double.NaN;
    PrevDayHigh = Double.NaN;
    PrevDayLow = Double.NaN;
    PrevDayClose = Double.NaN;
}
else
{
    PrevDayOpen = Highest(open(period = aggregationPeriod)[displace_amount], length);
    PrevDayHigh = Highest(high(period = aggregationPeriod)[displace_amount], length);
    PrevDayLow = Highest(low(period = aggregationPeriod)[displace_amount], length);
    PrevDayClose = Highest(close(period = aggregationPeriod)[displace_amount], length);
}
PrevDayOpen.SetDefaultColor(CreateColor(116, 189, 239));
PrevDayOpen.SetPaintingStrategy(PaintingStrategy.LINE);
PrevDayOpen.SetStyle(Curve.LONG_DASH);

PrevDayHigh.SetDefaultColor(CreateColor(0, 255, 255));
PrevDayHigh.SetPaintingStrategy(PaintingStrategy.LINE);

PrevDayLow.SetDefaultColor(CreateColor(0, 255, 255));
PrevDayLow.SetPaintingStrategy(PaintingStrategy.LINE);

PrevDayClose.SetDefaultColor(CreateColor(116, 189, 239));
PrevDayClose.SetPaintingStrategy(PaintingStrategy.LINE);
PrevDayClose.SetStyle(Curve.LONG_DASH);

Once the old code is replaced, just follow the steps below to resolve this issue...

1.png


2.png


3.png


4.png


5.png



The chart below shows the extra lines you wanted removed...Just in case, I retained the lines, but you don't have to view them if you don't want to...Just keep the "displace amount" set to "zero"...

c.png


To view just the current lines shown below, just make sure to keep the "displace amount" set to "zero"...

b.png


Hope this helps...

Good Luck and Good Trading :)
 
Solution

Similar threads

Top