Announcement

Collapse
No announcement yet.

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 pilotfo, Today, 12:50 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by DTSSTS, Today, 11:35 AM
          2 responses
          10 views
          0 likes
          Last Post DTSSTS
          by DTSSTS
           
          Started by sinpeople, Today, 07:20 AM
          2 responses
          5 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Frank1000, Today, 03:05 AM
          5 responses
          12 views
          0 likes
          Last Post Frank1000  
          Started by fscabrera03, Yesterday, 01:18 PM
          2 responses
          25 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X