Strategy + indicator coding - samples / examples - NinjaTrader Programming | futures io social day trading
futures io futures trading


Strategy + indicator coding - samples / examples
Updated: Views / Replies:12,258 / 19
Created: by max-td Attachments:1

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
 1  
 
Thread Tools Search this Thread
 

Strategy + indicator coding - samples / examples

  #11 (permalink)
Elite Member
Frankfurt
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: FGBL 6E B4
 
max-td's Avatar
 
Posts: 1,754 since Jun 2009
Thanks: 2,309 given, 917 received

hi mrticks,
see MXASJs post.

max-td

Last edited by max-td; November 30th, 2009 at 09:09 AM.
Reply With Quote
 
  #12 (permalink)
Elite Member
Dublin, Ireland.
 
Futures Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Favorite Futures: FDAX, cable/yen, FX, options on commodities
 
mrticks's Avatar
 
Posts: 67 since Jun 2009
Thanks: 16 given, 9 received


max-td View Post
hi mrticks,
it should work like this with all three together.

I have a break-even component in there also. Maybe that is my problem. I'll go over a few strategies from other people and see how they have coded it out.


Thanks for the response.

Reply With Quote
 
  #13 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received


The SetTrailStop() method can NOT be used concurrently with the SetStopLoss() method for the same position, if both methods are called for the same position (fromEntrySignal) the SetStopLoss() will always take precedence. You can however, use both methods in the same strategy if they reference different signal names.

-NT 6 Help

Reply With Quote
The following 2 users say Thank You to MXASJ for this post:
 
  #14 (permalink)
Elite Member
Dublin, Ireland.
 
Futures Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Favorite Futures: FDAX, cable/yen, FX, options on commodities
 
mrticks's Avatar
 
Posts: 67 since Jun 2009
Thanks: 16 given, 9 received


MXASJ View Post
The SetTrailStop() method can NOT be used concurrently with the SetStopLoss() method for the same position, if both methods are called for the same position (fromEntrySignal) the SetStopLoss() will always take precedence. You can however, use both methods in the same strategy if they reference different signal names.

-NT 6 Help

Thanks MXAJ, good to know, appreciate it.

Reply With Quote
 
  #15 (permalink)
Elite Member
Dublin, Ireland.
 
Futures Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Favorite Futures: FDAX, cable/yen, FX, options on commodities
 
mrticks's Avatar
 
Posts: 67 since Jun 2009
Thanks: 16 given, 9 received


max-td View Post
here some snippets for

StopLoss
ProfitTarget
TrailStop

in strategys

 
Code
                            
    protected override void Initialize()

        {
            
// Submit stop-loss and profit target orders


            
SetStopLoss(CalculationMode.Ticks5);

            
SetProfitTarget(CalculationMode.Ticks10);

           
SetTrailStop(CalculationMode.Ticks40);
            
            
CalculateOnBarClose true;
            

        } 
http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?SetProfitTarget

http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?SetTrailStop

http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?SetStopLoss


Attention :
The SetTrailStop() method can NOT be used concurrently with the SetStopLoss() method for the same position, if both methods are called for the same position (fromEntrySignal) the SetStopLoss() will always take precedence. You can however, use both methods in the same strategy if they reference different signal names.


Here is the code that I had:

 
Code
                            
#region Breakeven and Trailing Stops
            // Resets the stop loss to the original value when all positions are closed
               
switch (Position.MarketPosition)
            {
                case 
MarketPosition.Flat:
                    
SetStopLoss(CalculationMode.TicksstopLoss);
                    
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.PriceinitialBreakEven);
                        
previousPrice Position.AvgPrice;
                        
PrintWithTimeStamp("previousPrice = "+previousPrice);
                    }
                    
// Once at breakeven wait till trailProfitTrigger is reached before advancing stoploss by trailStop size step
                    
else if (previousPrice    != ////StopLoss is at breakeven
                             
&& GetCurrentAsk() > previousPrice trailProfitTrigger TickSize
                        
)
                    {
                        
newPrice previousPrice trailStop TickSize;
                        
SetStopLoss(CalculationMode.PricenewPrice);
                        
previousPrice newPrice;
                        
PrintWithTimeStamp("previousPrice = "+previousPrice);
                    }
                    break; 
