How to get current day's premarket high?

MrKrabs

MrKrabs

New member
Hey all

Trying to hack together a few different studies, a main component being able to capture the current day's premarket high. I'm unsure how to get this data.

Here's part of something I've found online, but it...doesn't seem to always be accurate. Or when it is it seems just slightly accurate. It's weird.

Code:
def stageOne = RegularTradingEnd(GetYYYYMMDD());
def premarketStart = stageOne[1] <> stageOne;
def stageTwo = SecondsTillTime(930);
def premarketSession = stageTwo > 0;
rec premarketHigh = if premarketStart and premarketSession then high else if high > premarketHigh[1] and premarketSession then high else premarketHigh[1];
 
horserider

horserider

Well-known member
VIP
Code:
input PlotPreMktLinesHrsPastOpen = 0;


def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def RMhrs = RegularTradingStart (GetYYYYMMDD()) < GetTime();
def PMStart = RMhrs[1] and PMhrs;
def PMHigh = CompoundValue(1, if PMStart then high else if PMhrs then Max(high, PMHigh[1]) else PMHigh[1], 0);
def bar = BarNumber();
def highBar = if PMhrs and high == PMHigh then bar else Double.NaN;
def PMHighBar = if bar == HighestAll(highBar) then PMHigh else PMHighBar[1];

plot PMH =  PMHighBar;
 
korygill

korygill

Active member
VIP
Might as well add the low and the mid and fix issue with drawing lines on 0. It should be possible I think to eliminate that HighestAll call (expensive). Here's my addition for all this sans a HighestAll fix....

I was actually just thinking about this for my charts...I will modify a bit further to change colors, line types, etc. But nice solution @horserider.

Code:
#
# see https://usethinkscript.com/threads/how-to-get-current-days-premarket-high.695/
#
declare once_per_bar;

input PlotPreMktLinesHrsPastOpen = yes;

def bar = BarNumber();
def nan = Double.NaN;
def vHigh = high;
def vLow = low;

def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def RMhrs = RegularTradingStart (GetYYYYMMDD()) < GetTime();
def PMStart = RMhrs[1] and PMhrs;
def PMHigh = CompoundValue(1, if PMStart then vHigh else if PMhrs then Max(vHigh, PMHigh[1]) else PMHigh[1], 0);
def PMLow = CompoundValue(1, if PMStart then vLow else if PMhrs then Min(vLow, PMLow[1]) else PMLow[1], 0);
def highBar = if PMhrs and vHigh == PMHigh then bar else nan;
def lowBar = if PMhrs and vLow == PMLow then bar else nan;
def PMHighBar = if bar == HighestAll(highBar) then PMHigh else PMHighBar[1];
def PMLowBar = if bar == HighestAll(lowBar) then PMLow else PMLowBar[1];

plot PMH =  if PlotPreMktLinesHrsPastOpen and PMHighBar != 0
            then PMHighBar
            else nan;
plot PML =  if PlotPreMktLinesHrsPastOpen and PMLowBar != 0
            then PMLowBar
            else nan;
plot PMMid = if PlotPreMktLinesHrsPastOpen and PMHighBar != 0 and PMLowBar != 0
             then (PMHighBar+PMLowBar)/2
             else nan;

# end of script
 
U

Utajiri

New member
Might as well add the low and the mid and fix issue with drawing lines on 0. It should be possible I think to eliminate that HighestAll call (expensive). Here's my addition for all this sans a HighestAll fix....

I was actually just thinking about this for my charts...I will modify a bit further to change colors, line types, etc. But nice solution @horserider.

Code:
#
# see https://usethinkscript.com/threads/how-to-get-current-days-premarket-high.695/
#
declare once_per_bar;

input PlotPreMktLinesHrsPastOpen = yes;

def bar = BarNumber();
def nan = Double.NaN;
def vHigh = high;
def vLow = low;

def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def RMhrs = RegularTradingStart (GetYYYYMMDD()) < GetTime();
def PMStart = RMhrs[1] and PMhrs;
def PMHigh = CompoundValue(1, if PMStart then vHigh else if PMhrs then Max(vHigh, PMHigh[1]) else PMHigh[1], 0);
def PMLow = CompoundValue(1, if PMStart then vLow else if PMhrs then Min(vLow, PMLow[1]) else PMLow[1], 0);
def highBar = if PMhrs and vHigh == PMHigh then bar else nan;
def lowBar = if PMhrs and vLow == PMLow then bar else nan;
def PMHighBar = if bar == HighestAll(highBar) then PMHigh else PMHighBar[1];
def PMLowBar = if bar == HighestAll(lowBar) then PMLow else PMLowBar[1];

plot PMH =  if PlotPreMktLinesHrsPastOpen and PMHighBar != 0
            then PMHighBar
            else nan;
plot PML =  if PlotPreMktLinesHrsPastOpen and PMLowBar != 0
            then PMLowBar
            else nan;
plot PMMid = if PlotPreMktLinesHrsPastOpen and PMHighBar != 0 and PMLowBar != 0
             then (PMHighBar+PMLowBar)/2
             else nan;

# end of script
Hi @korygill - I picked up on this premarket Hilo code you built. Awesome.... Is there a way to add a marker or bubble input to it.... just so it can be identified in the midst of multiple lines on a chart?
 
korygill

korygill

Active member
VIP
Try this update to put a chart bubble on each line.



