• 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

Dumb Question

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

    Dumb Question

    I have a dumb question. In this example:

    if (Close[0] >= Position.AvgPrice + 4 * TickSize)

    Is the close referring to the bar close?

    What I am trying to do is create a stoploss that updates once there is 4 ticks of profit. I am not wanting to wait until the bar closes to do it though, I want the event to trigger instantly.

    If it is referring to the bar closing, is there anything to replace close with last or something to make it trigger right away?

    Thank you.

    #2
    Hello shawnkm,

    Thank you for writing in.

    Close[0] would be referring to the close price of the current bar. Now, depending if your strategy has calculate on bar close set to true or false....
    • If CalculateOnBarClose is true: Close[0] will refer to the closing price of the bar that just closed.
    • If CalculateOnBarClose is false: Close[0] will refer to the current price of the instrument.


    If you would like your strategy logic to run in real time, you'll need to set the CalculateOnBarClose property in Initialize() to false. This will cause your strategy logic to evaluate on every tick that comes in rather than at the close of a bar.

    More information about CalculateOnBarClose can be found here: https://ninjatrader.com/support/help...onbarclose.htm

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      I do want CalculateOnBarClose to be false as thats how I have written the strategy, I just want to update stoplosses in real time.

      There is no way to have it update stoploss in realtime while leaving CalculateOnBarClose to false?

      Thanks again.

      Comment


        #4
        Hello shawnkm,

        CalculateOnBarClose should be false if you would like the strategy to evaluate in real-time.

        Close[0] will return the current last price with CalculateOnBarClose set to false.

        Are you not seeing your stop loss update when this condition is met?
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Sorry... i meant calculate on close i have set to true. As i don't want tons of false signals on the entry. I just want stop losses updated in realtime.

          Comment


            #6
            Hello shawnkm,

            If you would like your stop losses to be updated in real-time while your strategy has CalculateOnBarClose set to true, you will need to update them within a method that is called in real-time.

            You can utilize the OnMarketData() method. OnMarketData() is called on every change in level one market data for the instrument regardless of the CalculateOnBarClose property setting: https://ninjatrader.com/support/help...marketdata.htm

            The example provided on the page will show you how you can obtain the current last price from within this method.
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              OK.. so if i want say an 8 tick trailing stop after the first bar, that updates each tick, can I do something like this:

              if (Close[0] > Position.AvgPrice + 1 * TickSize && currentStop < Position.AvgPrice - 7 * TickSize)
              {
              currentStop = Position.AvgPrice - 7 * TickSize;
              SetStopLoss(CalculationMode.Price, currentStop);
              trail = true;
              }

              {
              EnterLong("Long1");
              }

              protected override void OnMarketData(MarketDataEventArgs e)
              {
              if (e.MarketDataType == MarketDataType.Last && trail == true && e.Price > currentStop + 1 * TickSize)
              {
              currentStop = e.Price - 8 * TickSize;
              SetStopLoss(CalculationMode.Price, currentStop);
              }
              }

              Comment


                #8
                Hello shawnkm,

                If you want a trailing stop, there is already a built-in method that will have the stop trail for you: https://ninjatrader.com/support/help...ttrailstop.htm

                I would also suggest taking a look at this reference sample for more information about modifying stop loss and/or profit target orders: http://ninjatrader.com/support/forum...ead.php?t=3222
                Zachary G.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by vpzdcv, Today, 02:31 AM
                0 responses
                7 views
                0 likes
                Last Post vpzdcv
                by vpzdcv
                 
                Started by YevhenShynkarenko, Today, 01:22 AM
                0 responses
                10 views
                0 likes
                Last Post YevhenShynkarenko  
                Started by ttodua, Today, 12:52 AM
                0 responses
                6 views
                0 likes
                Last Post ttodua
                by ttodua
                 
                Started by ttodua, Today, 12:50 AM
                0 responses
                5 views
                0 likes
                Last Post ttodua
                by ttodua
                 
                Started by mulshah, Yesterday, 11:12 PM
                0 responses
                6 views
                0 likes
                Last Post mulshah
                by mulshah
                 
                Working...
                X