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 bill2023, Yesterday, 08:51 AM
          8 responses
          43 views
          0 likes
          Last Post bill2023  
          Started by yertle, Today, 08:38 AM
          6 responses
          25 views
          0 likes
          Last Post ryjoga
          by ryjoga
           
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          24 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          16 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          46 views
          0 likes
          Last Post jeronymite  
          Working...
          X