• 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

trailing stop

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

    trailing stop

    Hey guys,
    just have got a few question if you don't mind. As I got it, the wizard trailingstop is based on tickbases and does not work on a minute basis; is that right?

    Thus I tried to programm my own trailing stop indicator. Now here's the problem: I can access the minute Price via Close[] etc. but how can I store a specific minute close price-value? I only need a variable holding this single value not being updated all the time.

    Might be a stupid question but I still can't find anything in the help section.

    Best wishes,

    Andrew

    #2
    Hi Andrew,

    You can assign the value of Close[x] to a double variable at any time using the assignment operator, like so:

    double closePrice = Close[0];

    You can update this variable with new closing prices as often as you would like in the same way. When you are working with the trailing stop, one thing that can trip people up is making sure that the trail only moves in the right direction, rather than moving in either direction along with the market price. If you would like any assistance with the trailing-stop logic, I'll be happy to help.

    Please let me know if I can assist further.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      thx for the reply!

      I know that I can store it as you suggested (double closePrice = Close[0], but it is updated all the time and recalculated with every new bar formed within the onbarupdate which I don't want.

      I want to enter into a trade storing only the minute price value of the first bar formed (independent of time) Lets say the entering Close is of Price 80.05 then my variable should still hold the value 80.05 in a few bars time. without this step my logic does not work.

      Or is there an easier way to get a trailing stop on minute basis?
      Being grateful for your help

      Andrew

      Comment


        #4
        Hi Andrew,

        I see what you mean. The best way to accomplish this would probably be to use some kind of conditional logic to determine when to set the value of the variable, and when not to. For example, perhaps you could set a bool variable to True when you enter a trade, and only change the value of the closePrice variable when that bool returns False.

        It may be easier to accomplish what you are looking for by using the SetTrailStop() method. Since SetTrailStop() works based on the setting of CalculateOnBarClose, you can use SetTrailStop() to move the stop loss based on when a bar closes. With CalculateOnBarClose set to True, OnBarUpdate() will run once per bar close. Thus, if you use a specific time interval for your data series, you can simply count how many bars have painted in a certain timeframe. For example, if you wanted to move your stop loss every 5 minutes, you could call SetStopLoss() every fifth bar while using 1 minute bars, or every single bar if you are using 5 minute bars.

        Things can get a bit tricky if you would like to base your entries on tick data while basing stop-loss adjustments on minute data, but there is a way to deal with this dilemma, as well. For more information on this, please see the reference sample below:

        http://www.ninjatrader.com/support/f...ad.php?t=19387

        For more information on using SetTrailStop(), please see the help guide article below:

        http://www.ninjatrader.com/support/h...ttrailstop.htm

        Please let me know if I can assist further.
        Dave I.NinjaTrader Product Management

        Comment


          #5
          Thx for the fast reply!

          the link you provided says: "Trail stops are amended on a tick by tick basis." I have got no tick data. Only minute data so far and I try to find a way to backtest my strategy with a trailing stop. Thus I try to to a workaround with an indicator.

          Got any tips to progam a trailing stop as an indicator? Only then I could run my backtest.

          Thx for your help,

          Best wishes,

          Andrew

          Comment


            #6
            Hello,

            I see what you mean. You should be able to use SetTrailStop() with minute data, rather than tick data. In backtesting, tick data is actually not used at all, only the bar data of the data series. For backtesting purposes, all historical data is treated as if CalculateOnBarClose is set to True, even if it is set to False in the strategy.

            For example, if you are using a 1-minute data series to backtest, then OnBarUpdate() will run at the end of each 1-minute bar, and any calls to SetTrailStop() would execute at that time.

            I believe that using a variable to track the price at which you want your trailing stop would be a better option than using an indicator. That way you can keep all of your trailing logic within the strategy, and exercise more control over how the stop is being moved.

            For more information on this last part, please see the reference sample below:

            http://www.ninjatrader.com/support/f...ead.php?t=3222

            When you enter a position, you can set a variable to whatever price data you wish to keep track of (entry price, original stop loss price, etc.), then use that variable to reference that price at a later time, as you need it.

            Please let me know if I can assist further.
            Dave I.NinjaTrader Product Management

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Bionian, Today, 10:10 AM
            2 responses
            17 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by D Trader, Today, 01:41 PM
            0 responses
            8 views
            0 likes
            Last Post D Trader  
            Started by rexmie888, Today, 04:00 AM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by terminatorT1000, Today, 01:23 AM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by Tradarr, Today, 12:25 PM
            0 responses
            8 views
            0 likes
            Last Post Tradarr
            by Tradarr
             
            Working...
            X