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 charlesugo_1, 05-26-2026, 05:03 PM
                  0 responses
                  65 views
                  0 likes
                  Last Post charlesugo_1  
                  Started by DannyP96, 05-18-2026, 02:38 PM
                  1 response
                  149 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by CarlTrading, 05-11-2026, 05:56 AM
                  0 responses
                  162 views
                  0 likes
                  Last Post CarlTrading  
                  Started by CarlTrading, 05-10-2026, 08:12 PM
                  0 responses
                  99 views
                  0 likes
                  Last Post CarlTrading  
                  Started by Hwop38, 05-04-2026, 07:02 PM
                  0 responses
                  286 views
                  0 likes
                  Last Post Hwop38
                  by Hwop38
                   
                  Working...
                  X