E-Mini SP 500

es111619.PNG
 
understanding regresssions .. notice the blue arrows, 3 points of regression .. a line in geometry takes 2 points .. once two points are established either you play the 3rd or wait for the 4th ..
 

Attachments

  • arrow.PNG
    arrow.PNG
    264.6 KB · Views: 392
the low on the 3rd regression proximity was on 11/13/19 .. 3075.75 , deploying the 'Line In Sand' algo or the breakout algo .. not the Inv Line In Sand. You input the dates 11/13/19 and the pivot 3075.75
 
if deployed on
11/13/19 .. the drawdown would be ~ 675 .. cum profit ~600
11/14/19 ~ -300 - 775
11/15/10 ~1,762.5

Can be used for swing trading .. the problem with traditional orders, it would only trigger once, and you would have to keep reinstituting the order again and again till breakout, tedious and screen intensive for trader.
 
Key is to find discrete structure, where the human eye see's a pattern, other regression players will see that break and look to get in intraday .. the market maker algo's also realize this, and will try to throw off as many positions as possible. If intraday trading, just exit on the close, don't hold anything overnight and just reinstitute on session open. The coded algo does this. It lets you input, the previous 8p-midnight session plus new day session till close. Main thing like anything, its not 100% efficiency. Zig Zag trades will create costs till final breakout.

If your playing high zig zag zone, based on market profile. Than instituting the Inv algo, would work against the market makers.
 
Last edited:
Consolidative pattern (zig zag) is always greater before the extent of the resulting gap, Meaning market makers will consolidate it extensively before the gap which is nominal.
 
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Trades like a straddle/breakout algo
/// </summary>
[Description("Trades based on time intervals using pivots")]
public class CrossLIS : Strategy
{
#region Variables
// Wizard generated variables
private double pricepivot = 3019.00; // Default setting for Pricepivot
private double pricepivotb = 3019.00;
private double pricepivotc = 3019.00;
private int tickprofit = 160; // Default setting for Tickprofit
private int tickstoploss = 16; // Default setting for Tickstoploss
private int trailtick = 40; // Default setting for Trailtick
private int quantity = 1;
private int starttime = 180000;
private int stoptime = 240000;
private int starttimeb = 1;
private int stoptimeb = 100000;
private int starttimec = 100100;
private int stoptimec = 153200;
private int startdate = 20190101;
private int stopdate = 20191231;
private int startdateb = 20190101;
private int stopdateb = 20191231;
private int startdatec = 20190101;
private int stopdatec = 20191231;
private int startcloseout = 153900;
private int stopcloseout = 154400;
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{

Add(PriorDayOHLC());
Add(CurrentDayOHL());
SetProfitTarget("", CalculationMode.Ticks, Tickprofit);
SetStopLoss("", CalculationMode.Ticks, Tickstoploss, true);
SetTrailStop("", CalculationMode.Ticks, Trailtick, true);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (ToDay(Time[0])>= startdate && ToDay(Time[0]) <= stopdate)
{
if ((ToTime(Time[0]) >= starttime && ToTime(Time[0]) <= stoptime))
{

// Condition set 1
if (CrossAbove(Close, Pricepivot, 1))


{
EnterLong(Quantity, "");
}

// Condition set 2
if (CrossBelow(Close, Pricepivot, 1))


{
EnterShort(Quantity, "");
}


}
}



if (ToDay(Time[0])>= startdateb && ToDay(Time[0]) <= stopdateb)
{
if ((ToTime(Time[0]) >= starttimeb && ToTime(Time[0]) <= stoptimeb))
{

// Condition set 3

if (CrossAbove(Close, Pricepivotb, 1))

{
EnterLong(Quantity, "");
}

// Condition set 4
if (CrossBelow(Close, Pricepivotb, 1))


{
EnterShort(Quantity, "");
}


}
}
if (ToDay(Time[0])>= startdatec && ToDay(Time[0]) <= stopdatec)
{
if ((ToTime(Time[0]) >= starttimec && ToTime(Time[0]) <= stoptimec))
{

// Condition set 5
if (CrossAbove(Close, Pricepivotc, 1))


{
EnterLong(Quantity, "");
}

// Condition set 6
if (CrossBelow(Close, Pricepivotc, 1))


{
EnterShort(Quantity, "");
}


}
}
if (ToDay(Time[0])>= startdatec && ToDay(Time[0]) <= stopdatec)
{
if ((ToTime(Time[0]) >= startcloseout && ToTime(Time[0]) <= stopcloseout))
{
if(Position.MarketPosition == MarketPosition.Long)
ExitLong();
if(Position.MarketPosition == MarketPosition.Short)
ExitShort();
}


}


}



#region Properties

[Description("pivot")]
[GridCategory("Parameters")]
public double Pricepivot
{
get { return pricepivot; }
set { pricepivot = Math.Max(1, value); }
}


[Description("pivot")]
[GridCategory("Parameters")]
public double Pricepivotb
{
get { return pricepivotb; }
set { pricepivotb = Math.Max(1, value); }
}


[Description("pivot")]
[GridCategory("Parameters")]
public double Pricepivotc
{
get { return pricepivotc; }
set { pricepivotc = Math.Max(1, value); }
}


[Description("tick profit")]
[GridCategory("Parameters")]
public int Tickprofit
{
get { return tickprofit; }
set { tickprofit = Math.Max(1, value); }
}


[Description("quantity")]
[GridCategory("Parameters")]
public int Quantity
{
get { return quantity; }
set { quantity = Math.Max(1, value); }
}


[Description("tick stoploss")]
[GridCategory("Parameters")]
public int Tickstoploss
{
get { return tickstoploss; }
set { tickstoploss = Math.Max(1, value); }
}


[Description("trail tick stop")]
[GridCategory("Parameters")]
public int Trailtick
{
get { return trailtick; }
set { trailtick = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]

public int Startdate
{
get { return startdate; }
set { startdate = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]

public int Stoptdate
{
get { return stopdate; }
set { stopdate = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]

public int Startdateb
{
get { return startdateb; }
set { startdateb = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]

public int Stoptdateb
{
get { return stopdateb; }
set { stopdateb = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]

public int Startdatec
{
get { return startdatec; }
set { startdatec = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]

public int Stoptdatec
{
get { return stopdatec; }
set { stopdatec = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int Starttime
{
get { return starttime;}
set { starttime = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int Stoptime
{
get { return stoptime; }
set { stoptime = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int Starttimeb
{
get { return starttimeb;}
set { starttimeb = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int Stoptimeb
{
get { return stoptimeb; }
set { stoptimeb = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int Starttimec
{
get { return starttimec;}
set { starttimec = Math.Max(1, value); }
}

[Description("")]
[GridCategory("Parameters")]
public int Stoptimec
{
get { return stoptimec; }
set { stoptimec = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int Startcloseout
{
get { return startcloseout; }
set { startcloseout = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int Stopcloseout
{
get { return stopcloseout; }
set { stopcloseout = Math.Max(1, value); }
}
#endregion

}
}
 
Added code to close out any positions if small account is being used, and closeout is mandatory. Notice the difference in sets of code, one if 'crosses above' crosses below' and other is > or < than .. variation. Ninjatrader Brokerage has mandatory margin check at 15:45 EST USA time. To build a safe amount of time for bar generation to trigger closeout, a large interval is used so account is not in margin violation.
 
Last edited:
Startdate and stopdate is usually Asian Session (11/19/19)
Startdateb and stopdateb is from midnight to midday next day (11/20/19)
Startdatec and stopdatec is from midday to closing day (11/20/19)

Starttime and stoptime is Asian session (18:00-24:00)
Starttimeb and stoptimeb is from midnight to midday (1-12:00)
Starttimec and stoptimec is from midday to closeoutstart
Closeoutstart to Closeoutstop (interval to exit positions)

Ideally you want to start the time intervals where you see a trendline break anticipated or has occurred. Or if trading news event is planned. The variation is code 'Cross Above/Below' or '> or <' the algo wont trigger if price has moved away using 'Cross Above/Below' method, but will trigger if using the > or < method. Reason being the Algo checks each bar generated to trigger code, both sets or variations have use in different situations.

You need some basic Ninjatrader code working knowledge to put it to use and create variations.
 
Last edited:
Price during different time intervals has different pivot outliers, if you try to backtest using the same pivot for historical data, you will get a great amount of zig zag costs. Up trending markets, the pivots are usually close to the prior session lows, and down trending markets, the pivots are usually above.
 
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
/// <summary>
/// Trades like a straddle/breakout algo
/// </summary>
[Description("Trades based on time intervals using pivots")]
public class AbBeLIS : Strategy
{
#region Variables
// Wizard generated variables
private double pricepivot = 3019.00; // Default setting for Pricepivot
private double pricepivotb = 3019.00;
private double pricepivotc = 3019.00;
private int tickprofit = 160; // Default setting for Tickprofit
private int tickstoploss = 16; // Default setting for Tickstoploss
private int trailtick = 40; // Default setting for Trailtick
private int quantity = 1;
private int starttime = 180000;
private int stoptime = 240000;
private int starttimeb = 1;
private int stoptimeb = 100000;
private int starttimec = 100100;
private int stoptimec = 153200;
private int startdate = 20190101;
private int stopdate = 20191231;
private int startdateb = 20190101;
private int stopdateb = 20191231;
private int startdatec = 20190101;
private int stopdatec = 20191231;
private int startcloseout = 153900;
private int stopcloseout = 154400;
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{

Add(PriorDayOHLC());
Add(CurrentDayOHL());
SetProfitTarget("", CalculationMode.Ticks, Tickprofit);
SetStopLoss("", CalculationMode.Ticks, Tickstoploss, true);
SetTrailStop("", CalculationMode.Ticks, Trailtick, true);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (ToDay(Time[0])>= startdate && ToDay(Time[0]) <= stopdate)
{
if ((ToTime(Time[0]) >= starttime && ToTime(Time[0]) <= stoptime))
{

// Condition set 1
if (Close[0] > Pricepivot)



{
EnterLong(Quantity, "");
}

// Condition set 2
if (Close[0] < Pricepivot)



{
EnterShort(Quantity, "");
}


}
}



if (ToDay(Time[0])>= startdateb && ToDay(Time[0]) <= stopdateb)
{
if ((ToTime(Time[0]) >= starttimeb && ToTime(Time[0]) <= stoptimeb))
{

// Condition set 3

if (Close[0] > Pricepivotb)


{
EnterLong(Quantity, "");
}

// Condition set 4
if (Close[0] < Pricepivotb)



{
EnterShort(Quantity, "");
}


}
}
if (ToDay(Time[0])>= startdatec && ToDay(Time[0]) <= stopdatec)
{
if ((ToTime(Time[0]) >= starttimec && ToTime(Time[0]) <= stoptimec))
{

// Condition set 5
if (Close[0] > Pricepivotc)


{
EnterLong(Quantity, "");
}

// Condition set 6
if (Close[0] < Pricepivotc)


{
EnterShort(Quantity, "");
}


}
}
if (ToDay(Time[0])>= startdatec && ToDay(Time[0]) <= stopdatec)
{
if ((ToTime(Time[0]) >= startcloseout && ToTime(Time[0]) <= stopcloseout))
{
if(Position.MarketPosition == MarketPosition.Long)
ExitLong();
if(Position.MarketPosition == MarketPosition.Short)
ExitShort();
}


}


}



#region Properties

[Description("pivot")]
[GridCategory("Parameters")]
public double Pricepivot
{
get { return pricepivot; }
set { pricepivot = Math.Max(1, value); }
}


[Description("pivot")]
[GridCategory("Parameters")]
public double Pricepivotb
{
get { return pricepivotb; }
set { pricepivotb = Math.Max(1, value); }
}


[Description("pivot")]
[GridCategory("Parameters")]
public double Pricepivotc
{
get { return pricepivotc; }
set { pricepivotc = Math.Max(1, value); }
}


[Description("tick profit")]
[GridCategory("Parameters")]
public int Tickprofit
{
get { return tickprofit; }
set { tickprofit = Math.Max(1, value); }
}


[Description("quantity")]
[GridCategory("Parameters")]
public int Quantity
{
get { return quantity; }
set { quantity = Math.Max(1, value); }
}


[Description("tick stoploss")]
[GridCategory("Parameters")]
public int Tickstoploss
{
get { return tickstoploss; }
set { tickstoploss = Math.Max(1, value); }
}


[Description("trail tick stop")]
[GridCategory("Parameters")]
public int Trailtick
{
get { return trailtick; }
set { trailtick = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]

public int Startdate
{
get { return startdate; }
set { startdate = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]

public int Stoptdate
{
get { return stopdate; }
set { stopdate = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]

public int Startdateb
{
get { return startdateb; }
set { startdateb = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]

public int Stoptdateb
{
get { return stopdateb; }
set { stopdateb = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]

public int Startdatec
{
get { return startdatec; }
set { startdatec = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]

public int Stoptdatec
{
get { return stopdatec; }
set { stopdatec = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int Starttime
{
get { return starttime;}
set { starttime = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int Stoptime
{
get { return stoptime; }
set { stoptime = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int Starttimeb
{
get { return starttimeb;}
set { starttimeb = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int Stoptimeb
{
get { return stoptimeb; }
set { stoptimeb = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int Starttimec
{
get { return starttimec;}
set { starttimec = Math.Max(1, value); }
}

[Description("")]
[GridCategory("Parameters")]
public int Stoptimec
{
get { return stoptimec; }
set { stoptimec = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int Startcloseout
{
get { return startcloseout; }
set { startcloseout = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int Stopcloseout
{
get { return stopcloseout; }
set { stopcloseout = Math.Max(1, value); }
}
#endregion

}
}
 
above is the 'above below' code. It's basically a buy and hold a swing short or long .. it exits before margin check, and reinstitutes on open of session.
 
Top