• 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

Current current price bar in historical testing

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

    Current current price bar in historical testing

    I am trying to set up a strategy that moves stop loss prices as the price increases but when I view in debug mode, the value Close[CurrentBar], does not change but I can see that the value of CurrentBar is increasing. The code is in the OnBarUpdate() method.

    #2
    Hello mww1615,

    Series use barsAgo values for indexes.

    0 bars ago would be the current bar.

    Using Close[CurrentBar] would return the close price of the first bar on the chart not the current bars close. This wouldn't change because that bar is already closed.

    Below is a public link to the help guide on Close.
    https://ninjatrader.com/support/help...n-us/close.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I am trying to backtest a strategy with changing stop losses and when I check the value of CurrentBar, it increases each time thru so I assumed close[CurrentBar] would be getting the price that was currently being evaluated on the chart. Here is the code I am trying to run to change the stop loss price based on how much the price has increased. Can you please give me a suggestion of how I can do this.

      if (Position.MarketPosition == MarketPosition.Long)
      {
      double p = Close[CurrentBar];
      if ( Close[CurrentBar] >= (entry_price + 6 * TickSize) && controlOne)
      {
      SetStopLoss("stopOrder", CalculationMode.Price, Position.AveragePrice, true);
      controlOne = false;
      }
      else if (Close[CurrentBar] >= (entry_price + 12 * TickSize) && !controlOne)
      {
      SetStopLoss("stopOrder", CalculationMode.Price, Position.AveragePrice + 4* TickSize, true);
      }
      }

      Comment


        #4
        Hello mww1615,

        Use a bars ago index of 0 bars ago as demonstrated in the help guide.

        Close[0]
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DTSSTS, Yesterday, 10:14 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by fredfred, Today, 04:17 PM
        0 responses
        10 views
        0 likes
        Last Post fredfred  
        Started by p.lozanski, Today, 03:51 PM
        0 responses
        7 views
        0 likes
        Last Post p.lozanski  
        Started by JTizz, Yesterday, 04:56 PM
        1 response
        25 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by brunoviveiros, Yesterday, 09:10 AM
        2 responses
        11 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X