Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to force trades on 1Tick series with multiple dataseries

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

    Trying to force trades on 1Tick series with multiple dataseries

    So I'm having some weirdness happen. Main strategy runs on 5000 Tick chart. I've also added 1 tick dataseries to the strategy. The logic is dumbed down so I can see an entry and an exit where I would expect to see it on the charts in a test strategy.

    Yet, entries and exits happen only on bar open/close (which I understand are the same) events on the main data series. Even though Ninjascript output appears to confirm entries are on second dataseries.

    Caluclations are set to Calculate = Calculate.OnPriceChange and I've tried with different indicators as well and get the same behavior.

    What I would expect to see is the entry/exit happening is the entry exit happening at random points along a bar instead of always at close/open. What am I missing?

    edit: tried to format code and it made it even less readable - how do I format code correctly?
    2nd edit: Removed "Code" tags and now the INDENT function is working properly and it's readable

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"";
    Name = "AZL";
    Calculate = Calculate.OnPriceChange;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 1800;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.High;
    OrderFillResolutionType = BarsPeriodType.Tick;
    OrderFillResolutionValue = 1;
    Slippage = 0;
    StartBehavior = StartBehavior.ImmediatelySubmitSynchronizeAccount;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = true;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    IsInstantiatedOnEachOptimizationIteration = false;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Tick, 1); // Add a 1 Tick Bars object: BarsInProgress index = 1
    }
    else if (State == State.DataLoaded)
    {
    linRegLength = 3;
    linReg = LinReg(linRegLength);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0) return; //only apply logic to the main data series - commenting this out doesn't change behavior
    if(BarsInProgress == 1) // 1 tick series
    {
    // This is never printed
    Print(Time[0] + " on BIP = " + BarsInProgress + " | Close[0]: " + Close[0]);
    }
    // Enter Long
    if (CrossAbove(linReg, ema, 1))
    {
    if (Position.MarketPosition == MarketPosition.Short)
    ExitShort(1,1, @"SX", @"SE");
    if (Position.MarketPosition == MarketPosition.Flat)
    EnterLong(1,1, @"LE");
    }

    // Enter Short
    if (CrossBelow(linReg, ema, 1))
    {
    if (Position.MarketPosition == MarketPosition.Long)
    ExitLong(1,1, @"LX", @"LE");
    if (Position.MarketPosition == MarketPosition.Flat)
    EnterShort(1,1, @"SE");
    }



    Attached Files
    Last edited by markdshark; 03-15-2023, 01:29 PM.

    #2
    When you place the orders, either place them explicitly on series #0 by using the overload to the order placement functions that lets you specify which series it is for, or make them keep alive and cancel them yourself when you want them canceled - if you place the orders like you're doing on series which is a 1-tick series it's canceled on the next tick, when the next 1-tick bar comes (the bar after your order was placed, so your order is now expired), which is before you get a fill. The randomness you are experiencing is probably related to repeatedly placing and canceling these orders every tick which is probably not what you were trying to do.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hello markdshark,

      "Yet, entries and exits happen only on bar open/close (which I understand are the same) events on the main data series."

      The logic is running on the primary series.

      if (BarsInProgress != 0) return; //only apply logic to the main data series - commenting this out doesn't change behavior

      This means it only updates when the primary bar closes.

      If you want to update intra-bar, enable TickReplay and use Calculate.OnEachTick or Calculate.OnBarClose.



      If you want to know why a strategy is behaving as it is, print the time of the bar and all values used in the condition with labels for each value and comparison operator.


      Provide the output saved to a text file for assistance with analyzing the output.
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      79 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      148 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      79 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      52 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      58 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X