Sample Advanced Automated Strategy v1.0 - NinjaTrader Programming | futures io social day trading
futures io futures trading


Sample Advanced Automated Strategy v1.0
Updated: Views / Replies:28,246 / 117
Created: by dsraider Attachments:15

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 don’t 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
 15  
 
Thread Tools Search this Thread
 

Sample Advanced Automated Strategy v1.0

  #21 (permalink)
 Vendor: www.ezcolortrading.com 
Cambridge, Ontario
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Zen-Fire
Favorite Futures: 6E
 
Posts: 1,773 since Dec 2009
Thanks: 1,258 given, 1,196 received

Hi Dave

My heartfelt thanks for sharing your strategy with us. I can tell the additional efforts you spent to make it simple and yet very comprehensive.

I've been studying it for almost 2 weeks now. As a newbie with minimal programming talents, my success as of this moment is having a BE condition triggered once the trade moves 8 ticks from my entry. All other efforts trying to include your Trail Stop code in different ways (that I could think of or tried) have not triggered a revised SL to protect some gained ticks even F5 compile successfully .. sigh ..

I am hoping maybe you will spare a few minutes going through my code and give me some tips on what I did wrong or how to make it work .. PLEASE!

 
Code
protectedoverridevoid Initialize()
{

EntriesPerDirection = 1; 
EntryHandling = EntryHandling.UniqueEntries;
CalculateOnBarClose = true;
}

privatevoid ManageOrders()
{
// Resets the stop loss to the original value when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, 15);
}

// If a long position is open, allow for stop loss modification to breakeven
if (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price +8 ticks, set stop loss to breakeven
if (Close[0] > Position.AvgPrice + 8 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice);
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\AutoTrail.wav");
}
}

// Once at breakeven wait till trailProfitTrigger is reached before advancing stoploss by trailStepTicks size
elseif (previousPrice != 0// SL is at Breakeven
&& Close[0] > previousPrice + trailProfitTrigger * TickSize)
{
newPrice = previousPrice + trailStepTicks * TickSize;
SetStopLoss(CalculationMode.Price, newPrice);
previousPrice = newPrice;
PrintWithTimeStamp("previousPrice = "+previousPrice);
PrintWithTimeStamp("newPrice = "+previousPrice);
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\AutoTrail.wav");
}

// If a short position is open, allow for stop loss modification to breakeven
if (Position.MarketPosition == MarketPosition.Short)
{
// Once the price is smaller than entry price -8 ticks, set stop loss to breakeven
if (Close[0] < Position.AvgPrice - 8 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice);
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\AutoTrail.wav");
}
}

// Once at breakeven wait till trailProfitTrigger is reached before advancing stoploss by trailStepTicks size
elseif (previousPrice != 0// SL is at Breakeven
&& Close[0] < previousPrice + trailProfitTrigger * TickSize)
{
newPrice = previousPrice - trailStepTicks * TickSize;
SetStopLoss(CalculationMode.Price, newPrice);
previousPrice = newPrice;
PrintWithTimeStamp("previousPrice = "+previousPrice);
PrintWithTimeStamp("newPrice = "+previousPrice);
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\AutoTrail.wav");
}
}
Thank you very much .. very much in advance!

Beth

Reply With Quote
 
  #22 (permalink)
Trading for Fun
New York, NY
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Amp Futures/Zen-Fire
Favorite Futures: ES
 
Posts: 142 since Dec 2009
Thanks: 41 given, 83 received

Hi Beth,

I noticed you changed CalculateOnBarClose to true. When it's set to false, Close[0] means current price, which really helps with a trailing stop. When set to true, it has to wait until the bar closes before it looks to move the stop. That could be a problem. If you can explain to me how you want the trail to actually work, I'll take a shot at it.

Don't lose your mind. We'll figure it out.

Dave

Reply With Quote
The following user says Thank You to dsraider for this post:
 
  #23 (permalink)
 Vendor: www.ezcolortrading.com 
Cambridge, Ontario
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Zen-Fire
Favorite Futures: 6E
 
Posts: 1,773 since Dec 2009
Thanks: 1,258 given, 1,196 received



dsraider View Post
Don't lose your mind. We'll figure it out.

Dave

Hi Dave

Your Swift response has certainly lightened me up! Days (incl 2 weekends) were spent trying to make a trail stop work. Every F5 compile successfully message gave me hope and yet it's a no no at the end. Very heart-breaking and I feel stupid when I've your master piece as my guidance.

I did try CalculateOnBarClose @ false and my supposed trail stop has not triggered anything when I backtested the strategy.


What I've been trying to do:

For example,

