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

positions alert

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

    positions alert

    Hi, I am new to Ninjatrader script. I tried to set and indicator with an alert on position quantity bigger than an input value. But it doesnt compile due to:
    1) > is not a valid term
    2) a ; is missing.

    What is the reason? thanks

    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    // Condition set 1
    if (Position.Quantity) > Maxpositions;
    { Alert("myAlert", "Reached threshold", "Alert1.wav", 10, Color.Black, Color.Yellow);

    }

    #2
    Hello gimir,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    Change the condition from if (Position.Quantity) > Maxpositions; to if (Position.Quantity > Maxpositions).

    So encapsulate the condition in parenthesis. So the full code is as follows:
    Code:
    if (Position.Quantity > Maxpositions)
    { Alert("myAlert", "Reached threshold", "Alert1.wav", 10, Color.Black, Color.Yellow);
    
    }

    Comment


      #3
      Hi,
      thank you for the reply.

      I did what suggested but it doesnt compile due to an error on the if clause (line 46): it expects an 'object'. I commented the line on the script in order to export it and I attached the script to this post. Could you please help me ?

      thanks
      Attached Files

      Comment


        #4
        Hello,

        Thank you for providing the script.

        The reason you are receiving this error is that "Position" can only be used in a strategy where this is being used in an indicator.

        The code you have now would work if used in a strategy instead of an indicator.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you.

          Is there something similar that I can use in an indicator to check the current position quantity and order?

          thanks

          Comment


            #6
            Hello,

            Unfortunately there is not when using an indicator, Indicators are really meant for visual price calculations and have not been created to use Strategy methods.

            When using a strategy this is available but only for the strategies instance, any positions or quantities reported would only be for the strategy the code is running in, it would not detect any other strategy positions on other instruments.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by geotrades1, Today, 10:02 AM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by ender_wiggum, Today, 09:50 AM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by rajendrasubedi2023, Today, 09:50 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by bmartz, Today, 09:30 AM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by geddyisodin, Today, 05:20 AM
            3 responses
            26 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X