Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Referencing an exposed variable on FirstTickOfBar in a real time strategy

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

    Referencing an exposed variable on FirstTickOfBar in a real time strategy

    Hello!
    I want to reference an exposed variable (not a DataSeries) of a custom indicator in a real time strategy (COBC = false) at the close of each bar (FirstTickOfBar). Since it's a variable and not a DataSeries that is referenced, the indicator output can't be shifted with a bars ago index of [1]. How would I correctly reference this variable in the strategy to return an output value for the close of each bar? Should the current or the previous variable value be exposed?

    When a strategy calls an indicator at FirstTickOfBar, will the referenced indicator output be returned before or after the OnBarUpdate() method of the indicator is processed for that first tick? Does the Update() method in the "getter" affect this behaviour somehow?

    Best Regards,
    Poseidon


    Indicator:
    Code:
            // Variables
            private double exposedVariable;
            
            protected override void OnBarUpdate()
            {
                exposedVariable = xyz;
            }
            
            //Properties
            [Browsable(false)]
            [XmlIgnore()]
            public double ExposedVariable
            {
                get { 
                         Update();         // Ensure our exposed variable is up-to-date.
                         return exposedVariable;
                      }
            }
    Strategy:

    Code:
           protected override void Initialize()
            {
                CalculateOnBarClose    = false;
            }
            
            protected override void OnBarUpdate()
            {
                if (FirstTickOfBar && Position.MarketPosition == MarketPosition.Flat)
                {
                    if ( myIndicator.exposedVariable > Close[0] );
                    EnterLong("long entry");
                }
            }

    #2
    Poseidon, including Update() in the 'getter' would ensure the variable is updated before the OnBarUpdate() is processed - you would want to expose the previous value then to get the value of the last closed bar.

    Comment


      #3
      Thanks for your prompt reply. Do I understand your answer correctly if I asign the expose variable as in this code example...

      Code:
              protected override void OnBarUpdate()
              {
                     xyz = (do some calculations here); // Calculate the current variable value
      
                    exposedVariable = xyz;    // Asign the value to the exposed variable
              }
      ....but NOT as in this example?
      Code:
              protected override void OnBarUpdate()
              {
                  exposedVariable = xyz;    // Asign the [COLOR=Red]previous[/COLOR] variable value to the exposed varaible before we calculate the current value
             
                  xyz = (do some calculations here); // Calculate the current variable value
      
              }
      /Best Regards
      Poseidon

      Comment


        #4
        Poseidon, this will likely not work as it's all happening in one bar update call running on each tick. You could sequence the value updates for example via CurrentBar checks, or it's likely easier altogether to work with a series here that you .Set as needed with your values.

        Comment


          #5
          Do you think that neither of my previous two code examples will work, although the strategy only calls the indicator at FirstTickOfBar? If the first example doesn't work, shouldn't the secons example be fine? (The reason for my inital question is that I want to expose a custom struct from an indicator. That's why I don't use a Series variable.)
          Last edited by poseidon_sthlm; 04-20-2011, 08:12 AM.

          Comment


            #6
            Poseidon, my speculation here without a test scenario would be that it would not matter, as both are happening in the same bar update - is your struct value / trigger changing that frequently? To be sure you would need print the exposed value at the time you're trying to work with it in your strategy and then ensure it's matching what you would need for correct signals taking place.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            580 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            336 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            554 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            552 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X