Welcome! Log In Create A New Profile

Get Earnings and Seasonal Trends - Subscribe Today!

Advanced

Fun with ThinkScript

Posted by robert 
Re: MA & Stochastic Signals?
November 30, 2017 01:53AM
Hi Jdubpwr,
yes that's correct: I don't care if above or below the HMA. The direction or color of HMA is more important. So if HMA is green and pointing up and Stoch oversold + cross of K/D then signal = ARROW UP.

The HMA settings can be 20 but ideally this can be modified in study settings if possible? I need to test it and may use higher settings.

Stoch Settings are fine with your 5,3,3 as long as they can be modified either in study setting or the script. Maybe I might use higher settings sometimes.

I need this for 1 minute and 5 minute charts mostly.

Thanks again and looking forward to your code if you can post it here when done! Thanks so much



Edited 2 time(s). Last edit at 11/30/2017 01:58AM by MX01.
Re: MA & Stochastic Signals?
November 30, 2017 01:57AM
No problem. Yes, all the settings can be changed. Your request was about as easy as joining to default indicators so glad to help, though I normally cannot. I post something for you in 20min.
Re: MA & Stochastic Signals?
November 30, 2017 02:01AM
Awesome!

By the way one small other question. How can I get sound alerts of signals that appear on a chart when a signal is lagging 1-2 candles?

Usually ThinkScript has this line "Alert.BAR" but the sound alerts don't happen when the signal lags 1-2 candles.

What would I need to replace "BAR" with?
Re: MA & Stochastic Signals?
November 30, 2017 02:12AM
normally you script it

alert(Crup[1], "Arrow Up", Alert.Bar, Sound.Ding); The Crup[1] is one bar back having close so that you don't get constant dings as the candle is forming, however, based on your question I have scripted yours to occur when while its forming and you can always change it to delay. You will see I coded it alert(Crup, "Arrow Up", Alert.Bar, Sound.Ding);
Re: MA & Stochastic Signals?
November 30, 2017 02:16AM
I am not the best scripter, but I am the best in this thread tonight. I don't have site permission to upload an image but it plots what you requested.

declare upper;

input over_bought = 80;
input over_sold = 20;
input KPeriod = 5;
input DPeriod = 3;
input slowing_period = 3;
input smoothingType = AverageType.SIMPLE;
input priceH = high;
input priceL = low;
input priceC = close;

input HA = 20;
input displace = 0;
plot HMA = MovingAverage(AverageType.HULL, priceC, HA)[-displace];
HMA.assignvalueColor(if HMA>HMA[1] then color.green else color.red);
HMA.setLineWeight(2);

def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def FullK = MovingAverage(smoothingType, FastK, slowing_period);
def FullD = MovingAverage(smoothingType, FullK, DPeriod);

def ASMA = HMA>HMA[1];
def LSMA = HMA<HMA[1];

plot Crup = if ASMA and FullD < over_sold and FullK crosses above FullD then low - 3*tickSize() else Double.NaN;
Crup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Crup.SetDefaultColor(Color.cyan);
Crup.setLineWeight(2);

plot Crdn  = if LSMA and FullD > over_bought and FullK crosses below FullD then high + 3*tickSize() else Double.NaN;
Crdn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Crdn.SetDefaultColor(Color.cyan);
Crdn.setLineWeight(2);

alert(Crup, "Arrow Up", Alert.Bar, Sound.Ding);
alert( Crdn, "Arrow Down", Alert.Bar, Sound.Ding);

Re: MA & Stochastic Signals?
November 30, 2017 02:27AM
Awesome, thanks!

I must apologize. I noticed my variables were a bit flawed when I described it. I just now noticed it.

The input HMA should be: 250. I changed that in your script.

And the Stoch arrow should not appear when there's a stoch K/D cross but when the stoch goes oversold 20 and the HMA is up/ green. Below is a screenshot how I imagine it should work and where the signal should appear.

Vice versa when trend is down with HMA red and Stoch overbought at +80





