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 GussJ, 03-04-2020, 03:11 PM
            16 responses
            3,281 views
            0 likes
            Last Post Leafcutter  
            Started by WHICKED, Today, 12:45 PM
            2 responses
            19 views
            0 likes
            Last Post WHICKED
            by WHICKED
             
            Started by Tim-c, Today, 02:10 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Taddypole, Today, 02:47 PM
            0 responses
            5 views
            0 likes
            Last Post Taddypole  
            Started by chbruno, 04-24-2024, 04:10 PM
            4 responses
            53 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Working...
            X