• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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".
    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

    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 soulfx, Today, 03:57 AM
        0 responses
        3 views
        0 likes
        Last Post soulfx
        by soulfx
         
        Started by digibob, Today, 03:45 AM
        0 responses
        5 views
        0 likes
        Last Post digibob
        by digibob
         
        Started by Matts7, Today, 12:56 AM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_Marco  
        Started by barrybrice, Yesterday, 08:51 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Marco  
        Started by hayleeabb, Today, 12:30 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChrisSch  
        Working...
        X