Edited 1 time(s). Last edit at 11/30/2017 02:31AM by MX01.
Re: MA & Stochastic Signals?
November 30, 2017 02:34AM
Sounds good, glad it works and that you were able to make the corrections. Have a great morning. thumbs up
Re: MA & Stochastic Signals?
November 30, 2017 02:37AM
I was only able to change the HMA settings but the arrows/ signals don't appear as desired.

As per screenshot, the HMA input should be 250 and the arrows only appear when stoch is oversold (20) while HMA up/ green. And arrow down/ signal when stoch overbought (80) and HMA red.

Sorry for the confusion, hope you could adjust the code?


Jdubpwr Wrote:
-------------------------------------------------------
> Sounds good, glad it works and that you were able
> to make the corrections. Have a great morning.
> thumbs up
Re: MA & Stochastic Signals?
November 30, 2017 02:54AM
When you say
"the arrows should only appear when stoch is oversold (20) while HMA up/ green. And arrow down/ signal when stoch overbought (80) and HMA red"

Do you mean K, D, or K&D is oversold/overbought?


When you say
"when the stoch goes oversold 20 ... ."

Do you mean Stoch crosses below 20 (still going down), less than 20 (fire an arrow anytime it is less than 20), or crosses above 20 (meaning price has been oversold and is turning up)?
Re: MA & Stochastic Signals?
November 30, 2017 03:02AM
Yes I guess K&D and arrow alert only when they turn up from 20 while HMA is green/ up.

vice versa when HMA red and K&D come down from 80.

Thanks much.
Re: MA & Stochastic Signals?
November 30, 2017 03:08AM
No problem. I set the HMA to 250, and changed the Stoch crosses. It will only plot a down arrow when HMA is red, and up arrow when HMA is green. Please consider, however, that multiple candles can close in the opposite direction of the HMA color before it changes which may give the appearance arrow are forming where they should not. The code relies on the HMA color, not the candle close above/below the HMA which is why I originally asked.

declare upper;

input over_bought = 80;
input over_sold = 20;
input KPeriod = 5;
input DPeriod = 3;
input slowing_period = 3;
input smoothingType = AverageType.SIMPLE;
input priceH = high;
input priceL = low;
input priceC = close;

input HA = 250;
input displace = 0;
plot HMA = MovingAverage(AverageType.HULL, priceC, HA)[-displace];
HMA.assignvalueColor(if HMA>HMA[1] then color.green else color.red);
HMA.setLineWeight(2);

def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC - lowest_k;
def c2 = Highest(priceH, KPeriod) - lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def FullK = MovingAverage(smoothingType, FastK, slowing_period);
def FullD = MovingAverage(smoothingType, FullK, DPeriod);

def ASMA = HMA>HMA[1];
def LSMA = HMA<HMA[1];

plot Crup = if ASMA and FullD crosses above over_sold then low - 3*tickSize() else Double.NaN;
Crup.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Crup.SetDefaultColor(Color.cyan);
Crup.setLineWeight(2);

plot Crdn  = if LSMA and FullD crosses below over_bought then high + 3*tickSize() else Double.NaN;
Crdn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Crdn.SetDefaultColor(Color.cyan);
Crdn.setLineWeight(2);

alert(Crup, "Arrow Up", Alert.Bar, Sound.Ding);
alert( Crdn, "Arrow Down", Alert.Bar, Sound.Ding);
Re: MA & Stochastic Signals?
November 30, 2017 03:13AM
Great, thanks so much again!

I will have to play with settings and see how to avoid some bad signals.

Cheers!
Re: MA & Stochastic Signals?
November 30, 2017 03:22AM
The longer the period of the HMA (and depending on what Stoch settings you use) the more prone it will be giving down arrows when price is above the HMA even if HMA is red, for example. If you want to avoid those signals (assuming those are the bad signals to which you refer) then look towards the bottom and change the following lines of script.


#plot Crup = if ASMA and FullD crosses above over_sold then low - 3*tickSize() else Double.NaN;
plot Crup = if ASMA and close>HMA and FullD crosses above over_sold then low - 3*tickSize() else Double.NaN;


