Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy using different calculation than indicator OnBarUpdate

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

    Strategy using different calculation than indicator OnBarUpdate

    Hi,

    I developped an inidactor that uses OnBarClose and use it in a strategy that use OnPriceChange to have a more precise entry. Ive been testing it on the playback function and the problem seems that the indicator does not update once the strategy is enabled. If a run a separate instance of the indicator by it's own, it works as intended.

    Im guessing that the problem is with the calculation methods being different for the strategy and the indicator. Ive read the documentation and it's stated that the strategy forces it's calculation method upon the indicator.

    Embedded scripts within a calling parent script should not use a different Calculate property since it is already utilizing the Calculate property of the parent script (i.e. the strategy your indicator is called from).
    How can I solve this?

    Thanks,

    #2
    Hello morkut,

    The best way forward would be to change the indicator to run OnPriceChange like the strategy and then confirm your logic works by applying just the indicator before trying to use it in the strategy. The strategy will force the indicator to work OnPriceChange which will change how its logic works. There is not a way to avoid that so you would have to program the indicator to support OnPriceChange in this use case. If you want to simulate OnBarClose logic in the indicator I would suggest looking at how the BuySellVolume indicator handles that by using the CurrentBar from OnBarUpdate. That lets you catch the first tick of the bar to update any plots to a final value and also run the logic you want OnBarClose.



    Comment


      #3
      Hi Jesse,

      Thanks for the response, it worked. Will have it in mind for the next ones. Have a good day.

      Comment


        #4
        Hi again,

        As I said in previous post, changing the indicator to OnPriceChange from OnBarClose using the same method as described as worked. But I ve made some changes to the strategy and now the indicator is back to not updating. I can't revert the changes Ive made. Ive checked and both, the strategy and the indicator, have a calculation method set to OnPriceChange.

        I have added some prints to the OnBarUpdate in the indicator and once the indicator has changed to Realtime Status from the strategy, the prints are no longer showing. What could be happening?

        Comment


          #5
          Hello morkut,

          As only you know what you changed you would have to determine what is wrong by by using prints to verify how your logic is working in both the indicator and strategy. The first step is going to be to apply the indicator and make sure it works by itself while using OnPriceChange. After confirming that works you can call it from the strategy and verify you can retrieve its values from the strategy. To have the indicator calculate you need to call it from the strategies OnBarUpdate so if you have any conditions that may prevent the indicator from getting called that would be the best starting point.

          Comment


            #6
            Hi,

            Ive managed to overcome the problem with the use of the indicator.Update() method but I dont know if this how it should be done. I have called AddChartIndicator right at State == State.DataLoaded if loop.

            Is there another way?

            Comment


              #7
              Hello morkut,

              As mentioned you need to call the indicator from the strategies OnBarUpdate for it to calculate. If you are just using AddChartIndicator to show the indicator but not getting a value from the indicator you can use the Update() method to make sure the indicator is getting called. Normally when you call an indicator from a strategy the purpose is to retrieve a value so you would be accessing a Plot from the strategies OnBarUpdate method which will make it update.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              52 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              130 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              70 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              44 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              49 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X