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

Position.AvgPrice

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

    Position.AvgPrice

    I am trying to exit my position with the entry price value minus (some value)

    I am testing with this code but I cannot get it to work.


    if (Low[0] <= Position.AvgPrice - 5));
    {
    ExitLong(
    "Stopped Out", "");
    }

    When I print Position.AvgPrice to the output window the value is 0

    When I print Position.AvgPrice - 5 to the output window I get -5

    Thanks for any help

    #2
    I used the wizard to create the code copied and pasted it.

    I now get the proper values in the output window but it is still not triggering an exit

    if (Low[0] < Position.AvgPrice - 5)
    {
    ExitLong(
    "Exit Long Pos", "");
    }

    Comment


      #3
      delta20, sounds like you're not in a position for the strategy when you're trying to trigger it? Please add a check in for not being flat with your Position.MarketPosition
      BertrandNinjaTrader Customer Service

      Comment


        #4
        I am still having the same issue.

        I know I am in a position because it goes all the way to exit on close which is past the
        Position.AvgPrice-5

        Is this code correct for filtering?
        //Check if open position
        if (Position.AvgPrice == Null || Position.AvgPrice = 0)
        return;


        // Condition set 3
        if (Low[0] < Postion.AvgPrice - 5);
        {
        ExitLong(
        "", "Exit Open Price");
        }

        Thanks

        Comment


          #5
          Originally posted by delta20 View Post
          I am still having the same issue.

          I know I am in a position because it goes all the way to exit on close which is past the
          Position.AvgPrice-5

          Is this code correct for filtering?
          //Check if open position
          if (Position.AvgPrice == Null || Position.AvgPrice = 0)
          return;


          // Condition set 3
          if (Low[0] < Postion.AvgPrice - 5);
          {
          ExitLong(
          "", "Exit Open Price");
          }

          Thanks
          Then you need to check if your condition is actually ever true.
          Does price ever retrace enough so that Low[0] is below the average entry price minus 5?
          Is COBC true or false?
          On what instrument are you running the code?
          On what timeframe?

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Vietanhnguyen2hotmailcom, Yesterday, 10:29 AM
          4 responses
          23 views
          0 likes
          Last Post Vietanhnguyen2hotmailcom  
          Started by PhillT, 04-19-2024, 02:16 PM
          4 responses
          35 views
          0 likes
          Last Post PhillT
          by PhillT
           
          Started by ageeholdings, 05-01-2024, 05:22 AM
          5 responses
          37 views
          0 likes
          Last Post ageeholdings  
          Started by reynoldsn, Today, 02:34 PM
          0 responses
          13 views
          0 likes
          Last Post reynoldsn  
          Started by nightstalker, Today, 02:05 PM
          0 responses
          21 views
          0 likes
          Last Post nightstalker  
          Working...
          X