#plot Crdn  = if LSMA and FullD crosses below over_bought then high + 3*tickSize() else Double.NaN;
plot Crdn  = if LSMA and close<HMA and FullD crosses below over_bought then high + 3*tickSize() else Double.NaN;


Re: MA & Stochastic Signals?
November 30, 2017 03:41AM
Hmm but with this code adjustments there are no more arrows appearing at all? At least here.

Can you check?
Re: MA & Stochastic Signals?
November 30, 2017 03:58AM
I checked it and it is correct. The filter is the draw back of a mechanical filter vs. your discretion. You could insert something like a stochastic cross and the candle close above/below the HMA within N bars these are about the only choices. Here is am image with some notes of me checking it on crude futures a few minutes ago.

Visit Image



Edited 2 time(s). Last edit at 11/30/2017 04:00AM by Jdubpwr.
Re: MA & Stochastic Signals?
November 30, 2017 04:03AM
Hmm not sure if this is better. I think I'll keep your previous code and mess with settings smiling smiley
Re: MA & Stochastic Signals?
November 30, 2017 04:04AM
I understand. No problem and I wish you well. I'll be stepping away from the computer for the morning, but have a great day and it was nice chatting with you.

thumbs up
Re: Fun with ThinkScript
December 01, 2017 01:41AM
Hey there. Something else and question to anybody:

Is somebody able to create a script to detect 'Bullish Engulfing' after price hit oversold levels either RSI or Stoch (20) and vice versa "Bearish Engulfing" after overbought (RSI/ Stoch 80)? And it would color the candles detected CYAN for bullish and PINK for bearish.

This should be working for 1 minute and 5 minute charts too.

I tried the TOS included patterns but they dont seem to work. Or at least not on 1 and 5 min charts.

Thanks



Edited 1 time(s). Last edit at 12/01/2017 01:50AM by MX01.
Re: Fun with ThinkScript
December 05, 2017 05:56AM
Never mind, somebody on twitter did it for me. Here's a little gift to you all if you want to play with it. winking smiley



# Bullish/ Bearish Engulfing Alerts (Oversold/ Overbought)

# Use with caution and in context of market.
# Make sure to adjust settings that fits you best.

# By Confluence Capital Group @ConfluenceCptl - 2017-12-04
# Addendum & thanks from @M0101X

input length = 14;
input over_Bought = 75;
input over_Sold = 25;
input price = close;
input averageType = AverageType.WEIGHTED;

#defining engulfing bars
def BodyMax = Max(open, close);
def BodyMin = Min(open, close);
def IsEngulfing = BodyMax > BodyMax[1] and
BodyMin < BodyMin[1];

#defining the bullish / bearish signals

def bullish_signal = RSI(length = length, averageType = averageType) < over_Sold and Isengulfing and close > open;

def bearish_signal = RSI(length = length, averageType = averageType) > over_Bought and Isengulfing and close < open;

#plotting the bullish / bearish signals
plot bullish = bullish_signal;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

plot bearish = bearish_signal;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);


alert(bullish_signal, "BULLISH ENGULFING", alert.bar, sound.Ring);
alert(bearish_signal, "BEARISH ENGULFING", alert.bar, sound.Ring);
Dan
Counting Number of Bars Between Two Dates That Meet Condition
December 05, 2017 11:14AM
My first request for Thinkscript help, I believe. I'm looking to find the total number of bars that meet a specified condition and put that total in a result field. My preference is to use two specific dates, but I suppose the total over a number of bars such as the last X bars would be just as good. The ultimate goal is to put the total number in a result field that I can place in a scan results column. This will allow me to output the scan results to a text file and get them into a spreadsheet for further analysis. Thanks in advance for any help the group can provide.
Re: Fun with ThinkScript
December 11, 2017 02:39PM
Hey everyone I came across this forum after doing some of my own scripts(very basic)

I'm trying to add an RSI label on my charts in any timeframe and I seem to have done it but I'm trying to figure out how to round the number to 2 decimal places. any thoughts? this is what I currently have:


def rsi = reference RSI("over bought" = 85, "over sold" = 15, price = close());

