Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

is it right to use Count to do something within certain amount of time?

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

    is it right to use Count to do something within certain amount of time?

    Hi,

    I'm trying to code a strategy that a status is valid for certain amount of bars being updated.

    Code:
    protected override void OnBarUpdate()
    
    private bool canEnterLong;
    private int enterLongTiming;
    
    if (...some condition)
                {
                    canEnterLong = true;
                    enterLongTiming = Count;
                }
    
    if (Count - enterLongTiming >= 30)
                {
                    canEnterLong = false;
                }
    My code tries to turn on canEnterLong status to be true only for 30 bars (if on 1 minute chart, it's 30 mins), and turn it off after 30 bars. Am I using Count correctly? I'm assuming that Count is the updated total number of bars on primary series, when the bar is live updating. Count number is plus 1 when current bar is closed. When canEnterLong is true, enterLongTiming records a count number. Then when current Count exceeds 30 more bars, it means 30 bars have passed and canEnterLong is false.

    Thank you very much! Please advise if I'm using it right.

    #2
    Hi HiddenPhilosopher,
    What you refer to as "Count" is basically "CurrentBar".

    I recently made a post covering the same topic ("valid until"), basically using the same technique.
    hi fellow traders. i am trying to work out how to highlight a certain range bar wicks. and use them in a type of condition. i have attached a drawing to hopeful show what I am trying to achieve any assistance will be greatly appreciated regards simon range bars.png

    You might consider to add Prints to your code with the number of CurrentBar when you set your bool canEnterLong to true and again when reverting back to false.
    If you open an OutputWindow before running the strategy in StrategyAnalyzer, you can see if the "timer" logic works fine.
    NT-Roland

    Comment


      #3
      Originally posted by NT-Roland View Post
      Hi HiddenPhilosopher,
      What you refer to as "Count" is basically "CurrentBar".
      https://ninjatrader.com/support/help...currentbar.htm
      I recently made a post covering the same topic ("valid until"), basically using the same technique.
      https://ninjatrader.com/support/foru...ull-range-bars
      You might consider to add Prints to your code with the number of CurrentBar when you set your bool canEnterLong to true and again when reverting back to false.
      If you open an OutputWindow before running the strategy in StrategyAnalyzer, you can see if the "timer" logic works fine.
      NT-Roland
      Hi Roland - If I'm understanding it right, my code should be:
      Code:
      protected override void OnBarUpdate()  
      private bool canEnterLong;
      private int enterLongTiming;  
      if (...some condition)
                  {
                      canEnterLong = true;
                      enterLongTiming = CurrentBar;
                  }
      if (CurrentBar - enterLongTiming >= 30)
                  {                
                      canEnterLong = false;
                  }
      Is this correct?
      Also, what does Count do every time a bar updates? I think I misunderstood the help guide.
      Last edited by HiddenPhilosopher; 05-31-2020, 08:59 AM.

      Comment


        #4
        Hi HiddenPhilosopher, thanks for posting.

        CurrentBar counts up from the beginning bar of the chart (the left most bar is CurrentBar == 0). There is no Count property in the default indicator/strategy class, so that must be some custom variable.

        Please let me know if I can assist any further.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by andrewtrades, Today, 04:57 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        3 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        6 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X