Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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:



            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 traderqz, Today, 12:06 AM
            2 responses
            3 views
            0 likes
            Last Post traderqz  
            Started by RideMe, 04-07-2024, 04:54 PM
            5 responses
            28 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by f.saeidi, Today, 08:13 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by DavidHP, Today, 07:56 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by kujista, Today, 06:23 AM
            3 responses
            11 views
            0 likes
            Last Post kujista
            by kujista
             
            Working...
            X