AddLabel(yes, rsi, if rsi >= 85 then Color.RED else if rsi <= 15 then color.GREEN else color.GRAY);
Re: Fun with ThinkScript
December 11, 2017 04:03PM
hello hit626387,

This is how I would do it, but there is probably a cleaner way. Hope it helps you.

AddLabel(yes, Concat("Rsi = ", Round(RSI, 2)), if rsi >= 85 then Color.RED else if rsi <= 15 then color.GREEN else color.GRAY);
Re: Fun with ThinkScript
December 18, 2017 06:41AM
looking to show a marker for Globex current price on a RTH chart.
I mean in a chart that does not show extended hours, I want to see where the current globex price level is, just before the open.
basicly the marker will move dynamically with the globex price. As soon as the normal trading starts the indicator will stop showing the marker, as obviously the price is the real time price of the chart.
I have some indicators that can only be active on a RTH chart and I cant show them with extended hours setting on.

I saw some script from tanman, but it shows the high and low. the current price is not working .

thanks guys
Re: Fun with ThinkScript
December 24, 2017 04:00PM
I've been trying to reconfigure Roberts 30min ORB to be a 15min ORB. I can't get the formatting right and don't seem to see anyone else ask throughout the thread. Can someone help me I would be forever grateful.


robert Wrote:
-------------------------------------------------------
I rewrote the code from scratch. Now if you extend the timeline to the right, the plotted lines will be drawn to the end of the day. Additionally, unlike the script above which requires the time period to be an even divisor of 30, this script will accept any time period up to 30 minutes---want to use a 5 min chart, ok; 8 min, you betcha; 17 min, why not.



# 30 min opening range with fib retracements
input ShowTodayOnly = yes;
input ShowFib1 = yes;
input ShowFib2 = yes;
input Fib1 = 1.382;
input Fib2 = 1.621;

def today = !ShowTodayOnly or GetDay() == GetLastDay();
def nMinutes = GetAggregationPeriod() / 60000;
def first30min = SecondsFromTime(0930) >= 0 and SecondsTillTime(1000) > 0;
def bar10am = SecondsFromTime(1000) >= 0 and SecondsFromTime(1000) < nMinutes * 60;

def OR30high = if first30min then Double.NaN else if bar10am then high(period = "30 min" )[1] else OR30high[1];
def OR30low = if first30min then Double.NaN else if bar10am then low(period = "30 min" )[1] else OR30low[1];
def OR30rng = OR30high - OR30low;

plot h30 = if !today then Double.NaN else OR30high;
h30.SetLineWeight(2);
h30.SetDefaultColor(Color.GREEN);
plot l30 = if !today then Double.NaN else OR30low;
l30.SetLineWeight(2);
l30.SetDefaultColor(Color.PINK);
plot mid = if !today then Double.NaN else (h30 + l30) / 2;
mid.SetDefaultColor(Color.LIGHT_GRAY);
plot fib1up = if !ShowFib1 then Double.NaN else l30 + OR30rng * Fib1;
fib1up.SetStyle(Curve.LONG_DASH);
fib1up.SetDefaultColor(Color.GREEN);
plot fib2up = if !ShowFib2 then Double.NaN else l30 + OR30rng * Fib2;
fib2up.SetStyle(Curve.SHORT_DASH);
fib2up.SetDefaultColor(Color.GREEN);
plot fib1dn = if !ShowFib1 then Double.NaN else h30 - OR30rng * Fib1;
fib1dn.SetStyle(Curve.LONG_DASH);
fib1dn.SetDefaultColor(Color.PINK);
plot fib2dn = if !ShowFib2 then Double.NaN else h30 - OR30rng * Fib2;
fib2dn.SetStyle(Curve.SHORT_DASH);
fib2dn.SetDefaultColor(Color.PINK);

# Delete the following line if you don't want the opening range filled with color
AddCloud(h30, l30, CreateColor(192, 192, 208));
Re: Fun with ThinkScript
December 26, 2017 04:48PM
Hi All,

