Programming my first strategy - need a little review - NinjaTrader Programming | futures io social day trading
futures io futures trading


Programming my first strategy - need a little review
Updated: Views / Replies:657 / 4
Created: by roreilly 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 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
 
Thread Tools Search this Thread
 

Programming my first strategy - need a little review

  #1 (permalink)
Elite Member
Milwaukee WI
 
Futures Experience: Intermediate
Platform: Firetip
Favorite Futures: oil, spy, qqq,
 
Posts: 17 since Sep 2012
Thanks: 60 given, 22 received

Programming my first strategy - need a little review

I am coding my first strategy from scratch, using a boolseries.

Entry is very simple: on the change in trend from the HeikinAshiPaintBars indicator.

Exit is 5 ticks beyond the extreme of the bar in which the indicator reverses itself again.

I still need to add a stoploss when a new position is opened; I will use onorderupdate() for that.

But I need help with the #region Properties

I have getting the error namespace member declaration expected on the last line, and so it won't compile. I can't figure out what I am supposed to add here. Any help would be appreciated.

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// This is the starter for my trading system.  Ides is to try to stay in trends longer.
    /// </summary>
    [Description("This is the starter for my trading system.  Ides is to try to stay in trends longer.")]
    public class HeikinAshiTFsystem : Strategy
    {
        #region Variables
        // Wizard generated variables
        private int initialStopLoss = 30; // Default setting for InitialStopLoss
        private int cushionOnStop = 6; // Default setting for CushionOnStop
        private int targetGain = 100; // Default setting for TargetGain
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
            Add(anaHeikinAshiPaintBars());

            CalculateOnBarClose = true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Condition set 1
            if (ToTime(Time[0]) >= ToTime(8, 59, 0)
                && ToTime(Time[0]) <= ToTime(10, 0, 0)
				&& (Position.MarketPosition == MarketPosition.Flat)
				&& (anaHeikinAshiPaintBars.UpTrend(false)[1])
				&& (anaHeikinAshiPaintBars.UpTrend(true)[0]))
            {
                EnterLong(DefaultQuantity, "");
            }

            // Condition set 2
            if (ToTime(Time[0]) >= ToTime(8, 59, 0)
                && ToTime(Time[0]) <= ToTime(10, 0, 0)
				&& (Position.MarketPosition == MarketPosition.Flat)
				&& (anaHeikinAshiPaintBars.UpTrend(true)[1])
				&& (anaHeikinAshiPaintBars.UpTrend(false)[0]))
            {
                EnterShort(DefaultQuantity, "");
            }
        
		// Condition set 3
			if ((Position.MarketPosition == MarketPosition.Long)
				&& (anaHeikinAshiPaintBars.UpTrend(true)[1])
				&& (anaHeikinAshiPaintBars.UpTrend(false)[0]))
			(
				ExitLongStop(Low[1]-5*TickSize)
			);
				
		// Condition set 4
			if ((Position.MarketPosition == MarketPosition.Short)
				&& (anaHeikinAshiPaintBars.UpTrend(false)[1])
				&& (anaHeikinAshiPaintBars.UpTrend(true)[0]))
			(
				ExitShortStop(High[1]-5*TickSize)

			);
			else 
			
        #region Properties

				
        #endregion Properties
    )}}}}

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)
 Vendor: www.probabletrades.com 
OC, California, USA
 
Futures Experience: Advanced
Platform: IB/TWS, NinjaTrader, thinkorswim
Favorite Futures: stocks, options, futures, VIX
 
shodson's Avatar
 
Posts: 1,859 since Jun 2009
Thanks: 480 given, 3,255 received


You are mixing parentheses ( ) with curly brackets { } so the compiler is confused when certain code blocks begin and end. Code blocks begin and end with brackets, not parentheses. The Condition Set 3 and Condition Set 4 blocks are using parentheses when they should use brackets. Also I noticed there is a closing parentheses at the bottom where you have all of those brackets stacked up.

You should vertically align your begin and ending brackets to make sure they are matching up properly, not pile them all together like you did at the end of the file.

Programming requires exact attention to details like these.

Reply With Quote
The following 2 users say Thank You to shodson for this post:
 
  #4 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,337 since Dec 2012
Thanks: 11,277 given, 7,091 received

@roreilly

