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

Min, Max will not work for exiting a position

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

    Min, Max will not work for exiting a position

    I'm trying to get ninjascript to exit a position if the last close is lower than the lowest low of the previous 10 bars. Or the last close is higher than the highest high of the previous 10 bars, for short positions.The code is:

    // Stop loss long
    if (Close[1] < MIN(Low, 10)[1])

    {
    ExitLong("Exit LONG", "Enter LONG");
    }


    // Stop loss short
    if (Close[1] > MAX(High, 10)[1])
    {
    ExitShort ("Exit SHORT", "Enter SHORT");
    }

    Min/Max works when I enter positions. Ex: && High[1] >= MAX(High, 10)[1])

    NinjaTrader doesn't show any mistakes in the code itself so why is it not working?

    #2
    Print out those values to the output window, and you will see the issue.

    Comment


      #3
      Originally posted by sledge View Post
      Print out those values to the output window, and you will see the issue.
      I'm really new to scripting as well as NT so could you please expand a little bit on what that means and how to do it. I saw some info in "Help" but it doesn't say what the output window is. Or rather I don't understand how it would help diagnose or solve this problem.
      Also, as far as I understand "Print" is always written as an action after a condition and never as a condition itself, right?

      Comment


        #4
        Hi Rdaoogle,

        Thank you for the post

        There is a forum post with the same common issue that has a explanation as to why you are running into a problem.
        http://www.ninjatrader.com/support/f...221#post210221

        Basically, you are referencing the same bar with the MIN[1]. Since Close can never be lower than Low or higher than High.

        An example alternative code -
        Code:
        if(Close[0] < MIN(Low,20)[1]) //Starts evaluating the 10-bar highest high starting at one bar prior to the close.
        Please let me know if I can be of further assistance
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Sorry, I am on my phone.

          In control center, menu tools, hclick output window.


          Then, look up c# Print statement.

          Put before your conditions some thing like:

          Print ("close[1]="+ Close[1] );

          then do that for your other comparison.

          you see the values and see why you never get in.



          Originally posted by rdaoogle View Post
          I'm really new to scripting as well as NT so could you please expand a little bit on what that means and how to do it. I saw some info in "Help" but it doesn't say what the output window is. Or rather I don't understand how it would help diagnose or solve this problem.
          Also, as far as I understand "Print" is always written as an action after a condition and never as a condition itself, right?

          Comment


            #6
            Thanks guys, that made it work
            Last edited by rdaoogle; 05-01-2013, 12:29 PM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by helpwanted, Today, 03:06 AM
            1 response
            12 views
            0 likes
            Last Post sarafuenonly123  
            Started by Brevo, Today, 01:45 AM
            0 responses
            9 views
            0 likes
            Last Post Brevo
            by Brevo
             
            Started by aussugardefender, Today, 01:07 AM
            0 responses
            5 views
            0 likes
            Last Post aussugardefender  
            Started by pvincent, 06-23-2022, 12:53 PM
            14 responses
            242 views
            0 likes
            Last Post Nyman
            by Nyman
             
            Started by TraderG23, 12-08-2023, 07:56 AM
            9 responses
            387 views
            1 like
            Last Post Gavini
            by Gavini
             
            Working...
            X