My entries are beautiful on the strategy!!!! Just can't get the trailing stop working. It takes the stop loss and initial breakeven but doesn't trail. When I get the code for trailing stop then I'll post it.

Reply With Quote
 
  #16 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

You need to get rid of the SetStopLoss code and use SetTrailStop I believe. I'll post an example later.

EDIT: I found this in my 6.5 folder and if memory serves the SetTrailStop function worked in this strategy both short and long. It's sloppy but might give you some ideas.

Attached Files
Register to download File Type: cs ZN_v1_Backtest.cs (8.5 KB, 106 views)

Last edited by MXASJ; December 1st, 2009 at 10:25 AM.
Reply With Quote
The following user says Thank You to MXASJ for this post:
 
  #17 (permalink)
Elite Member
Dublin, Ireland.
 
Futures Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Favorite Futures: FDAX, cable/yen, FX, options on commodities
 
mrticks's Avatar
 
Posts: 67 since Jun 2009
Thanks: 16 given, 9 received


MXASJ View Post
You need to get rid of the SetStopLoss code and use SetTrailStop I believe. I'll post an example later.

EDIT: I found this in my 6.5 folder and if memory serves the SetTrailStop function worked in this strategy both short and long. It's sloppy but might give you some ideas.

Thanks MXASJ, I'll take a look at that template. Appreciate the response.

Reply With Quote
 
  #18 (permalink)
Elite Member
Dublin, Ireland.
 
Futures Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Favorite Futures: FDAX, cable/yen, FX, options on commodities
 
mrticks's Avatar
 
Posts: 67 since Jun 2009
Thanks: 16 given, 9 received


MXASJ View Post
You need to get rid of the SetStopLoss code and use SetTrailStop I believe. I'll post an example later.

EDIT: I found this in my 6.5 folder and if memory serves the SetTrailStop function worked in this strategy both short and long. It's sloppy but might give you some ideas.

I got exactly what I wanted from that, perfect entries and spot on trail stops, so am going to modify a breakeven to it and see how it runs.

 
Code
                            
SetTrailStop(CalculationMode.TicksStop);
EnterLongStop(ContractAmountHigh[0] + PrevBarPlusTicks TickSize"Long Entry"); 

Reply With Quote
 
  #19 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

Glad it helped! In terms of breakeven you can do that with your target/trail in some ways. A two contract ZN example with a target on the first contract @ 5 ticks and an 8 tick trail on both contracts becomes a "breakeven" trade once that target is hit (ignoring slippage).

Reply With Quote
 
  #20 (permalink)
Elite Member
Dublin, Ireland.
 
Futures Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Favorite Futures: FDAX, cable/yen, FX, options on commodities
 
mrticks's Avatar
 
Posts: 67 since Jun 2009
Thanks: 16 given, 9 received



MXASJ View Post
Glad it helped! In terms of breakeven you can do that with your target/trail in some ways. A two contract ZN example with a target on the first contract @ 5 ticks and an 8 tick trail on both contracts becomes a "breakeven" trade once that target is hit (ignoring slippage).

Thanks. Will hopefully get some code up here later with a breakeven type method on it. Depending on how the day goes!

Reply With Quote

Reply



futures io > > > > > Strategy + indicator coding - samples / examples

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
Some coding help adding PnL display to strategy grego The Elite Circle 5 March 23rd, 2012 02:12 PM
Strategy Coding Challenge MWinfrey NinjaTrader Programming 4 January 25th, 2011 06:12 PM
Strategy coding - Would Anyone please take a quick look at........ mdsvtr NinjaTrader Programming 4 November 5th, 2010 06:54 AM
Strategy Wizard Coding Question njaisson NinjaTrader Programming 8 October 6th, 2010 08:34 AM
Help Coding Trailing stoploss in Strategy Darshiit NinjaTrader Programming 3 June 25th, 2010 10:45 AM


All times are GMT -4. The time now is 09:33 AM.

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