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

Selecting Indicator for DivergenceSpotter and Calling it from the strategy

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

    Selecting Indicator for DivergenceSpotter and Calling it from the strategy

    Hey,

    I want to call this Divergence Spotter indicator (https://ninjatraderecosystem.com/use...e-spotter-nt8/) from a strategy AND SELECT another indicator to base divergence on, instead of MACD.

    How can I modify indicator code, so it would let me call it from the strategy and select, let's say, RSI (instead of MACD), because now, when I go to indicator's properties, it only gives me option to call as: DivergenceSpotterV2(Input) (where input is close price as default).

    And I want it to become DivergenceSpotterV2(Indicator, Input), so I could select indicator of my choice to base the divergence on.

    #2
    Hello UltraNIX,

    Thanks for your post.

    We can't just use an indicator as input because each indicator will be different, with different constructors, so different code paths must be taken to properly instantiate the indicator.

    A way to accomplish your goal would be to create an enum of indicators that would be supported by your strategy, use the enum as the input and have your strategy take different code paths to instantiate different indicators and use different indicators based on the enum's selection.

    We have an example that can demonstrate much of this process/functionality, which can be found below.



    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Maybe I misguided you with my explanation. If you look into the code of the DivergenceSpotter indicator, it already has the enum with 14 indicators to select from:

      Code:
       public enum DivergenceSpotter_IndicatorType
      { MACD=1,
      TRIX=2,
      CCI=3,
      BOP=4,
      CMO=5,
      ChaikinMoneyFlow=6,
      Momentum=7,
      MFI=8,
      RSI=9,
      ROC=10,
      StochSlowD=11,
      StochFastD=12,
      StochFastK=13,
      StochRSI=14
      }
      So that's what I want. Default indicator, used for divergence, is MACD. I want to be able to change to any of the indicator that is included in this enum. How? My guess is that indicator code needs adjustments. Your help would be appreciated.

      Comment


        #4
        Hello UltraNIX,

        The default would be set in the indicator under OnStateChange under State == State.SetDefaults.

        DivergenceSpotter has this line of code:

        indicatorType = DivergenceSpotter_IndicatorType.MACD; // Default setting for IndicatorType

        If you press the backspace key from "DivergenceSpotter_IndicatorType.MACD" to "DivergenceSpotter_IndicatorType" and then enter another period (".") then you can use Intellisense/Intelliprompt to select another item from that enum. You can also reference the enum directly and type in an item from the enum.

        Using Intelliprompt in the NinjaScript Editor - https://ninjatrader.com/support/help...elliprompt.htm
        JimNinjaTrader Customer Service

        Comment


          #5
          Can you provide a simple code example? I am still confused, even though I checked your link.

          Comment


            #6
            Hello UltraNIX,

            Please see the animated GIF below that shows Intelliprompt becoming visible after adding a period after "DivergenceSpotter_IndicatorType"

            I then use the cursor arrows on my keyboard to select another item in the enum.

            If the thumbnail is too small, you can right click on the image and select "Open image in new tab" or similar menu item to view the original image

            Click image for larger version  Name:	2021-10-08_13-08-07.gif Views:	0 Size:	193.3 KB ID:	1174251
            JimNinjaTrader Customer Service

            Comment


              #7
              I understand that, but my idea is to call indicator from the strategy, without any manual interference. So I would like to switch variables from the enum via code in the strategy, not by hand in the indicator.

              Comment


                #8
                Hello UltraNIX,

                I see, thanks for clarifying.

                Yes, the indicator would need to be modified so the [NinjaScriptProperty] attribute is added to the public properties of indicator, so the indicator constructor is created that accepts the DivergenceSpotter_IndicatorType input.

                Then you would create a public property in the strategy of type DivergenceSpotter_IndicatorType and use that property to instantiate the indicator.

                I created an example that demonstrates for your review.
                Attached Files
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Thanks, that's exactly what I needed!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by 21laienoch, Today, 07:25 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post 21laienoch  
                  Started by burtoninlondon, 04-28-2024, 12:38 AM
                  1 response
                  16 views
                  0 likes
                  Last Post burtoninlondon  
                  Started by MacDad, 02-25-2024, 11:48 PM
                  8 responses
                  175 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by alancurry, Today, 06:53 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post alancurry  
                  Started by Juanhuisman, Today, 06:51 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post Juanhuisman  
                  Working...
                  X