Pre-Market Change PMO to PMC/RTCO

V

VicD

Member
Hi guys. I'm working on a code/column that looks at change from Pre-Market Open to Pre-Market Close or Regular Trading Hours Open.

I hacked this together using 2 scripts but getting garbage. And it's too dang heavy. Any suggestions to define PMO and PMC easier?

Code:
# Inputs

input PlotPreMktLinesHrsPastOpen = 0;

input PlotRegMktLinesHrsPastOpen = 0;

input PlotYesterdayMktLinesHrsPastOpen = 0;

input PlotActiveRegMktLinesOnPrevDays = 0;

input DisplayPreMarketPriceBubbles = yes;

input DisplayCurrentDayPriceBubbles = yes;

input DisplayPreviousDayPriceBubbles = yes;

# Pre market / Regular market definitions

def ExtPMOut = PlotPreMktLinesHrsPastOpen * 3610000;

def ExtRMOut = PlotRegMktLinesHrsPastOpen * 3610000;

def ExtYMOut = PlotYesterdayMktLinesHrsPastOpen * 3610000;

def MktPlot = GetLastDay() - PlotActiveRegMktLinesOnPrevDays <= GetDay() and GetLastYear() - 0 <= GetYear();

def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();

def RMhrs = RegularTradingStart (GetYYYYMMDD()) < GetTime();

def PMplots = RegularTradingStart (GetYYYYMMDD()) > GetTime() - ExtPMOut;

def RMplots = RegularTradingStart (GetYYYYMMDD()) > GetTime() - ExtRMOut;

def YMplots = RegularTradingStart (GetYYYYMMDD()) > GetTime() - ExtYMOut;

def PMStart = RMhrs[1] and PMhrs;

def RMStart = PMhrs[1] and RMhrs;

def PMHigh = CompoundValue(1, if PMStart then high else if PMhrs then Max(high, PMHigh[1]) else PMHigh[1], 0);

def PMLow = CompoundValue (1, if PMStart then low else if PMhrs then Min(low, PMLow[1]) else PMLow[1], 0);





# Pre market open code

def HidePMO = if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN then yes else no;

def day = GetDay();

def PMopenBar = day != day[1];

def PMOpen = if PMopenBar then open else PMOpen[1];

def PMO = if HidePMO and MktPlot and PMplots then PMOpen else Double.NaN;





# Current day open code

def HideCDO = if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN then yes else no;

def CDOpen = if !day then Double.NaN else open (period = "day");

def CDO = if HideCDO and MktPlot and RMplots then CDOpen else Double.NaN;



plot PMC =  (PMOpen - CDOpen);
PMC.assignvalueColor(if PMC >0 then color.green else color.red);
 
V

VicD

Member
So this is not elegant. But I figured the closes I can do is this for a search column to see pre market change, I want to see if premarket is rising or falling. And this at least gives me an idea. I was trying to figure out how to set 4 am open and subtract close at 9:30 am and could not get it to work. Then tried to do day open minus 11 30 minute bars, and could not figure out the script. So went with difference of a 4 hour bar close and prior 4 minute bar close. This would have to be looked at like an hour before market open but at least it can easily show trend in a column.

Code:
plot change = Round(((CLOSE("period" = AggregationPeriod.FOUR_HOURS)-close("period" = AggregationPeriod.FOUR_HOURS)[1])/(close("period" = AggregationPeriod.FOUR_HOURS)[1]))*100, 2);

AssignBackgroundColor(if change > 0 then Color.DARK_GREEN else Color.DARK_RED);
 

Similar threads

Top