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 benmarkal, Yesterday, 12:52 PM
            3 responses
            23 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by helpwanted, Today, 03:06 AM
            1 response
            19 views
            0 likes
            Last Post sarafuenonly123  
            Started by Brevo, Today, 01:45 AM
            0 responses
            11 views
            0 likes
            Last Post Brevo
            by Brevo
             
            Started by pvincent, 06-23-2022, 12:53 PM
            14 responses
            244 views
            0 likes
            Last Post Nyman
            by Nyman
             
            Started by TraderG23, 12-08-2023, 07:56 AM
            9 responses
            388 views
            1 like
            Last Post Gavini
            by Gavini
             
            Working...
            X