Boolean Flag help needed (strategy) - NinjaTrader | futures io social day trading
futures io futures trading


Boolean Flag help needed (strategy)
Updated: Views / Replies:1,975 / 10
Created: by wallsteetking 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
 

Boolean Flag help needed (strategy)

  #1 (permalink)
Trading Apprentice
MN
 
Futures Experience: Intermediate
Platform: Ninjatrader
Favorite Futures: ES
 
Posts: 25 since Feb 2011
Thanks: 4 given, 0 received

Boolean Flag help needed (strategy)

hey guys I need some help with my code. What I want to do is create a long entry when two of my systems both fire a long on the same bar. what i did is i created a boolean and put both of my strategies into one strategy called Mashall. however when i write the code, and run it.. does not work for some reason. can someone please help me decipher why this does not work.

 
Code
/// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class MASHALL : Strategy
    {
        #region Variables
        // Wizard generated variables
        private int myInput0 = 1; // Default setting for MyInput0
        private bool enterLongStrat1 = false;
        private bool enterLongStrat2= false;
        // 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()
        {
        CalculateOnBarClose = true;
    SetProfitTarget("", CalculationMode.Ticks, 4);
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            
            // Strategy 1
        if (Bars.BarsSinceSession >=7)
                
            if (Stochastics(7, 14, 3).D[0] >= 30)
            {
                enterLongStrat1 = true;
  //       enterLongStrat2 = false;
        DrawTriangleUp("My triangle up" + CurrentBar, true, 0, High[0] + 20 * TickSize, Color.Red);
                
            }
            
            //Strategy 2
            if (Bars.BarsSinceSession >=7)
                
            if ( Close[0] >= EMA(30)[0])
            {
                enterLongStrat2 = true;
 //         enterLongStrat1 = false; now, then both conditions can never be simultaneously true if you have this
            DrawTriangleUp("My triangle up" + CurrentBar, true, 0, High[0] + 30 * TickSize, Color.Blue);
                
            }
            
            if (Bars.BarsSinceSession >=7)
            if(enterLongStrat2 == true && enterLongStrat1 == true)
            {    
                  EnterLong(DefaultQuantity, "");

            }
        }

        #region Properties
        [Description("")]
        [GridCategory("Parameters")]
        public int MyInput0
        {
            get { return myInput0; }
            set { myInput0 = Math.Max(1, value); }
        }
    
        
        #endregion

Reply With Quote
 
  #2 (permalink)
 Vendor: www.traderwerks.com 
Taipei Taiwan
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Optimus
Favorite Futures: TW
 
Posts: 693 since Jun 2009
Thanks: 440 given, 440 received

At the top of the OnBarUpdate() loop reset the flags to false

 
Code
 
        protected override void OnBarUpdate()
        {
            enterLongStrat1 = false;
           enterLongStrat2= false;

Math. A gateway drug to reality.
Reply With Quote
 
  #3 (permalink)
Elite Member
las vegas
 
Futures Experience: Intermediate
Platform: Sierra Chart
Broker/Data: Velocity/IB
Favorite Futures: 6E
 
Posts: 1,147 since Feb 2010
Thanks: 304 given, 836 received


i think should be if(enterLongStrat2 == true || enterLongStrat1 == true)

Reply With Quote
 
  #4 (permalink)
Trading Apprentice
MN
 
Futures Experience: Intermediate
Platform: Ninjatrader
Favorite Futures: ES
 
Posts: 25 since Feb 2011
Thanks: 4 given, 0 received

I tried both things and it still does not work. I have attached the file here can you guys check it .. this seems so simple to do but its not working.

Attached Files
Register to download File Type: zip Mashall.zip (10.4 KB, 7 views)
Reply With Quote
 
  #5 (permalink)
Trading Apprentice
MN
 
Futures Experience: Intermediate
Platform: Ninjatrader
Favorite Futures: ES
 
Posts: 25 since Feb 2011
Thanks: 4 given, 0 received

the reason you can tell that its not working is by looking at the triangles. when the strategy is activated you never see both red and blue triangles appear on the SAME BAR.

Reply With Quote
 
  #6 (permalink)
Elite Member
Israel
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: pfg
Favorite Futures: eminis
 
Posts: 323 since Jun 2009
Thanks: 6 given, 206 received

Why not just:
 
Code
if (Bars.BarsSinceSession >=7 && Stochastics(7, 14, 3).D[0] >= 30 && Close[0] >= EMA(30)[0])
{
DrawTriangleUp("My triangle up" + CurrentBar, true, 0, High[0] + 20 * TickSize, Color.Red);
EnterLong(DefaultQuantity, "");
}

Reply With Quote
 
  #7 (permalink)
Trading Apprentice
MN
 
Futures Experience: Intermediate
Platform: Ninjatrader
Favorite Futures: ES
 
Posts: 25 since Feb 2011
Thanks: 4 given, 0 received

The reason that I am not doing it that way is because i am going to have more than 2 conditions (probably around 11)
And some of the other conditions will be inverse of other conditions. For example one would say go long only on
== 20K while another would say go long on >= 30K or greater. If i would combine this, it would not work that well. So I need to learn have to do boolean in ninjatrader. But i am having a very hard time making the code work.


Last edited by wallsteetking; July 21st, 2013 at 06:28 PM.
Reply With Quote
 
  #8 (permalink)
Trading Apprentice
MN
 
Futures Experience: Intermediate
Platform: Ninjatrader
Favorite Futures: ES
 
Posts: 25 since Feb 2011
Thanks: 4 given, 0 received

Hey guys just a quick question does anyone have a boolean trading system NOT INDICATOR for ninjatrader. that I can use and just put my conditions in instead of yours. your help would be appreciated

Reply With Quote
 
  #9 (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,254 received

I would approach it differently...

I would create boolean properties like

 
Code
bool PriceMovedUp { get { return Close[0] > Close[1]; } }
bool AboveMA { get { return Close[0] > SMA(200)[0]; } }
(calm down literal 'net, I know this it not optimized, just trying to show a point...)

then in your OnBarUpdate() you just stack together your predicates (true/false conditions) in easy-to-follow English

 
Code
if (PriceMovedUp && AboveMA)
    EnterLong();
Another approach would be to track a score of a setup. So for example if you have 8 possible conditions you like to look at, and if 6 pass then you take a trade. So when each condition is valid, add +1 to your score. This is one way you can layer on more and more conditions without adding a bunch of unmanageable if/then permutations.

 
Code
int score = 0;
if (PriceMovedUp) score++;
if (AboveMA) score++;

if (score >= 2)
    EnterLong();

To me, readability is very important, because code can grow and become very complex really quickly. In my opinion OnBarUpdate() needs to be the most English-reading code you write, because these are the core rules of your strategy. The gory/technical details behind each command and condition can be defined elsewhere, but OnBarUpdate() needs to be your most coarse-grained part of your strategy/indicator to keep your sanity when modifying and maintaining your strategy.

For example, here is a strategy I've been trading live for years: my gap fading strat. This is the OnBarUpdate() method. The whole strategy is almost 700 lines long, but I can open this open and quickly refresh my memory about how it works just by looking at OnBarUpdate() even though I haven't looked at this code in a long time.

 
Code
protected override void OnBarUpdate()
{
	if (TimeToDecide)
	{
		if (ShouldFadeGap)
		{
			if (GapIsBigEnough)
				FadeGap();
			else
				DontFadeGap();
		}
		else if (ShouldFadeExtendedTarget)
			FadeExtendedTarget();
		else
			DontFadeGap();
	}
	else if (_faded)
	{
		ManageTrade();
	}
}


Last edited by shodson; July 24th, 2013 at 09:23 PM.
Reply With Quote
The following 4 users say Thank You to shodson for this post:
 
  #10 (permalink)
Elite Member
Frankfurt+Germany
 
Futures Experience: Intermediate
Platform: Ninja Trader, esignal
Broker/Data: IB
Favorite Futures: futures, options, stocks
 
Posts: 14 since May 2013
Thanks: 2 given, 0 received


@shodson
very interesting. I would like to code my strategy in the same structure. Could you please explain your syntax a bit more detailed.

Would be highly appreciate your help.

guw75



shodson View Post
I would approach it differently...

I would create boolean properties like

 
Code
bool PriceMovedUp { get { return Close[0] > Close[1]; } }
bool AboveMA { get { return Close[0] > SMA(200)[0]; } }
(calm down literal 'net, I know this it not optimized, just trying to show a point...)

then in your OnBarUpdate() you just stack together your predicates (true/false conditions) in easy-to-follow English

 
Code
if (PriceMovedUp && AboveMA)
    EnterLong();


Another approach would be to track a score of a setup. So for example if you have 8 possible conditions you like to look at, and if 6 pass then you take a trade. So when each condition is valid, add +1 to your score. This is one way you can layer on more and more conditions without adding a bunch of unmanageable if/then permutations.

 
Code
int score = 0;
if (PriceMovedUp) score++;
if (AboveMA) score++;

if (score >= 2)
    EnterLong();

To me, readability is very important, because code can grow and become very complex really quickly. In my opinion OnBarUpdate() needs to be the most English-reading code you write, because these are the core rules of your strategy. The gory/technical details behind each command and condition can be defined elsewhere, but OnBarUpdate() needs to be your most coarse-grained part of your strategy/indicator to keep your sanity when modifying and maintaining your strategy.

For example, here is a strategy I've been trading live for years: my gap fading strat. This is the OnBarUpdate() method. The whole strategy is almost 700 lines long, but I can open this open and quickly refresh my memory about how it works just by looking at OnBarUpdate() even though I haven't looked at this code in a long time.

 
Code
protected override void OnBarUpdate()
{
	if (TimeToDecide)
	{
		if (ShouldFadeGap)
		{
			if (GapIsBigEnough)
				FadeGap();
			else
				DontFadeGap();
		}
		else if (ShouldFadeExtendedTarget)
			FadeExtendedTarget();
		else
			DontFadeGap();
	}
	else if (_faded)
	{
		ManageTrade();
	}
}


Reply With Quote

Reply



futures io > > > > Boolean Flag help needed (strategy)

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
Using SuperTrend for trailing stop in a strategy - help needed DarrenH NinjaTrader Programming 16 September 29th, 2017 11:03 PM
Flag/Pennant Patterns bellair NinjaTrader 6 February 16th, 2016 02:26 PM
Programmer needed for Renko Chart strategy ashtheace Sierra Chart Programming 10 July 4th, 2012 10:42 PM
Swing Strategy help needed! prisonbreaker82 NinjaTrader Programming 6 April 16th, 2012 01:28 AM
NT7 Strategy/Strategies Needed Slipknot511 NinjaTrader Programming 8 August 22nd, 2010 02:39 AM


All times are GMT -4. The time now is 03:19 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.13 seconds with 20 queries on phoenix via your IP 54.226.172.30