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

Link between strategy and indicator

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

    Link between strategy and indicator

    Generally speaking, what goes on behind the scenes when you use an indicator in a strategy? Take, for instance, the very basic OpenIsClose indicator from the tutorial:

    Code:
    [B]INDICATOR:[/B]
    OnBarUpdate()
    {
         Plot0.Set(Open[0] == Close[0] ? 1:0);
    }
    Let's say I don't have that indicator on a chart or active anywhere, but then use it in a strategy:
    Code:
    [B]STRATEGY:[/B]
    OnBarUpdate()
    {
         If OpenIsClose()[0] == 1
              //other code
    }
    What is going on? How does my indicator's code, which deals with a plot that doesn't even exist in the strategy, end up giving my strategy a useful value via the "OpenIsClose()[0]" statement?

    #2
    Hello YD777,

    Thank you for writing in.

    OpenIsClose() is a method call for the indicator OpenIsClose.

    Simply, when calling an indicator from a strategy with its method call, the indicator will do its calculations based on the close prices, and then return the result of that calculation. The indexer, [0], refers to a barsAgo value. A value of 0 would be the indicator value for the current bar your script is evaluating. A value of 1 would be the indicator value for the previous bar. So on and so forth.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      OK. So behind the scenes, an indicator object is created somewhere? And that same object is used for the entire run of the strategy?

      Comment


        #4
        Hello YD777,

        Thanks for your reply.

        Yes, that is correct.

        You may want to review this thread for further understanding: http://ninjatrader.com/support/forum...rs+efficiently
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          That thread is very useful, thanks for the link. Particularly, that link posted in the thread was the exact kind of think I was looking for:


          I would suggest that this type of information be included in the standard help files.

          Comment


            #6
            Hello YD777,

            Thanks for reply and suggestion.
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by algospoke, Yesterday, 06:40 PM
            2 responses
            18 views
            0 likes
            Last Post algospoke  
            Started by ghoul, Today, 06:02 PM
            3 responses
            14 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            44 views
            0 likes
            Last Post jeronymite  
            Started by Barry Milan, Yesterday, 10:35 PM
            7 responses
            20 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by AttiM, 02-14-2024, 05:20 PM
            10 responses
            180 views
            0 likes
            Last Post jeronymite  
            Working...
            X