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

Create simple indicator

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

    Create simple indicator

    Hello! I've got 2 indicators, I need to combine them in one, just indicator1/Indicator2 and calculate average value for "n" periods, "n" I set up by myself.

    P.S.: I'm not a professional programmer, it's better to explain me step by step.

    Thanks!

    #2
    Hello U0000999,

    To do that you would need to create a third indicator with a Plot.

    If you have not programmed NinjaScript before it would be difficult to explain step by step what to do for custom indicators, You can however use the strategy builder to gather the syntax needed for your custom indicators.
    1. from the control center go to New -> Strategy builder.
    2. Open the Conditions and actions page
    3. Click Add in the bottom actions section of the window
    4. Select Misc -> Print
    5. Hover the mouse over message and click Set
    6. Select Indicator -> Your custom indicator 1
    7. After adding the action repeat these steps again to add a second action of printing indicator 2.
    8. Click View code

    That will generate the basic variables for the indicators and their syntax in OnBarUpdate.

    You should see something similar to:

    Code:
    Print(myIndicator1);
    Print(myIndicaotr2);
    Leave the strategy open so you can copy code from the file as needed
    In a new NinjaScript editor window, right click the indicators folder and choose new indicator. Give the indicator a name and then on the Plots page add a plot.
    After generating the file you should see a similar structure to what the strategy has.

    From the strategy you will need to copy the variables for myIndicator1 and 2 into the indicator in the same location, it needs to look the same. You should also see some extra code related to the indicators in the OnStateChange override, that needs copied to the indicator as well.

    Finally in OnBarUpdate to divide the indicators and plot the result it would look like:

    Code:
    Value[0] = myIndicator1[0] / myIndicator2[0];
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Nicholewatkinsi, Yesterday, 10:53 PM
    0 responses
    6 views
    0 likes
    Last Post Nicholewatkinsi  
    Started by dward123, 01-02-2024, 09:59 PM
    4 responses
    175 views
    0 likes
    Last Post Lancer
    by Lancer
     
    Started by ETFVoyageur, Yesterday, 04:00 PM
    2 responses
    19 views
    0 likes
    Last Post ETFVoyageur  
    Started by AaronKTradingForum, Yesterday, 03:44 PM
    1 response
    14 views
    0 likes
    Last Post AaronKTradingForum  
    Started by Felix Reichert, 04-26-2024, 02:12 PM
    11 responses
    80 views
    0 likes
    Last Post Felix Reichert  
    Working...
    X