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

Cannot redeclare dataseries for a trailing stop.

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

    Cannot redeclare dataseries for a trailing stop.

    Hi,

    I am trying to create a trailing stop logic (I don't want to use the trailstop method as I don't want my trailing stop to be entered when I initially enter the market, I only want it to kick in when a certain condition becomes true).

    But I am finding that once I declare a dataseries, Ninjatrader 7 seems to not allow me to redeclare the dataseries value:.

    For example, here is the code I'm looking at:
    PHP Code:
    //NB This is within if (BarsInProgress == 0) {

    //Stop Calculations
                
    Minmove TickSize*5;
                if (
    Xtest[0] >= Closes[0][0]) 
    //If xTest (trail stop price) is higher than current price, reset it to current price minus Minmove
                
    {    
                
    Xtest.Set(Closes[0][0] -Minmove);
                }
    //Else if new xTest would be tighter to current price than current xTest, and/or xTest = zero redeclare at tighter value    
                
    else if (Closes[0][0] -Minmove] > Xtest[1] || Xtest[0] ==)
                {
                
    Xtest.Set(Closes[0][0] -Minmove);
                }
    //Else continue to use same xTest value
                
    else
                {
                
    Xtest.Set(Xtest[1]);
                }
                Print(
    "Xtest    " Xtest[0] + "    Price    "Closes[0][0]); 
    The output for this does not behave as expected xTest is revalued both higher and lower, always according to the original declared value (current close minus 5 ticks):

    Xtest 10759 Price 10764
    Xtest 10763 Price 10768
    Xtest 10765 Price 10770
    Xtest 10765 Price 10770
    Xtest 10765 Price 10770

    Is there a way around this please? The current results above means that my "trailing stop" simply follows the market and doesn't "lock in" the profit.

    Many thanks in advance,

    David

    #2
    David, this is simply a matter of convention. You just have to set the historical value differently. The overload you are looking for is this:
    Code:
    DataSeries.Set(int barsAgo, double value);
    So to set your DataSeries (dSeries) a value of 100 2 bars back, this would do the trick:
    Code:
    dSeries.Set(2, 100);
    AustinNinjaTrader Customer Service

    Comment


      #3
      Hi Austin,

      Many thanks for the fast reply.

      Are you saying that I can use the code you've provided to redeclare the Dseries? I'm not sure I want to set a historical value; I want to redeclare the Dseries.

      Apologies if I've misunderstood.

      Kind Regards,

      David

      Comment


        #4
        Hi dfarrell,

        Thanks you for posting, someone will reply shortly.
        TimNinjaTrader Customer Service

        Comment


          #5
          dfarrell,

          Perhaps this article discussing DataSeries objects will be helpful for you: http://www.ninjatrader-support.com/H...taSeriesObject

          What you want to do then is just use .Set(someValue) and set whatever value into it that you would like.
          Josh P.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by andrewtrades, Today, 04:57 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          3 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          6 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X