• 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

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 7robert, Today, 08:11 AM
            3 responses
            47 views
            0 likes
            Last Post NinjaTrader_Kate  
            Started by madmen, Yesterday, 09:18 PM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Started by stoner, Today, 09:01 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by Conall, Yesterday, 04:00 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by neoikon, Today, 08:43 AM
            2 responses
            13 views
            0 likes
            Last Post neoikon
            by neoikon
             
            Working...
            X