1. Long at 1000 with SL at 985 (initial 15 ticks SL) and BE when it moves 8 ticks from entry
2. Price moves to 1008
3. BE condition moves SL to 1000 (from 985) - that's how far I've accomplished
4. Price continues moving to 1010 (1008 + 2)
5. Trail stop kicks in with SL adjusts to 1002 (1000 + 2)
6. Price continues moving to 1012 (1010 + 2)
7. Trail stop to have SL adjusted to 1004 (1002 + 2)
.. ..

For every 2-tick move, SL will be adjusted 2 ticks to protect some gained profits.

++

I moved the trail stop code around dozens times and nothing has happened after each F5 compile successful. I'm running out of gas and that prompted to knock at your door. My heartfelt thanks for your GIANT lift!

Beth (now a little relieved )

Reply With Quote
 
  #24 (permalink)
Trading for Fun
New York, NY
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Amp Futures/Zen-Fire
Favorite Futures: ES
 
Posts: 142 since Dec 2009
Thanks: 41 given, 83 received

Can you try this?:

 
Code
                            
#region Variables
        
        
private int        breakEvenTicks        8;
        private 
int        plusBreakEven        0;
        private 
int     trailProfitTrigger     9;
        private 
int        trailStepTicks        2;
        
        private 
double    initialBreakEven    0;
        private 
double     previousPrice         0;
        private 
double     newPrice             0;

#endregion

protected override void OnBarUpdate()

#region Trail Stop
                    // Only allow entries if we have no current positions open
                        
switch (Position.MarketPosition)
                    {
                        case 
MarketPosition.Flat:
                            
SetStopLoss(""CalculationMode.Ticks15false);
                                                        
previousPrice 0;
                            break;
                        case 
MarketPosition.Long:
                            
// Once the price is greater than entry price+ breakEvenTicks ticks, set stop loss to breakeven
                            
if (Close[0] == Position.AvgPrice breakEvenTicks TickSize && previousPrice == 0)
                            {
                                
initialBreakEven Position.AvgPrice plusBreakEven TickSize
                                
SetStopLoss(""CalculationMode.PriceinitialBreakEvenfalse);
                                
previousPrice Position.AvgPrice;
                                
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\AutoTrail.wav");
                                
PrintWithTimeStamp("previousPrice = "+previousPrice);
                                
PrintWithTimeStamp("newPrice = "+previousPrice);
                            }
                                                        
// Once at breakeven wait till trailProfitTrigger is reached before advancing stoploss by trailStepTicks size step
                            
else if (previousPrice    != ////StopLoss is at breakeven
                                    
&& Close[0] > previousPrice trailProfitTrigger TickSize)
                                
                            {
                                
newPrice previousPrice trailStepTicks TickSize;
                                
SetStopLoss(""CalculationMode.PricenewPricefalse);
                                
previousPrice newPrice;
                                
PrintWithTimeStamp("previousPrice = "+previousPrice);
                                
PrintWithTimeStamp("newPrice = "+previousPrice);
                                
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\AutoTrail.wav");
                            }
                            break; 
I've obviously left some things out, but these are the parts needed for what you want to do. Remember to set CalculateOnBarClose back to false (that's why I use FirstTickOfBar in my entry code). I'm wondering if OnBarUpdate makes a difference as well, as I just realized you switched it to ManageOrders. Anyway, let me know how it goes.

Dave

Reply With Quote
The following user says Thank You to dsraider for this post:
 
  #25 (permalink)
Elite Member
Atlanta, Georgia
 
Futures Experience: Intermediate
Platform: NT
Broker/Data: DDT
Favorite Futures: ZN, ZB
 
cbritton's Avatar
 
Posts: 224 since Mar 2010
Thanks: 152 given, 237 received

I think you want this instead:

 
Code
                            
...
  
// Once at breakeven wait till trailProfitTrigger is reached before advancing stoploss by trailStepTicks size step
                            
else if (previousPrice    != ////StopLoss is at breakeven
                                    
&& Close[0] > previousPrice trailProfitTrigger TickSize)
                                
                            {
                                
newPrice previousPrice trailStepTicks TickSize;
                                
SetStopLoss(""CalculationMode.PricenewPricefalse);
                                
// print the previous price before it's changed
                                
PrintWithTimeStamp("previousPrice = "+previousPrice);
                                
previousPrice newPrice;
                                
PrintWithTimeStamp("newPrice = "+previousPrice);
                                
PlaySound(@"C:\Program Files\NinjaTrader 6.5\sounds\AutoTrail.wav");
                            }
                            break;
... 
Otherwise you won't see the previous price being printed

“Strategy without tactics is the slowest route to victory. Tactics without strategy is the noise before defeat.” - Sun Tzu
Reply With Quote
The following user says Thank You to cbritton for this post:
 
  #26 (permalink)
 Vendor: www.ezcolortrading.com 
Cambridge, Ontario
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Zen-Fire
Favorite Futures: 6E
 
