Overnight Hold strategy- unfinished, not backtested

Started to post this in the "strategies" section but as you can tell from the title haven't figured it out yet. Was hoping to get some feedback and suggestion; input for if this idea is pointless.

So I love @YungTraderFromMontana breakout scan, Mobius mobile fractal pivot script and one of my own I have been using to find breakouts. But I always think "how can I catch them the day before?" A lot of afternoons, before the market closes, I look through my watchlist looking for those tickers that are close to a "entry" plot just to get idea, and by morning some of them have gapped up to the entry point.

So the thought is to use overnight ATR in relation to a breakout entry point as a measure if a ticker will gap up overnight to that plot. So If a stock is under an entry point but overnight ATR is greater than the distance between close and entry line then it would be a BUY. Think of it as a proximity filter for use on your favorite breakout. If your interested keep reading.

Here is what I have so far. Pieced together the overnight ATR script from the forum. Due to time agg the timeframe needs to be under the daily timeframe. Think that is most of my issues. The breakout portion could be changed out for any breakout script, its just what I'm using. Maybe you have another idea.

Code:
#BYEBYE_Money Breakout
#By Prison Mke
input price = close;
input highestInXBars = 10;
input lookBackBars = 10;
def highestInBarsBack = Highest(high, highestInXBars);
def lastBar = !IsNaN(close) and IsNaN(close[-1]);
def targetHigh = if lastBar then highestInBarsBack[lookBackBars] else 0;
plot higherlevel = HighestAll(targetHigh);

input highestInXBars2 = 20;
input lookBackBars2 = 20;
def highestInBarsBack2 = Highest(high, highestInXBars2);
def lastBar2 = !IsNaN(close) and IsNaN(close[-1]);
def targetHigh2 = if lastBar2 then highestInBarsBack[lookBackBars2] else 0;
plot highestlevel = HighestAll(targetHigh2);

input lowestInXBars = 10;
input lowlookBackBars = 10;
def lowestInBarsBack = Lowest(low, lowestInXBars);
def lowlastBar = !IsNaN(close) and IsNaN(close[-1]);
def targetLow = if lowlastBar then lowestInBarsBack[lowlookBackBars] else Double.POSITIVE_INFINITY;
plot lowerlevel = LowestAll(targetLow);

input lowestInXBars1 = 20;
input lowlookBackBars1 = 20;
def lowestInBarsBack1 = Lowest(low, lowestInXBars1);
def lowlastBar1 = !IsNaN(close) and IsNaN(close[-1]);
def targetLow1 = if lowlastBar1 then lowestInBarsBack1[lowlookBackBars1] else Double.POSITIVE_INFINITY;
plot lowestlevel = LowestAll(targetLow1);


#OVER NIGHT ATR stuff

input agg = AggregationPeriod.DAY;
input length = 14;
input averageType = AverageType.WILDERS;
input PlotPreMktLinesHrsPastOpen = yes;

def bar = BarNumber();
def nan = Double.NaN;
def vHigh = high(period= agg);
def vLow = low(period= agg);
def vClose = close(period= agg);


def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def RMhrs = RegularTradingStart (GetYYYYMMDD()) < GetTime();
def PMStart = RMhrs[1] and PMhrs;
def PMclose = CompoundValue(1, if PMStart then vHigh else if PMhrs then Max(vHigh, PMclose[1]) else PMclose[1], 0);
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;


#problem solving stuff
def ONATR = MovingAverage(averageType, TrueRange(PMHigh, PMclose, PMLow), length);


AddLabel(yes,Round( ONATR )+ ": " );

def dollasaway = higherlevel - pmclose or highestlevel- pmclose;

Addlabel(yes, dollasaway+ ":");
def amount= dollasaway- onatr;
addlabel(yes, amount+ ":" );

#Signal
plot OverNite_entry = dollasaway < ONATR;


Next would be making it a strategy to see if it was pointless. But not there yet.
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

So got a little farther on my idea. Overnight ATR works and have added it to my watchlist. Had the wrong variable originally. Pivots came from a Mobius code I chopped up. Thanks Mobius.

The idea for the study is instead of waiting for a break of a high, why not buy towards the end of the day once price is within overnight ATR range and play the gap up to the breakout.

Still have a few issues creating a scan and also would like it to only agg from daily timeframe but it won't. Cant backtest it either bc of the way the pivots are defined. Also originally had the cloud only showing on the current day, but wouldn't show on daily chart so I removed those lines.
The code needs to be really looked over and fine tuned but its a start.


Code:
#Overnight ATR gapup idicator V1
#By Prison Mike


