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 NullPointStrategies, Today, 05:17 AM
            0 responses
            46 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            126 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            66 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X