Excluding after hours and pre market orders.

M

masonbarnard

New member
how do i exclude after-hours or premarket session orders from triggering in a custom think script? I only want the orders to "trigger" intraday (open to close)

The strategy is simply premarket high long, moving average exit, and a custom stop.

--------------------

#pm_high_low

input alertPeriodStart = 930;
input alertPeriodEnd = 1130;
input alertOnBreak = no;
input alertOnPullBack = no;
input numberOfDays = 2;
input numberOfYears = 0;


input price = close;
input length = 50;
input displace = 0;
input showBreakoutSignals = no;

plot SMA = Average(price[-displace], length);

SMA.SetDefaultColor(GetColor(1));


def startCounter = SecondsFromTime(alertPeriodStart);
def endCounter = SecondsTillTime(alertPeriodEnd);

def alertPeriod = if startCounter >= 0 and endCounter >= 0 then 1 else 0;

def regularSessionHours = RegularTradingStart(GetYYYYMMDD()) <= GetTime();
def extendedSessionHours = RegularTradingStart(GetYYYYMMDD()) >= GetTime();

def extendedSessionStart = regularSessionHours[1] and extendedSessionHours;
def regularSessionStart = extendedSessionHours[1] and regularSessionHours;

def extendedSessionHigh = CompoundValue(1, if extendedSessionStart then high else if extendedSessionHours then Max(high, extendedSessionHigh[1]) else extendedSessionHigh[1], high);

def extendedSessionLow = CompoundValue(1, if extendedSessionStart then low else if extendedSessionHours then Min(low, extendedSessionLow[1]) else extendedSessionLow[1], low);

def regularSessionHigh = CompoundValue(1, if regularSessionStart then high else if regularSessionHours then Max(high, regularSessionHigh[1]) else regularSessionHigh[1], 0);

def regularSessionLow = CompoundValue(1, if regularSessionStart then low else if regularSessionHours then Min(low, regularSessionLow[1]) else regularSessionLow[1], 0);


AddOrder(OrderType.BUY_TO_OPEN, close crosses extendedSessionHigh and sma, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "entry");
AddOrder(OrderType.SELL_TO_CLOSE, price crosses below sma, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "exit");
AddOrder(OrderType.SELL_TO_CLOSE, price < extendedSessionLow and sma, tickcolor = GetColor(2), arrowcolor = GetColor(1), name = "Stop");



#---------- Plot the overnight high/low during regular market hours
plot overnightHigh = extendedSessionHigh;
overnightHigh.SetDefaultColor(Color.GREEN);
overnightHigh.SetLineWeight(1);
overnightHigh.SetPaintingStrategy(PaintingStrategy.LINE);
overnightHigh.SetStyle(Curve.FIRM);
plot overnightLow = extendedSessionLow;
overnightLow.SetDefaultColor(Color.RED);
overnightLow.SetLineWeight(1);
overnightLow.SetPaintingStrategy(PaintingStrategy.LINE);
overnightLow.SetStyle(Curve.FIRM);
 
M

masonbarnard

New member
nevermind got it, had to add alert period to orders
 

Similar threads

Top