#Pivots come from a Mobius code
#The idea for the study is instead of waiting for a break of a high, why not buy towards the end of the day and play the gap up to the breakout high.
#Having an issue creating a scan for it and also would like it to only agg from daily timeframe. Cant backtest it either bc of the way the pivots are defined.
#also originally had the cloud only showing on the current day, but wouldnt show on daily chart so I removed those lines.
#The code needs to be really looked over.



input n = 10;
def bar = BarNumber();
def nan = Double.NaN;
input Agg = AggregationPeriod.day;
input Length = 500;
input AverageType = AverageType.SIMPLE;
input ATRMulti = .75;
def h = high(period = Agg);
def l = low(period = Agg);
def c = close(period = Agg);


def hrs = RegularTradingStart (GetYYYYMMDD()) ;

#input buy= 1200;
#def buytime=  SecondsFromTime(buy) >=  !IsNaN(c);

def PMhrs = RegularTradingStart (GetYYYYMMDD()) > GetTime();
def RMhrs = RegularTradingStart (GetYYYYMMDD()) < GetTime();
def PMStart = RMhrs[1] and PMhrs;
def PMclose = CompoundValue(1, if PMStart then h else if PMhrs then Max(h, PMclose[1]) else PMclose[1], 0);
def PMHigh = CompoundValue(1, if PMStart then h else if PMhrs then Max(h, PMHigh[1]) else PMHigh[1], 0);
def PMLow = CompoundValue(1, if PMStart then l else if PMhrs then Min(l, PMLow[1]) else PMLow[1], 0);
def highBar = if PMhrs and h == PMHigh then bar else nan;
def lowBar = if PMhrs and l == 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];

def ONATR = MovingAverage(AverageType, TrueRange(h, c, l), Length) * ATRMulti;

# Internal Script Reference
script LinePlot {
    input BarID = 0;
    input Value = 0;
    input BarOrigin = 0;
    def ThisBar = HighestAll(BarOrigin);
    def ValueLine = if BarOrigin == ThisBar
                then Value
                else Double.NaN;
    plot P = if ThisBar - BarID <= BarOrigin
             then HighestAll(ValueLine)
             else Double.NaN;
}

def PH;
def PL;
def hh = fold i = 1 to n + 1
            with p = 1
            while p
            do h > GetValue(h, -i);
PH = if (bar > n and
                h == Highest(h, n) and
                hh)
            then h
            else Double.NaN;
def ll = fold j = 1 to n + 1 
            with q = 1
            while q
            do l < GetValue(low, -j);
PL = if (bar > n and
                l == Lowest(l, n) and
                ll)
            then l
            else Double.NaN;
def PHBar = if !IsNaN(PH)
               then bar
               else PHBar[1];
def PLBar = if !IsNaN(PL)
               then bar
               else PLBar[1];
def PHL = if !IsNaN(PH)
             then PH
             else PHL[1];
def priorPHBar = if PHL != PHL[1]
                    then PHBar[1]
                    else priorPHBar[1];
def PriorPH = if PHL != PHL[1]
                 then PHL[1]
                 else PriorPH[1];
def PLL = if !IsNaN(PL)
             then PL
             else PLL[1];

def HighPivots = bar >= HighestAll(priorPHBar);

def FirstRpoint = if HighPivots
                     then bar - PHBar
                     else 0;


plot PivotHighLine = LinePlot(FirstRpoint, PH, PHBar);
PivotHighLine.SetStyle(Curve.FIRM);
PivotHighLine.SetDefaultColor(Color.GREEN);



plot EntryATR =  PivotHighLine - ONATR;
EntryATR.SetStyle(Curve.SHORT_DASH);
EntryATR.SetDefaultColor(Color.GREEN);
AddCloud(PivotHighLine, EntryATR, Color.YELLOW, Color.YELLOW);


plot UpArrow = if hrs and  c crosses above EntryATR then c else nan;
UpArrow.SetPaintingStrategy(paintingStrategy.POINTS);
uparrow.setdefaultcolor(color.green);


AddLabel(yes, Round( ONATR ) + " " );
 
I am liking the idea you have behind this. Can be a bit frustrating to see a stock one is interested in buying shoot up several dollars overnight before you enter.
 
@RickAns, @codydog thanks for your comments.

Ultimately there needs to be more criteria for an entry to confirm it’s going to pop overnight, but this is a start in seeing the relationship.

C-dog, you mean to backtest it? It’s what imma try.
 
@Prison Mike - i've always learned more when i entered a real trade to see what was right or wrong in my strategies than just back testing - i think making or losing cash is a great tutor!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
573 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top