Redeclaring a dataseries to use as a trailing stop - futures io
futures io futures trading



Redeclaring a dataseries to use as a trailing stop


Discussion in NinjaTrader

Updated by eman
      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 2,422 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 5 replies
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 100,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Thread Tools Search this Thread
 

Redeclaring a dataseries to use as a trailing stop

  #1 (permalink)
London
 
Experience: Intermediate
Platform: NT
Broker: None yet
Trading: US
 
Posts: 2 since Apr 2010
Thanks: 0 given, 0 received

Redeclaring a dataseries to use as 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:
 
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

Reply With Quote

Can you help answer these questions
from other members on futures io?
Convert NinjaTrader NT7 indicator to Tradestation EasyLanguage and RADARSCREEN
Platforms and Indicators
Issue meeting order entry conditions
Elite Automated NinjaTrader Trading
Last 5 minutes Label
ThinkOrSwim
Moving average with Lag reduction
NinjaTrader
Linux?
ThinkOrSwim
 
Best Threads (Most Thanked)
in the last 7 days on futures io
FIO Journal Challenge - June 2020 edition w/SharkIndicators
59 thanks
Spoo-nalysis ES e-mini futures S&P 500
55 thanks
June Charity Fundraiser - Feeding hungry families
51 thanks
Fixed vs trailing stops
28 thanks
AMP Futures / AMP Global Review
27 thanks
 
  #3 (permalink)
London
 
Experience: Intermediate
Platform: NT
Broker: None yet
Trading: US
 
Posts: 2 since Apr 2010
Thanks: 0 given, 0 received

Another version of the above


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");
                    } 

Reply With Quote
 
  #4 (permalink)
Site Administrator
Manta, Ecuador
 
Experience: Advanced
Platform: My own custom solution
Trading: Emini Futures
 
Big Mike's Avatar
 
Posts: 48,778 since Jun 2009
Thanks: 31,486 given, 94,171 received

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

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/
Follow me on Twitter Visit my Facebook Visit my futures io Trade Journal Reply With Quote
 
  #5 (permalink)
Galveston ,TX
 
Experience: Intermediate
Platform: NT7
Broker: Zaner
Trading: Futures
 
Posts: 386 since Mar 2010
Thanks: 364 given, 433 received

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)
Galveston ,TX
 
Experience: Intermediate
Platform: NT7
Broker: Zaner
Trading: Futures
 
Posts: 386 since Mar 2010
Thanks: 364 given, 433 received

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



futures io Trading Community Platforms and Indicators NinjaTrader > Redeclaring a dataseries to use as a trailing stop




Upcoming Webinars and Events
 

Free BloodHound Licenses for everyone!

June
 

Every journal equals ten meals for the hungry

June
     



Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts