Redeclaring a dataseries to use as a trailing stop - NinjaTrader Programming | futures io social day trading
futures io futures trading


Redeclaring a dataseries to use as a trailing stop
Updated: Views / Replies:1,585 / 5
Created: by Davidnmfarrell Attachments:0

Welcome to futures io.

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

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you dont need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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

Reply
 
Thread Tools Search this Thread
 

Redeclaring a dataseries to use as a trailing stop

  #1 (permalink)
Just starting out...
London
 
Futures Experience: Intermediate
Platform: NT
Broker/Data: None yet
Favorite Futures: 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
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Just starting out...
London
 
Futures Experience: Intermediate
Platform: NT
Broker/Data: None yet
Favorite Futures: 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
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,240 since Jun 2009
Thanks: 29,353 given, 83,234 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

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #5 (permalink)
 Vendor: www.coroin.com 
Galveston ,TX
 
Futures Experience: Intermediate
Platform: NT7
Broker/Data: Zaner
Favorite Futures: 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)
 Vendor: www.coroin.com 
Galveston ,TX
 
Futures Experience: Intermediate
Platform: NT7
Broker/Data: Zaner
Favorite Futures: 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

Reply



futures io > > > > > Redeclaring a dataseries to use as a trailing stop

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Limit Order and Trailing Stop Tiger45 NinjaTrader Programming 7 May 9th, 2013 06:57 AM
Trailing stop following an indicator nanobiotech NinjaTrader Programming 9 October 3rd, 2011 10:50 AM
trailing stop la LeBeau kiasom EasyLanguage Programming 4 May 13th, 2011 06:13 PM
Trailing Stop Loss and Reverse shergenr NinjaTrader Programming 3 March 1st, 2011 11:05 AM
Trailing stop loss kavin729 NinjaTrader Programming 1 August 20th, 2010 02:17 PM


All times are GMT -4. The time now is 03:44 PM.

Copyright © 2017 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
Page generated 2017-12-15 in 0.14 seconds with 19 queries on phoenix via your IP 54.90.92.204