Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Tracking gaps on ES Futures

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Tracking gaps on ES Futures

    Hi all,

    I am trying to create a simple script that checks for gap ups or gap downs on ES futures. The logic is quite simple so I'm not sure where I'm screwing up (output results are incorrect)

    All I want to do is the following

    1) Compare the first 5 minute bar data with the last 5 minute bar of the previous day
    2) Compute whether there was a gap up or gap down
    3) Print the gap results at the end of the script

    For some reason when I run the script against 2019, the logic is running on the 8:35am bar instead of the 9:35am bar (close of the first bar, BarsRequiredToTrade being 1). I am also not getting any gap prints once the script is terminated. Hoping an expert can chime in here and point me in the right direction.

    I am testing the logic in the Strategy Analyzer, and I have the template set specifically to US Equities RTH because I want 9:30-4pm EST data to be included only.


    namespace NinjaTrader.NinjaScript.Strategies.JBAlgos

    {



    public class TradeOrFade : Strategy

    {



    private int gapCount;

    private int gapUps;

    private int gapDowns;



    protected override void OnStateChange()

    {

    if (State == State.SetDefaults)

    {

    Description = @"Enter the description for your new custom Strategy here.";

    Name = "TradeOrFade";

    Calculate = Calculate.OnBarClose;

    EntriesPerDirection = 1;

    EntryHandling = EntryHandling.AllEntries;

    IsExitOnSessionCloseStrategy = true;

    ExitOnSessionCloseSeconds = 30;

    IsFillLimitOnTouch = false;

    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;

    OrderFillResolution = OrderFillResolution.Standard;

    Slippage = 0;

    StartBehavior = StartBehavior.WaitUntilFlat;

    TimeInForce = TimeInForce.Gtc;

    TraceOrders = false;

    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;

    StopTargetHandling = StopTargetHandling.PerEntryExecution;

    BarsRequiredToTrade = 1;

    // Disable this property for performance gains in Strategy Analyzer optimizations

    // See the Help Guide for additional information

    IsInstantiatedOnEachOptimizationIteration = true;

    }

    else if (State == State.Configure)

    {

    AddDataSeries(BarsPeriodType.Minute, 5);

    }

    else if(State == State.Terminated){

    Print(string.Format("Found {0} gaps in total, {1} were down gaps, {2} were up gaps:", gapCount, gapDowns, gapUps));

    }

    }




    protected override void OnBarUpdate()

    {

    // Check if there are enough bars loaded for the primary data series

    if (CurrentBar < BarsRequiredToTrade) return;



    Print(string.Format("Close[1], {0}, @ {1}", Close[1], Time[1]));

    Print(string.Format("Open[0], {0}, @ {1}", Open[0], Time[0]));



    if(Close[1] - Open[0] > 1){

    Print("Found down gap " + Time[0]);

    gapCount++;

    gapDowns++;

    }



    if(Open[0] - Close[1] > 1){

    Print("Found up gap " + Time[0]);

    gapCount++;

    gapUps++;

    }



    }

    }

    }
    jaybedreamin
    NinjaTrader Ecosystem Vendor - Zion Trading Algos

    #2
    Hello jaybedreamin,

    Thank you for your post.

    You may be able to utilize IsFirstBarOfSession and IsLastBarOfSession in order to get the desired results in your script. For more information, please see the following help guide pages:For the print when the State is State.Terminated, do you receive any error messages on the Log tab of the Control Center? More information about the NinjaScript Lifecycle and State.Terminated may be found at the following links:Please let me know if I may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    10 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    14 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    11 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Yesterday, 07:51 PM
    0 responses
    13 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,983 views
    3 likes
    Last Post jhudas88  
    Working...
    X