Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Redeclaring a dataseries to use as a trailing stop
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:
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):
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.
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
- 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
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.
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.