Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Enter a trade after a variable was triggered [?] (bars ago)

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

    Enter a trade after a variable was triggered [?] (bars ago)

    Hello Everyone,


    I'm coding in NinjaScript, however, I'm new to coding. I have a bool variable for a Buy Entry on the 25 tick chart - I'll refer to as "A". I also have another set of conditions of when I want to enter a Buy on the 50 tick chart - I'll refer to as "B". When my "B" Conditions are met for a Buy, I only want to enter a Buy if "A" was also triggered within 3 or 4 or 5 bars ago. But, I'm not sure how to reference a bool variable having been triggered as "true" for a specific # of bars ago. I hope that makes sense.

    I think this is simple to code, but I can't figure out how to code it. Sigh. How do I reference a bool variable that was triggered as true 3 or 4 or 5 bars ago? Any guidance anyone can provide is greatly appreciated!



    #2
    Hello Ttrade12,

    The way to do this would be to use a counter to reset the variable after X bars. For example, condition A becomes true and toggles a variable to true. In another condition, check if the variable is true and increment a counter for each bar where it is true. In a third condition, check if the variable is true and greater than the target number. If so, set it to false. You can then use that variable's value in any other condition. If it's true, it would be within the range of bars you set.

    Comment


      #3
      Thanks, Jesse! I'll try that.

      Comment


        #4
        I'm looking for examples for the 2nd condition - using a counter to reset the variable. I see examples of using a custom series in the Strategy Builder. I'm not using SB. I'm coding with NinjaScript. So, do I still need to use a custom series for this 2nd condition?

        Comment


          #5
          Hello Ttrade12,

          You can just make an int variable and increment it.

          Code:
          private int counter; 
          protected override void OnBarUpdate()
          {
              if(someCondition)
             {   
                  counter++;
              }
          }

          Comment


            #6
            Ok, thanks. I'll work on this.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            87 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            132 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            68 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by cmoran13, 04-16-2026, 01:02 PM
            0 responses
            118 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            67 views
            0 likes
            Last Post PaulMohn  
            Working...
            X