Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsArray2 issue

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

    BarsArray2 issue

    I am creating a Strategy with 2 time frames. Condition 1 works fine as it is referencing the BarsArray[2].

    Condition 2 is not working properly when I reference BarsArray[1]. If I delete the following part of the script:
    (this.BarsSinceEntry() > 40 || this.BarsSinceEntry() == -1 ) it will then work fine.

    How do I include the BarsSinceEntry script so that the 2nd Condition works properly?


    // Condition set 1

    if ((EMA(14 [0]>RMV(BarsArray[2]).Sup[1] ) && (CrossAbove(EMA(14), EMA(62), 1)))

    {EnterLong(DefaultQuantity, "EnterLong");
    }

    // Condition set 2
    if ((TSI((BarsArray[1]),29, 40)[1] > -30 && (this.BarsSinceEntry() > 40 || this.BarsSinceEntry() == -1 ) && (CrossAbove(EMA(6), FedIndicator().P1, 1))))

    {EnterLong(DefaultQuantity, "EnterLong");}


    Thank you,

    #2
    Hello Scarlett09,

    Could you clarify what you are looking for it to do?

    BarsSinceEntry() is going to return a the Primary Series how many bars since it last entered. Are you wanting to have it scale into your order?

    Note that it is always a good idea to use Print() statements to verify values are what you expect as well - Debugging your NinjaScript code.

    You may also want for strategies add TraceOrders = true to your Initialize() method to make sure that your orders are being called properly and you can then view valuable output related to strategy submitted orders through Tools > Output window - TraceOrders

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Hi JC,

      There are 2 time-frames in use here.

      They are:
      1) 2 minute time-frame which the TSI indicator uses
      2) 60 minute time-frame which the RMV indicator uses

      Under Initialize() I've added the time-frames in that order

      The 1st Condition is straight forward, simple crossover given that the EMA(14) is above the RMV line then go Long

      In the 2nd Condition I am trying to prevent over-trading. Thus with the 2 minute based Indicator I don't want a Signal for 80 minutes after the last Signal which is why I've added the (this.BarsSinceEntry() > 40

      If I include the (this.BarsSinceEntry() > 40 then No signals appear. If I delete the (this.BarsSinceEntry() > 40 then the Strategy works fine with the exception of over-trading.

      Thus I want to include the (this.BarsSinceEntry() > 40 so I the Strategy is not over-trading.

      Thanks,

      Comment


        #4
        Hello Scarlett09,

        this.BarsSinceEntry() will only be true when your first signal has enter a position and there has been 40 bars have pasted.

        Could you clarify if that is what you would like your strategy to do?
        JCNinjaTrader Customer Service

        Comment


          #5
          that is correct, I want 40 bars to pass before a signal is provided again

          Comment


            #6
            Hello Scarlett09,

            Thanks for the clarification on this.

            What is your Primary Time frame that you are apply your strategy to? 1 Minute, 60 Miinute?

            Also, have you tried to using the Print() method to see if your Strategy is getting 40 bars since the entry to make the condition true?

            Example:
            Code:
            // Condition set 1
            if (...)
            {
            }
            
            Print("BarsSinceEntry: "+this.BarsSinceEntry() );
            
            // Condition set 2
            if (...)
            This will display the value of the BarsSinceEntry inside of the Tools -> Output window so we can easily see if the value is getting to 40 or if it is being reset by getting another entry.

            Happy to be of further assistance.
            JCNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            648 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            573 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            575 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X