Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why doesnt my strategy using ^TICK work?

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

    Why doesnt my strategy using ^TICK work?

    Code:
    #region Using declarations
    using System;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.NinjaScript.Strategies;
    
    #endregion
    
    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class TickTrader : Strategy
        {
            private int tickThreshold = 700; // Define the threshold for TICK
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description = @"Enter the description for your new custom Strategy here.";
                    Name = "TickTrader";
                    Calculate = Calculate.OnEachTick; // More responsive with OnEachTick
                    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 = true;
                    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                    StopTargetHandling = StopTargetHandling.PerEntryExecution;
                    BarsRequiredToTrade = 20;
                    IsInstantiatedOnEachOptimizationIteration = true;
                }
                else if (State == State.Configure)
                {
                    // Add an TICK 1 minute Bars object to the strategy
                    AddDataSeries("^TICK", Data.BarsPeriodType.Minute, 1);
                    
                    // Set stop loss and profit target
                    SetStopLoss("", CalculationMode.Ticks, 8, false);
                    SetProfitTarget("", CalculationMode.Ticks, 4);
                }
            }
    
            protected override void OnBarUpdate()
            {
                // Ensure enough bars are loaded
                if (CurrentBar < BarsRequiredToTrade || CurrentBars[1] < 1)
                    return;
    
                // Only trade during market hours (9:00 AM - 2:15 PM)
                bool market_open = ToTime(Time[0]) >= 90000 && ToTime(Time[0]) <= 141500;
    
                // TICK value comes from the secondary data series (index 1)
                double tickValue = Closes[1][0]; // Secondary series
    
                // Trade only when market is open
                if (market_open)
                {
                    // Go long when TICK crosses below the threshold
                    if (tickValue < -tickThreshold && Position.MarketPosition == MarketPosition.Flat)
                    {
                        EnterLong();
                    }
        
                    // Go short when TICK crosses above the threshold
                    if (tickValue > tickThreshold && Position.MarketPosition == MarketPosition.Flat)
                    {
                        EnterShort();
                    }
                }
            }
        }
    }
    
    ​
    I dont get why this isnt working but basically I want to go long when tick crosses below 700 and vice versa. I also want to skip the first 30 minutes.

    #2
    Hello ExtremelyRough,

    Do you currently have a subscription for the TICK instrument and can you open a normal chart to view bars?

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello ExtremelyRough,

      Do you currently have a subscription for the TICK instrument and can you open a normal chart to view bars?
      Yes I can see the tick chart just fine.

      Click image for larger version

Name:	image.png
Views:	127
Size:	37.3 KB
ID:	1319449

      Comment


        #4
        Hello ExtremelyRough,

        I would suggest trying a Print to see if the strategy is processing bars for that series, please try adding the following to the beginning of OnBarUpdate:

        if(BarsInProgress == 1)
        Print(CurrentBar);

        If the secondary series is added and processing you should see incrementing prints in the output window. If that is the case that means you would need to use a print to check the conditions you made.

        Print(market_open);
        if (market_open)
        {

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello ExtremelyRough,

          I would suggest trying a Print to see if the strategy is processing bars for that series, please try adding the following to the beginning of OnBarUpdate:

          if(BarsInProgress == 1)
          Print(CurrentBar);

          If the secondary series is added and processing you should see incrementing prints in the output window. If that is the case that means you would need to use a print to check the conditions you made.

          Print(market_open);
          if (market_open)
          {
          I think ive found the issue. It only enters if TICK closes above or below +-700. Is there a way to make this more responsive and enter at the cross above or below?

          Comment


            #6
            Hello ExtremelyRough,

            You could change the 700 value to something more appropriate or also change the conditions. If you wanted to use crossing conditions you can see an example of how to do that here:



            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            111 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            59 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            38 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            41 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            78 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X