Code:
#
# see https://usethinkscript.com/threads/how-to-get-current-days-premarket-high.695/
#
declare once_per_bar;

input PlotPreMktLinesHrsPastOpen = yes;
input ShowChartBubbles = yes;

def bar = BarNumber();
def nan = Double.NaN;
def vHigh = high;
def vLow = low;

def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def RMhrs = RegularTradingStart (GetYYYYMMDD()) < GetTime();
def PMStart = RMhrs[1] and PMhrs;
def PMHigh = CompoundValue(1, if PMStart then vHigh else if PMhrs then Max(vHigh, PMHigh[1]) else PMHigh[1], 0);
def PMLow = CompoundValue(1, if PMStart then vLow else if PMhrs then Min(vLow, PMLow[1]) else PMLow[1], 0);
def highBar = if PMhrs and vHigh == PMHigh then bar else nan;
def lowBar = if PMhrs and vLow == PMLow then bar else nan;
def PMHighBar = if bar == HighestAll(highBar) then PMHigh else PMHighBar[1];
def PMLowBar = if bar == HighestAll(lowBar) then PMLow else PMLowBar[1];

plot PMH =  if PlotPreMktLinesHrsPastOpen and PMHighBar != 0
            then PMHighBar
            else nan;
plot PML =  if PlotPreMktLinesHrsPastOpen and PMLowBar != 0
            then PMLowBar
            else nan;
plot PMMid = if PlotPreMktLinesHrsPastOpen and PMHighBar != 0 and PMLowBar != 0
             then (PMHighBar + PMLowBar) / 2
             else nan;

AddChartBubble(ShowChartBubbles and bar == HighestAll(highBar),
  PMHigh,
  "PM High",
  Color.Gray,
  1);

AddChartBubble(ShowChartBubbles and bar == HighestAll(lowBar),
  PMLow,
  "PM Low",
  Color.Gray,
  0);

AddChartBubble(ShowChartBubbles and bar == Max(HighestAll(highBar), HighestAll(lowBar)),
  (PMHighBar + PMLowBar) / 2,
  "PM Mid",
  Color.Gray,
  1);

# end of script
 
U

Utajiri

New member
Thanks @korygill - appreciate it. Can we however have an additional input on where to place the bubble? Something like a "distance from last candle" input..... which allows us input a value and it places the chart bubble where we want it... either to the left,right or center?
 
S

snappy33

New member
Hello,
I wanted to scan for stocks above Premarket High based on the post below that plots the indicator
https://usethinkscript.com/threads/how-to-get-current-days-premarket-high.695/post-5193and came up with the following which doesnt pull any stocks when creating a Custom Study scan:

Code:
input PlotPreMktLinesHrsPastOpen = 0;


def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def RMhrs = RegularTradingStart (GetYYYYMMDD()) < GetTime();
def PMStart = RMhrs[1] and PMhrs;
def PMHigh = CompoundValue(1, if PMStart then high else if PMhrs then Max(high, PMHigh[1]) else PMHigh[1], 0);
def bar = BarNumber();
def highBar = if PMhrs and high == PMHigh then bar else Double.NaN;
def PMHighBar = if bar == HighestAll(highBar) then PMHigh else PMHighBar[1];

plot PMH =  close > PMHighBar;
Any help greatly appreciated!
 
horserider

horserider

Well-known member
VIP
plot PMH = close > PMHighBar; Rethink what you are plotting? Does this even plot?
 
S

snappy33

New member
plot PMH = close > PMHighBar; Rethink what you are plotting? Does this even plot?
Not a coder by any means and barely crawling at that horserider, it doesnt plot and hence why want to learn why as the indicator is correct to what I want it to do (or look for) but looking for help or guidance to learn
 
horserider

horserider

Well-known member
VIP
@snappy33 Not a scan expert but seems you will need to use the PMhigh study in your scan then add an additional scan condition to find close over PMhigh probably within a few bars.

close crosses PreMarket_High() within 3 bars

Something like the above with the bold text being the name of your premarket high study. Also can make 2 scans one for cross above and one for cross below if preferred. Should be able to make these easily in scan condition wizard. Start with price ,close then cross, then study.
 
C

C4men

Member
@horserider Not to bug you, but I think you'd be able to help me pretty quickly with a variation of the above script that would paint each day.

I am looking for:
  • 4 lines: Pre-market High, Pre-market Low, Previous Day High, Previous Day Low
  • Would paint all lines at market open and maintain extension right, (through the day)
  • With a "cloud" between the top two and a cloud between the bottom two
  • Ability to adjust the color of the clouds

-- PM High --
(cloud color 1)
-- PD High --


-- PM Low --
(cloud color 2)
-- PD Low --

Can you help a total newbie get going on this?
 
horserider

horserider

Well-known member
VIP
Ok just threw together Kory's study above with a PD study. Not interested in spending time making it pretty or exactly to your wants but should function.
 
I

Ishaam

Member
VIP
Hi @korygill , is it possible to have 2 x inputs for this script to define pre-market selected hours that you want the script to plot for? Example, I would like to plot the high, low, mid for hours between 12am and 8am EST, would appreciate your help on this, thanks.
 
3AMBH

3AMBH

Member
2019 Donor
VIP
Hi Traders,

How are you using the pre-market price level in your trading decisions?. Thanks
 
Top