Posts: 1,773 since Dec 2009
Thanks: 1,258 given, 1,196 received

BIG BIG Thank You to Dave and cbritton for your prompt code suggestion. I have them in the strategy (+ CalculateOnBarClose at false) and it's running on sim now. For backtesting, the revised strategy has generated the same results (same trades etc) as the one without the trail stop code?!!

Maybe trail stop only works when it's on live. Will find out later today and please stay tuned to my report.

Have a Great day.

Beth (grateful for your guidance)

Reply With Quote
 
  #27 (permalink)
Trading for Fun
New York, NY
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Amp Futures/Zen-Fire
Favorite Futures: ES
 
Posts: 142 since Dec 2009
Thanks: 41 given, 83 received

Beth,

The trail should would on the sim. If it isn't, we have an issue. I may have to take a peek at your actual strat if we can't figure it out here, as I'm flying slightly blind. Maybe you can change around a few things if you'd like to keep your actual signal to yourself. Good luck for now. I'll check back after market close.

Dave

Reply With Quote
The following user says Thank You to dsraider for this post:
 
  #28 (permalink)
 Vendor: www.ezcolortrading.com 
Cambridge, Ontario
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Zen-Fire
Favorite Futures: 6E
 
Posts: 1,773 since Dec 2009
Thanks: 1,258 given, 1,196 received

Thanks Dave. No rush as I've been working on this for 2 weeks now. The strategy with trail got a little crazy after a few minutes. You will see from the enclosed log that it started to open and close a position within a second after Trade No 1. Just stopped it running.

I have a thread on my automation efforts here. I am trying to automate The Wizard's systems and the signals are well-known in the Big Mike community. Please let me know later tonight what will you need to find out what I did wrong. Thank You .. Thank You again from the bottom of my petite heart for your help!

Beth

Attached Thumbnails
Sample Advanced Automated Strategy v1.0-ym-trade-log-w-trail.jpg  
Reply With Quote
 
  #29 (permalink)
Trading for Fun
New York, NY
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Amp Futures/Zen-Fire
Favorite Futures: ES
 
Posts: 142 since Dec 2009
Thanks: 41 given, 83 received

I'm guessing you will need to add FirstTickOfBar to your entry code and set your indicator conditions a bar back. So, instead of if(Close[0] > Open[0]) go long, you would use if(FirstTickOfBar && Close[1] > Open[1]) go long. Since CalculateOnBarClose = false makes Close[0] = current price, this allows you use close as a true close and prevents the strat from taking trades on every tick, like yours seems to be doing.

If you'd like to PM me the strat or post it here, I'll have a look. It's hard to tell what will work without knowing how you want to enter.

D

Reply With Quote
The following user says Thank You to dsraider for this post:
 
  #30 (permalink)
 Vendor: www.ezcolortrading.com 
Cambridge, Ontario
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Zen-Fire
Favorite Futures: 6E
 
Posts: 1,773 since Dec 2009
Thanks: 1,258 given, 1,196 received


Thanks Dave for your swift suggestion. I changed the entry conditions with FirstTickOfBar and [0] to [1] etc. Backtest results were different from the strategy without the trail (finally .. smile). Have it run on sim now and so far not generating trades every second - great news! Thanks to you.

Need to pick your brains on the following please:

1. trailProfitTrigger = 9;

8 + 1 formula with 8 being the breakEvenTicks? The trade needs to be 9 ticks away before the system starts adjusting the BE stoploss to BE + 2 ticks regularly (with 2 being the trailStepTicks), right?

2. With CalculateOnBarClose at false, I also changed the Exit condition. I'm not sure if I did correctly on the following CrossBelow:

(CrossBelow(d9ParticleOscillatorWVertLineR(7, 0).RawTrend, 0, 0)
which was (CrossBelow(d9ParticleOscillatorWVertLineR(7, 0).RawTrend, 0, 1)

Appreciate your advice. Thank you.

Beth

Reply With Quote

Reply



futures io > > > > > Sample Advanced Automated Strategy v1.0

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
VIDEO TUTORIAL: How to create an advanced MultiCharts EasyLanguage Strategy Big Mike MultiCharts 39 November 9th, 2017 04:35 AM
VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy Big Mike NinjaTrader 63 November 6th, 2016 03:25 PM
End of day sample strategy mrticks The Elite Circle 9 February 18th, 2011 07:37 AM
VIDEO TUTORIAL: How to create an advanced NinjaTrader Strategy Big Mike NinjaTrader Programming 0 January 26th, 2010 06:22 AM
Advanced Strategy Writing zeller4 NinjaTrader Programming 8 December 28th, 2009 12:21 AM


All times are GMT -4. The time now is 02:45 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-11 in 0.16 seconds with 20 queries on phoenix via your IP 54.226.172.30