Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to access bars before position.avgprice

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

    how to access bars before position.avgprice

    hi i want to set my stoploss at low[1]

    low[1] = 1 bar before the position.avgprice

    right now i'm using low[1] as stoploss, but it seems that if the stoploss is not hit immediatly, and bars since entry are >0 then the low[1] price is not the low before avg.price..

    any idea?

    #2
    calhawk01, what exactly do you please by ' low[1] = 1 bar before the position.avgprice'?

    The Low of the bar before you entered with your position?

    If you just set it at Low[1] in OnBarUpdate dynamically, it will follow the swings as new Lows are defined by the bars after your entry.

    Comment


      #3
      Originally posted by calhawk01 View Post
      hi i want to set my stoploss at low[1]

      low[1] = 1 bar before the position.avgprice

      right now i'm using low[1] as stoploss, but it seems that if the stoploss is not hit immediatly, and bars since entry are >0 then the low[1] price is not the low before avg.price..

      any idea?
      Position.AvgPrice comes into existence as non-zero, only when the order is executed. That points to the solution: set the StopLoss in the OnExecution() event when the order state indicates that the order has been filled.

      Comment


        #4
        Originally posted by NinjaTrader_Bertrand View Post
        calhawk01, what exactly do you please by ' low[1] = 1 bar before the position.avgprice'?

        The Low of the bar before you entered with your position?

        If you just set it at Low[1] in OnBarUpdate dynamically, it will follow the swings as new Lows are defined by the bars after your entry.
        yes by low[1] i mean the low of the bar prior to position avg price.

        cant seem to figure out how to do thst

        Comment


          #5
          Originally posted by calhawk01 View Post
          yes by low[1] i mean the low of the bar prior to position avg price.

          cant seem to figure out how to do thst

          solution:

          Code:
          if(BarsSinceEntry("Entry1")==0) SetStopLoss(CalculationMode.Price, Low[1]);

          Comment


            #6
            hi i'm trying to access the ENTRY price's bar

            if (Position.MarketPosition == MarketPosition.Long
            && Close[0] <= Low[BarsSinceEntry()])
            {
            ExitLong();
            }

            for some reason its not working properly. it exits even though close[0] has not closed below the low of entry price. COBC=true

            Comment


              #7
              if (Position.MarketPosition == MarketPosition.Long
              && Close[0] <= Variable0)
              {
              ExitLong();
              }


              the above exits on the same bar./.



              if (BarsSinceEntry() > 1
              && Position.MarketPosition == MarketPosition.Long
              && Close[0] <= Variable0)
              {
              ExitLong();
              }


              but the above does exit when close[0] goes below variable[0]. variable0 is close of entry price.

              Comment


                #8
                Originally posted by calhawk01 View Post
                if (Position.MarketPosition == MarketPosition.Long
                && Close[0] <= Variable0)
                {
                ExitLong();
                }


                the above exits on the same bar./.



                if (BarsSinceEntry() > 1
                && Position.MarketPosition == MarketPosition.Long
                && Close[0] <= Variable0)
                {
                ExitLong();
                }


                but the above does exit when close[0] goes below variable[0]. variable0 is close of entry price.
                what i'm trying to do is exit if the close[0] is less than the closing of the entry price. i'm using renko bars, therefore, i want to wait until the close[0] has been established

                Comment


                  #9
                  calhawk01, so you mean the low of the entry bar or the actual entry price (Position.AvgPrice) itself? From the snippets this is not clear to me. If you're working on CalculateOnBarClose = true, the script would wait until the bar is closed and evaluate your conditions, as such it would not exit intrabar on the price level breached.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  571 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  330 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  549 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  549 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X