NexusFi: Find Your Edge


Home Menu

 





Redeclaring a dataseries to use as a trailing stop


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Davidnmfarrell with 2 posts (0 thanks)
    2. looks_two eman with 2 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 Big Mike with 1 posts (0 thanks)
    1. trending_up 4,251 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 Davidnmfarrell 
London
 
Experience: Intermediate
Platform: NT
Broker: None yet
Trading: US
Posts: 2 since Apr 2010
Thanks Given: 0
Thanks Received: 0

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:
 
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


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Topstep Acquires The Futures Desk -- Prop Firm Consolida …
Funded Trading Evaluation Firms
Iran Update May 8: Still Reviewing MOU, Demands Reparati …
Traders Hideout
The May 31 Binary: 60% Trump Declares Iran Ops Over, Onl …
Prediction Markets & Event Contracts
February NFP Preview -- Why This Mornings Jobs Number Co …
Traders Hideout
Kharg Island at 6%, Regime Fall at 1.5% -- The Black Swa …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
23 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
  #3 (permalink)
 Davidnmfarrell 
London
 
Experience: Intermediate
Platform: NT
Broker: None yet
Trading: US
Posts: 2 since Apr 2010
Thanks Given: 0
Thanks Received: 0


This code attempts to do a similar thing but also for some reason the stop retraces, rather than only excepting higher values.

 
Code
                            
if (Closes[0][0] > Closes[0][1])

                    {
                    
ExitLongStop(Position.Quantity,Closes[0][0]-Minmove,"Long Exit","Uptrend");
                    }
                    else
                    {
                    
ExitLongStop(Position.Quantity,Closes[0][1]-Minmove,"Long Exit","Uptrend");
                    } 


Started this thread Reply With Quote
  #4 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,669 since Jun 2009
Thanks Given: 33,669
Thanks Received: 102,557

Make it simpler.

My first guess as to why it isn't performing as you expect is because of the way NT handles MTF.

I suggest making a new strategy, just make it single time frame only, and test your code there. Then you'll see the differences.

Another way is to put a debug Print() statement right above each of the .Set() for DataSeries so you can see when it is being called and why. Be sure the print includes which BarsInProgress you are currently looping through and the CurrentBar.

Mike




We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 eman 
Galveston ,TX
 
Experience: Intermediate
Platform: NT7
Broker: Zaner
Trading: Futures
Posts: 386 since Mar 2010
Thanks Given: 364
Thanks Received: 435

here's an idea:
- initialize a secondary bar series as 1-tick
- when you enter your stop, make sure you have a pointer to it
 
Code
myStopId = ExitLongStop(...);
- then you can check Close[0] inside (BarsInProgress == 1) to see if it has moved up 1-tick in your direction; if so, then adjust your stop accordingly
 
Code
if (BarsInProgress == 1)
  if (Close[0] > ...logic...)
    myStopId = ExitLongStop(...new_value...);
note: you'll need to code up a stop-threshold and stop-value to use inside that second if() statement ... and you can get as complex as you like -- initial fixed stop that converts to a trailing stop after x ticks in profit, etc.

cheers,
-e


Reply With Quote
  #6 (permalink)
 eman 
Galveston ,TX
 
Experience: Intermediate
Platform: NT7
Broker: Zaner
Trading: Futures
Posts: 386 since Mar 2010
Thanks Given: 364
Thanks Received: 435

...one other thing...

make sure you use the correct overload to submit those stop order modifications to the 1-tick bar array, not 0 (default); otherwise you won't effectively simulate the trailing stop logic.

cheers,
-e


Reply With Quote




Last Updated on April 26, 2010


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts