Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MultiTF Start Issues wih BarsSince*** on Lower TF

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

    MultiTF Start Issues wih BarsSince*** on Lower TF

    For background: I am a novice and have programmed strategies using advance handling, and I understand referencing other time frames(TF) - I thought. But, I have been at this for 18 hours and cannot get it.

    1: I want my logic looking at 5M HA bars, but as soon as the current 5M bar closes {so is this [0]?} I want it to test the logic and send the order to the smaller (1Tick) TF, not wait for the next 5M bar to submit if you know what I mean.

    2: I also want it to monitor the open position on the smaller TF and close it if XYZ, even if that 5M bar is not closed.

    3: I do not want it taking more than 1 trade per 5M HA bar.

    So I tried all kinds of goofy stuff, but the most recent problem is how do I place an order on the 1-Tick, but reference the 5M using BarsSinceLast****()? Because it will only reference the series the order was on right? So if I place orders on the 1-tick (Series 1) to get immediate fills, and only want 1 trade per the 5Min HA(Main Chart Series 0) then it doesn't catch it?

    I also tried pulling the 5M HA into the script hard coded but could figure out how to store that into a BarsArray. AddHeikenAshi(?what goes here?, 5)...

    Here is an example. This is just where I was at when I gave up, I have not added complete Advanced Order Handling yet:

    HTML Code:
    //ADDING 1-TICK FOR ORDERS AND MANAGEMENT
    
             else if (State == State.Configure)
             {
             AddDataSeries(BarsPeriodType.Tick, 1);
             }
    
    
            ​protected override void OnBarUpdate()
            {
    
                //LOGIC ON 5M HA​, the main chart the strat is on
                if (BarsInProgress == 0)
                {
                    if (CurrentBars[0] < 2)
                        return;
                     // Set 1 Long Entry
                    if ((Position.MarketPosition == MarketPosition.Flat)
                       && (ENTRY LOGIC)
                       && ((BarsSinceEntryExecution(1,"Long",1) >= 1 ) || (BarsSinceEntryExecution(1,"",1) == -1 )))  //HOW CAN I MAKE IT REF THE 5M WHEN ORDER WAS ON SERIES 1?
                    {
                        EnterLong(1, Convert.ToInt32(DefaultQuantity), "Long");
                    }
                }
    //1-TICK TF FOR MONITORING
                if (BarsInProgress == 1)
                {
                    if (CurrentBars[1] < 50)
                        return;
                    //Set 3 Long Exit
                    if ((Position.MarketPosition == MarketPosition.Long)
                        && (EXIT LOGIC))
                        {
                            ExitLong(1, Convert.ToInt32(DefaultQuantity), "Out", "Long");
                        }
                }​

    I have been up and down using varibales to try and set whether a trade was taken on the 5-min bar, but nothing I have tried has worked.

    Hopefully someone can point out something simple i am missing. If bringing in hard-coded HA 5M time-frame works better I would do that, but have not been able to make it work. So if you could answer how to hard-code a 5M HA data series as a bonus that would be awesome and teach me a lot. thank you.

    #2
    Hello HaveGunsWillTravel,

    Thanks for your post.

    You mention that you "cannot get it working" but I do not understand exactly what is not working in the script. Please provide a brief description of what exactly is not working so I may accurately assist.

    I see you are submitting the order to the 1-Tick series and you are exiting on the 1-Tick series so the Entry order would exit when the logic to do so is reached on that secondary series. I see you are using BarsSinceEntryExecution() for your entry order but since the entry order is submitted to the 1-Tick series, this would check if 1 bar has passed on the 1-Tick series since the entry order was made and you would not be able to use this to check if 1 5-Minute bar has passed since the entry was made since the entry is submitted on the 1-Tick series.

    We have this reference sample linked below demonstrating adding intrabar granularity in a script which you might find helpful.

    SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/helpGuides/nt8/backtesting_ninjascript_strate.htm

    Working with multi-instrument/multi-timeframe NinajScripts: https://ninjatrader.com/support/help...nts.htm​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Originally posted by NinjaTrader_BrandonH View Post
      Hello HaveGunsWillTravel,

      Thanks for your post.

      You mention that you "cannot get it working" but I do not understand exactly what is not working in the script. Please provide a brief description of what exactly is not working so I may accurately assist.
      Yes Sir, so I mean 1,2,3 referenced in the above. Specifically, it will take a trade, then close it when the conditions are met, but then take repeated trades and close again within that same 5M bar. (Because that 5M logic is true) So I get 1 good entry, a good close, then a few junk trades going off like a pin-ball table within the same 5M bar.

      I would like to prevent that.

      Originally posted by NinjaTrader_BrandonH View Post
      I see you are using BarsSinceEntryExecution() for your entry order but since the entry order is submitted to the 1-Tick series, this would check if 1 bar has passed on the 1-Tick series since the entry order was made and you would not be able to use this to check if 1 5-Minute bar has passed since the entry was made since the entry is submitted on the 1-Tick series.
      Right, so how could I reference the order being only 1 trade per 5M bar if it is placed in the tick series?

      I hope I have explained it enough. If not let me know and thank you for your help,on it!

      As a second bonus:

      Could you tell me how to invoke AddHeikenAhsi() 5M Data series I could reference in my script? I have trouble understanding the arguments.
      Last edited by HaveGunsWillTravel; 05-24-2023, 01:55 PM.

      Comment


        #4
        Hello HaveGunsWillTravel,

        Thanks for your notes.

        A bool variable would need to be used with your custom logic to control when trades are made by the script.

        You could use a bool variable and reset it to false on each 5-minute bar and check if the bool is false in your entry condition.

        Then, set it to true when you submit the entry order in your script.

        To reset the bool you on each 5-minute bar you could consider checking if IsFirstTickOfBar is true in BarsInProgress 0 and set the bool to false.

        IsFirstTickOfBar: https://ninjatrader.com/support/help...ttickofbar.htm
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Perfect, thank you!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, 03-13-2026, 05:17 AM
          0 responses
          86 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          151 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
          53 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          61 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X