As well as the parentheses mix ups mentioned by @shodson you are missing the definitions for the anaHeikenAshipaintBarSeries (ref'd in https://futures.io/ninjatrader/32424-calling-boolseries-indicator.html#post422023)


You also appear to have deleted the NinjaScript generated code for handling the input parameters, I have tidied the code and commented out the missing requirements until you download and install them in your system. I don't have them in my system so check with @Fat Tails if you don't already have them. (I tried a couple of forum searches but nothing showed up, but then it often does that to me.)


Clicking on brackets or parentheses will highlight the matching one in the editor, and clicking on the left hand side [+]/[-] boxes to see sections in/out also helps. When it doubt, comment it out and add bits back in slowly, and sometimes do it into a complete newly generated file in case of really hard to spot junk characters or oddball stuff that's crept in.


Formatting better will help a lot, but cut/paste from Ninja into these CODE blocks in posts can give messy results due to lack of TAB handling on editing and different mixes of tabs/spaces, etc so just edit as per your prefs, where possible use tabs consistently before adding spaces to align, i.e. whatyouseemightnotbewhatyouget (as you can see here.) Using a ZIP file is preferable for large projects, but this way can be ok for fast glances.

It compiles fine now but I doubt that it is either correct or will make you a fortune if it is, have fun.

 
Code
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class Tstrat : Strategy
    {
        #region Variables
        // Wizard generated variables
        private int initialStopLoss = 30; // Default setting for InitialStopLoss
        private int cushionOnStop = 6; // Default setting for CushionOnStop
        private int targetGain = 100; // Default setting for TargetGain
        // User defined variables (add any user defined variables below)
		
		//private anaHeikinAshiType  candleType  =  anaHeikinAshiType.Dan_Valcu_Smoothed;   
		//private int period  =   10;
		//private anaHAMAType  smoothingType  =  anaHAMAType.Ehlers;
		//private Indicator.anaHeikinAshi  AHA  =   null;        
		#endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
			//AHA = anaHeikinAshi(candleType, period, smoothingType);
			//Add(AHA);
			
           CalculateOnBarClose = true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Condition set 1
			
            if (ToTime(Time[0]) >= ToTime(8, 59, 0)
                && ToTime(Time[0]) <= ToTime(10, 0, 0)
				&& (Position.MarketPosition == MarketPosition.Flat)
				/*&& (anaHeikinAshiPaintBars.UpTrend(false)[1])
				&& (anaHeikinAshiPaintBars.UpTrend(true)[0])*/ )
            {
                EnterLong(DefaultQuantity, "");
            }


            // Condition set 2
			
            if (ToTime(Time[0]) >= ToTime(8, 59, 0)
                && ToTime(Time[0]) <= ToTime(10, 0, 0)
				&& (Position.MarketPosition == MarketPosition.Flat)
				/*&& (anaHeikinAshiPaintBars.UpTrend(true)[1])
				&& (anaHeikinAshiPaintBars.UpTrend(false)[0])*/ )
            {
                EnterShort(DefaultQuantity, "");
            }
        
			// Condition set 3
			
			if ((Position.MarketPosition == MarketPosition.Long)
				/*&& (anaHeikinAshiPaintBars.UpTrend(true)[1])
				&& (anaHeikinAshiPaintBars.UpTrend(false)[0]) */)
			{
				ExitLongStop(Low[1]-5*TickSize);
			}
			else
			{
				// if you want different code
			}
				
			// Condition set 4
			if ((Position.MarketPosition == MarketPosition.Short)
				/* && (anaHeikinAshiPaintBars.UpTrend(false)[1])
				&& (anaHeikinAshiPaintBars.UpTrend(true)[0]) */)
			{
				ExitShortStop(High[1]-5*TickSize);

			}
			else
			{
				// if you want different code
			}
		}
  

        #region Properties
        [Description("")]
        [GridCategory("Parameters")]
        public int InitialStopLoss
        {
            get { return initialStopLoss; }
            set { initialStopLoss = Math.Max(1, value); }
        }
		
        [Description("")]
        [GridCategory("Parameters")]
        public int CushionOnStop
        {
            get { return cushionOnStop; }
            set { cushionOnStop = Math.Max(1, value); }
        }
		
        [Description("")]
        [GridCategory("Parameters")]
        public int TargetGain
        {
            get { return targetGain; }
            set { targetGain = Math.Max(1, value); }
        }
        #endregion
    }
}

Travel Well
Reply With Quote
The following 2 users say Thank You to ratfink for this post:
 
  #5 (permalink)
Elite Member
Milwaukee WI
 
Futures Experience: Intermediate
Platform: Firetip
Favorite Futures: oil, spy, qqq,
 
Posts: 17 since Sep 2012
Thanks: 60 given, 22 received


shodson View Post
You are mixing parentheses ( ) with curly brackets { } so the compiler is confused when certain code blocks begin and end. Code blocks begin and end with brackets, not parentheses. The Condition Set 3 and Condition Set 4 blocks are using parentheses when they should use brackets. Also I noticed there is a closing parentheses at the bottom where you have all of those brackets stacked up.

You should vertically align your begin and ending brackets to make sure they are matching up properly, not pile them all together like you did at the end of the file.

Programming requires exact attention to details like these.

Your comment was spot on. The text was so small on my screen, the parentheses and curly brackets looked the same. I bumped up the font size, and problem solved! Thank you so much, I had been spinning my wheels for hours.

Reply With Quote
The following 2 users say Thank You to roreilly for this post:

Reply



futures io > > > > > Programming my first strategy - need a little review

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
Help programming strategy sburtt NinjaTrader Programming 2 November 20th, 2012 06:06 PM
Programming simple strategy Hermo Elite Automated Trading 1 October 24th, 2012 08:21 PM
Help with programming strategy ryangillespie Elite Automated Trading 2 February 9th, 2012 06:13 PM
Can someone help with strategy programming? Tony NinjaTrader Programming 2 October 3rd, 2010 09:38 PM
Programming Strategy Ideas spinnybobo Elite Automated Trading 14 May 12th, 2010 01:04 PM


All times are GMT -4. The time now is 08:23 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-15 in 0.14 seconds with 19 queries on phoenix via your IP 54.234.247.118