Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceEntry

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

    BarsSinceEntry

    I am using BarsSinceEntry within a strategy but when testing using market replay no trades are being fired.

    Syntax is :

    if(BarsSinceEntry("LongEntryCrosses")>1)
    {
    //enter long trade
    LongOrderCrosses = EnterLong(LotSize,"LongEntryCrosses");

    }

    Is there a reason for this?

    If I take out the test on some bars the strategy is attempting to place a trade multiple times (100s) and this is then being cancelled due to logic I think within the strategy

    #2
    mballagan,

    You cannot use that condition like that because for the very first trade there was no BarsSinceEntry() > 1. You will need to code a set for the first trade and a separate set for subsequent trades you wish to use the BarsSinceEntry logic with.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      BarsSinceEntry

      Ok thanks so I have used the following code:

      bool entertradecondition = false;


      Trade firstTrade = Performance.AllTrades[
      0];

      if(firstTrade == null)
      {
      entertradecondition =
      true;
      }
      else
      {
      entertradecondition = BarsSinceEntry()>
      1;
      }

      if(entertradecondition)
      {
      //enter trade

      }

      Comment


        #4
        mballagan,

        You can try it.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          BarsSinceEntry

          It doesnt seem to work. I have more than one time series in the strategy although only executing trades on the primary series.

          If using the syntax:

          Trade firstTrade = Performance.AllTrades[0];

          Is there a way I can retrieve the label the trade was initialised under?

          For example if EnterLong("LongOrder1") was used the label is LongOrder1.

          Comment


            #6


            You will want to go to the individual IExecutions and then grab the Name properties from them.
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by charlesugo_1, 05-26-2026, 05:03 PM
            0 responses
            60 views
            0 likes
            Last Post charlesugo_1  
            Started by DannyP96, 05-18-2026, 02:38 PM
            1 response
            147 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            161 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 05-10-2026, 08:12 PM
            0 responses
            97 views
            0 likes
            Last Post CarlTrading  
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            284 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Working...
            X