I've trying to incorporate Volume into my setup. As a result, I came across the following indicator.
input period = AggregationPeriod.HOUR;

def O = open(period = period);
def H = high(period = period);
def C = close(period = period);
def L = low(period = period);
def V = volume(period = period);

def O1 = open(period = period);
def H1 = high(period = period);
def C1 = close(period = period);
def L1 = low(period = period);
def V1 = volume(period = period);

def SV = -V * (H - C) / (H - L);
def BV = V1 * (C1 - L1) / (H1 - L1);


AddLabel(yes, "Buy ", if BV > SV then Color.GREEN else color.GRAY);

AddLabel(yes, "Sell", if SV > BV then Color.RED else color.GRAY);

I've been playing around with it on various charts, however, no matter what chart/time frame I select, the indicator shows a green signal for buying pressure and a gray signal for selling pressure...

Any thoughts/ideas? Thanks in advance smiling smiley
Re: Fun with ThinkScript
December 28, 2017 02:26AM
does anyone know how I could modify this script to include PM and AH. or start at a user specified time?

# Box Volume Stats
# Version 1.0
# Created by: Enigma
# Created: 05/18/17

declare lower;

#Inputs
input Show30DayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOf30DayAvg = yes;
input UnusualVolumePercent = 200;
input Show30BarAvg = yes;
input ShowCurrentBar = yes;


