• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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);
    
    }
    Patrick H.NinjaTrader Customer Service

    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 chrismcdermut, Today, 01:46 PM
            3 responses
            16 views
            0 likes
            Last Post MojoJojo  
            Started by Bricolico, Today, 09:28 PM
            0 responses
            4 views
            0 likes
            Last Post Bricolico  
            Started by Tradwell385, Today, 08:51 PM
            0 responses
            6 views
            0 likes
            Last Post Tradwell385  
            Started by dvcpro4, Today, 07:08 PM
            0 responses
            18 views
            0 likes
            Last Post dvcpro4
            by dvcpro4
             
            Started by pennywise, Today, 06:40 PM
            0 responses
            8 views
            0 likes
            Last Post pennywise  
            Working...
            X