NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 04-18-2010, 08:11 AM   #1
dfarrell
Junior Member
 
Join Date: Mar 2010
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default 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
dfarrell is offline  
Reply With Quote
Old 04-18-2010, 12:22 PM   #2
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 90 times in 82 posts
Default

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);
NinjaTrader_Austin is offline  
Reply With Quote
Old 04-18-2010, 02:12 PM   #3
dfarrell
Junior Member
 
Join Date: Mar 2010
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default

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
dfarrell is offline  
Reply With Quote
Old 04-19-2010, 07:07 AM   #4
NinjaTrader_Tim
NinjaTrader Customer Service
 
NinjaTrader_Tim's Avatar
 
Join Date: Nov 2009
Location: Denver, CO
Posts: 1,424
Thanks: 0
Thanked 3 times in 3 posts
Default

Hi dfarrell,

Thanks you for posting, someone will reply shortly.
NinjaTrader_Tim is offline  
Reply With Quote
Old 04-19-2010, 09:38 AM   #5
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

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.
NinjaTrader_Josh is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trailing Profits - How to Reverse a Trailing Stop? jeremymgp Strategy Development 1 05-05-2009 10:47 AM
Going from a Stop Loss to a Trailing Stop within a strategy Sidhartha Strategy Development 28 03-24-2009 03:11 PM
Trailing Stop with a fixed 20 tick stop Godzilla Strategy Development 3 03-18-2009 07:07 AM
stop loss, trailing stop modification in NT6 alfie Strategy Development 1 03-26-2008 03:46 PM
NT 6.5 - Trailing stop not trailing PocoDiablo Miscellaneous Support 3 03-19-2008 01:46 PM


All times are GMT -6. The time now is 05:45 PM.