#Volume Data
def volLast30DayAvg = (volume(period = "DAY"winking smiley[1] + volume(period = "DAY"winking smiley[2] + volume(period = "DAY"winking smiley[3] + volume(period = "DAY"winking smiley[4] + volume(period = "DAY"winking smiley[5] + volume(period = "DAY"winking smiley[6] + volume(period = "DAY"winking smiley[7] + volume(period = "DAY"winking smiley[8] + volume(period = "DAY"winking smiley[9] + volume(period = "DAY"winking smiley[10] + volume(period = "DAY"winking smiley[11] + volume(period = "DAY"winking smiley[12] + volume(period = "DAY"winking smiley[13] + volume(period = "DAY"winking smiley[14] + volume(period = "DAY"winking smiley[15] + volume(period = "DAY"winking smiley[16] + volume(period = "DAY"winking smiley[17] + volume(period = "DAY"winking smiley[18] + volume(period = "DAY"winking smiley[19] + volume(period = "DAY"winking smiley[20] + volume(period = "DAY"winking smiley[21] + volume(period = "DAY"winking smiley[22] + volume(period = "DAY"winking smiley[23] + volume(period = "DAY"winking smiley[24] + volume(period = "DAY"winking smiley[25] + volume(period = "DAY"winking smiley[26] + volume(period = "DAY"winking smiley[27] + volume(period = "DAY"winking smiley[28] + volume(period = "DAY"winking smiley[29] + volume(period = "DAY"winking smiley[30]) / 30;
def today = volume(period = "DAY"winking smiley;
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
#def avg30Bars = VolumeAvg(30).VolAvg;
def avg30Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10] + volume[11] + volume[12] + volume[13] + volume[14] + volume[15] + volume[16] + volume[17] + volume[18] + volume[19] + volume[20] + volume[21] + volume[22] + volume[23] + volume[24] + volume[25] + volume[26] + volume[27] + volume[28] + volume[29] + volume[30]) / 30;
def curVolume = volume;


# Labels
AddLabel(Show30DayAvg, "Daily Avg: " + Round(volLast30DayAvg, 0), Color.LIGHT_GRAY);
AddLabel(ShowTodayVolume, "Today: " + today, (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.LIGHT_GRAY));
AddLabel(ShowPercentOf30DayAvg, percentOf30Day + "%", (if percentOf30Day >= UnusualVolumePercent then Color.GREEN else if percentOf30Day >= 100 then Color.ORANGE else Color.WHITE) );
AddLabel(Show30BarAvg, "Avg 30 Bars: " + Round(avg30Bars, 0), Color.LIGHT_GRAY);
AddLabel(ShowCurrentBar, "Cur Bar: " + curVolume, (if curVolume >= avg30Bars then Color.GREEN else Color.ORANGE));
ThinkScript: Recording Values in the First Few Bars on 5min Chart
December 30, 2017 12:29PM
I am trying to build a scanner that pulls stocks that open the day with 2 or 3 green bars each successively making new highs. I have the following code, but it does not work. I know its a little crude, so new thoughts are welcome (as opposed to just debugging this code):

def na = double.nan;

input ORBegin1 = 0930;
input OREnd1 = 0935;

input ORBegin2 = 0935;
input OREnd2 = 0940;

input ShowTodayOnly = {"No", default "Yes"};

def s1 = ShowTodayOnly;

# First bar calculations

def ORActive1 = if secondsTillTime(OREnd1)>0 and secondsFromTime(ORBegin1)>=0 then 1 else 0;
def today1 = if s1 == 0 or getday() == getlastday() and secondsfromtime(ORBegin1) >= 1 then 1 else 0;

rec ORHigh1 = if ORHigh1[1] == 0 or ORActive1[1] == 0 AND ORActive1==1 then high else if ORActive1 AND high > ORHigh1[1] then high else ORHigh1[1];
rec ORLow1 = if ORLow1[1] ==0 or ORActive1[1] == 0 AND ORActive1 == 1 then low else if ORActive1 AND low < ORlow1[1] then low else ORLow1[1];

rec begin1_close = if(secondsTillTime(OREnd1) == 0, close, 0);

def green1 = if begin1_close > open then 1 else 0;

# Second bar calculations

def s2 = ShowTodayOnly;

def ORActive2 = if secondsTillTime(OREnd2)>0 and secondsFromTime(ORBegin2) >=0 then 1 else 0;
def today2 = if s2 == 0 or getday() == getlastday() and secondsfromtime(ORBegin2) >= 1 then 1 else 0;

rec ORHigh2 = if ORHigh2[1]==0 or ORActive2[1]==0 AND ORActive2==1 then high else if ORActive2 AND high > ORHigh2[1] then high else ORHigh2[1];

rec ORLow2 = if ORLow2[1] ==0 or ORActive2[1]==0 AND ORActive2 == 1 then low else if ORActive2 AND low < ORlow2[1] then low else ORLow2[1];

rec begin2_close = if(secondsTillTime(OREnd2) == 0, close, 0);

def green2 = if begin2_close > open then 1 else 0;

plot f = green1 == 1 AND green2 == 1 AND ORHigh2 > ORHigh1;



Edited 1 time(s). Last edit at 12/30/2017 12:55PM by adam66639.
Going Backwards across chart data in TOS
January 03, 2018 12:18PM
Hi all I have a question about going backwards through chart data. The below line plots a line across the progressively higher highs over the chart data.

rec highs = if isnan(high[1]) then double.nan else if high > highs[1] then high else highs[1];

What I'm trying to do is start at the most recent point and go backwards identifying higher highs as you go back in time. I treid the below but doesnt seem to work

rec highs = if isnan(high[-1]) then high else if high < highs[-1] then highs[-1] else high;

Any suggestions are appreciated!

Thanks.
jt
Counting no. of bars
January 11, 2018 04:02PM
Hi - I'm looking for a way get a count of no. of bars after the low of day bar that closed higher than previous bar. All on a five minute chart.

Below is the rough study I have so far.

I can get the low of day barnumber by the code below:
def bn = BarNumber();
def time = SecondsFromTime(930) > 0 ;
def lod = if time then low(period = AggregationPeriod.DAY) else Double.NaN;
def lodbn = if low == lod then bn else lodbn[1];

I can get the current bar number by simply:
def currentbn = barnumber();

and the count of bars between current bar and LOD bar by:
def diff = currentbn-lodbn;

Now, this is where I am stuck -
def condition = close>close[1];
def count = sum(condition, diff); --- TOS won't let me use "diff" here because it wants me to put a fixed number here. But this is dynamic in what I'm trying to achieve.

Looking for another way to accomplish this. Thanks for helping!
Re: Fun with ThinkScript
January 16, 2018 04:29PM
Hi Robert,

You really know your stuff!

I've been working on a thinkscript to mark post/pre market high/lows without having extended hours selected in TOS. Can you help me find a way to formulate this thinkscript to do so? As you can see, I can capture the premarket high/low, but only to view it when I have "extended hours" selected under chart settings. What ideally I would like to do is have postmarket from the previous day and premarket current day high/low visible in both extended hours and non-extended hour chart settings.

def na=double.nan;
#
# Define time that OR begins (in hhmm format,
# 0100 is the default):
#
input ORBegin = 0100;
#
# Define time that OR is finished (in hhmm format,
# 09:30 is the default):
#
input OREnd = 0930;
#
# Input first and second fib extension levels
# (default 1.382, 1.621):
#
Input FibExt1=1.382;
Input FibExt2=1.621;
#
# Show Today only? (Default Yes)
#
input ShowTodayOnly={"No", default "Yes"};
def s=ShowTodayOnly;
#
# Show Second fib extension? (Default No)
#
input ShowFibExt2={default "No", "Yes"};
def sf2=ShowFibExt2;
#
# Create logic for OR definition:
#
Def ORActive = if secondstilltime(OREnd)>0 AND secondsfromtime(ORBegin)>=0 then 1 else 0;
#
# Create logic to paint only current day post-open:
#
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(ORBegin)>=0 then 1 else 0;
#
# Track OR High:
#
Rec ORHigh = if ORHigh[1]==0 or ORActive[1]==0 AND ORActive==1 then high else if ORActive AND high>ORHigh[1] then high else ORHigh[1];
#
# Track OR Low:
#
Rec ORLow = if ORLow[1]==0 or ORActive[1]==0 AND ORActive==1 then low else if ORActive AND low<ORLow[1] then low else ORLow[1];
#
# Calculate OR width:
#
Def ORWidth = ORHigh - ORLow;
#
# Calculate fib levels:
#
Def fib_mid = (ORHigh+ORLow)/2;
Def fib_ext_up1 = ORHigh + ORWidth*(FibExt1 - 1);
Def fib_ext_down1 = ORLow - ORWidth*(FibExt1 - 1);
Def fib_ext_up2= ORHigh + ORWidth*(FibExt2 - 1);
Def fib_ext_down2 = ORLow - ORWidth*(FibExt2 - 1);
#
# Define all the plots:
#
Plot ORH=if ORActive OR today<1 then na else ORHigh;
Plot ORL=if ORActive OR today<1 then na else ORLow;
Plot FibMid=if ORActive OR today<1 then na else fib_mid;
Plot FibExtUp1=if ORActive OR today<1 then na else fib_ext_up1;
Plot FibExtDown1=if ORActive OR today<1 then na else fib_ext_down1;
Plot FibExtUp2=if ORActive OR today<1 OR sf2<1 then na else fib_ext_up2;
Plot FibExtDown2=if ORActive OR today<1 OR sf2<1 then na else fib_ext_down2;
#
# Formatting:
#
ORH.setdefaultcolor(color.green);
ORH.setStyle(curve.Long_DASH);
ORH.setlineweight(3);
ORL.setdefaultcolor(color.red);
ORL.setStyle(curve.Long_DASH);
ORL.setlineweight(3);
FibMid.setdefaultcolor(color.gray);
FibMid.setStyle(curve.SHORT_DASH);
FibMid.setlineweight(3);
FibExtUp1.setdefaultcolor(color.green);
FibExtUp1.setStyle(curve.SHORT_DASH);
FibExtUp1.setlineweight(2);
FibExtDown1.setdefaultcolor(color.red);
FibExtDown1.setStyle(curve.SHORT_DASH);
FibExtDown1.setlineweight(2);
FibExtUp2.setdefaultcolor(color.green);
FibExtUp2.setStyle(curve.SHORT_DASH);
FibExtUp2.setlineweight(1);
FibExtDown2.setdefaultcolor(color.red);
FibExtDown2.setStyle(curve.SHORT_DASH);
FibExtDown2.setlineweight(1);
Sorry, only registered users may post in this forum.

Click here to login