Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator Calculate Number of shares

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

    Indicator Calculate Number of shares

    Hello

    I would like to create an indicator that will calculate the number of shares (positionSize) based on a dollar amount specified by user input variable (CashValue).


    PositionSize = CashValue / close[0]

    The purpose for this...

    There is no way to define position size based on a specific cash value in the strategy wizard.
    I would like to be able to use the value created from the indicator to define the number of shares in my strategy.

    I am able to unlock the strategy and hard code this but then no long have access to the strategy builder to work with.

    I have limited coding experience and have tried to create and indicator using the wizard and altering an existing indicator with no success.

    Is this possible?

    Any help would be appreciated.



    #2
    Hi sdauteuil, thanks for your note.

    I'm not aware of any way to calculate this within the builder, this will need to be done by writing code in the NinjScript editor. You can use the Account object to get account info e.g.

    if (Account.Get(AccountItem.CashValue, Currency.UsDollar) > 25000)
    {
    //example of checking CashValue
    }

    If I can assist any further please let me know.

    Comment


      #3
      I was able to change the logic in the ATR indicator that comes with NT. The new oscillator shows the number of shares that equal a $10,000 position.

      I was then able to set a variable in the strategy builder to equal the value of the new indicator I created. I used that variable for the number of shares and that works fine in the strategy.

      Unfortunately I have not been able to figure out how to create this simple indicator from scratch. I just changed the logic using the same variables and plot already defined in the ATR indicator.

      I tried using the wizard and adding my logic but couldn't get it to return a plot (oscillator) on the chart and was not able to reference the value in the strategy builder.

      Do you know of any tutorials on creating indicators?

      This will work for now but I would prefer cleaner code... appropriately named variables etc

      Thank you

      Comment


        #4
        Hi sdauteuil, thanks for your reply.

        The VOL or SMA indicators are probably the most simple examples in the platform by default, we also have the reference samples below:



        If you have any questions on this material please let me know.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        670 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        379 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        111 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        575 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        582 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X