Filter switch - NinjaTrader Programming | futures io social day trading
futures io futures trading


Filter switch
Updated: Views / Replies:1,170 / 9
Created: by seeker 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 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
 

Filter switch

  #1 (permalink)
Elite Member
Germany
 
Futures Experience: Intermediate
Platform: NT
Favorite Futures: ES,6E
 
seeker's Avatar
 
Posts: 21 since Mar 2012
Thanks: 73 given, 2 received

Filter switch

Hi programmers,

in order to test various trendfilters within my strategy (condition1 && condition2 && ...), I would like to be able to activate/deactivate them in the strategy menu (without having to change the code everytime).

So Im looking for the best way to integrate a bool for each one to switch it on and off.
Can anyone help me please?

Thank you,
seeker

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)
Fiddler
Nashville, TN
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IB
Favorite Futures: NQ ES
 
Posts: 468 since Feb 2011
Thanks: 323 given, 542 received


I believe that this elite thread will give you some ideas. There would be multiple ways to implement.

Reply With Quote
 
  #4 (permalink)
Elite Member
Germany
 
Futures Experience: Intermediate
Platform: NT
Favorite Futures: ES,6E
 
seeker's Avatar
 
Posts: 21 since Mar 2012
Thanks: 73 given, 2 received

Thank you monpere and Luger,

I will try this.
Btw. I forgot to mention, the goal is not only to activate the several filters separately, but also in combination (for instance 2 + 3 + 5 are working - whatever I select in the menu).

seeker

Reply With Quote
 
  #5 (permalink)
Fiddler
Nashville, TN
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IB
Favorite Futures: NQ ES
 
Posts: 468 since Feb 2011
Thanks: 323 given, 542 received

That really does add complexity, I don't think I realized the scope of your plan with my first post.

First if you plan to use the optimizer then use 0/1 instead of true/false since the optimizer does not work on booleans. Second I envision a structure like this:

Parameter screen:
Filter1 = Input 0 or 1 here
Filter2 = Input 0 or 1 here
Filter3 = Input 0 or 1 here


Now in the actual code each condition&& will include an ||. In case you did not know || = OR. Below is pseudo-code with an example.

Example: You want to test with filters 1 & 3 active. Ignoring filter 2.
Parameter Input
Filter1 = 1
Filter2 = 0
Filter3 = 1

 
Code
if ((trigger = go) &&
((Filter1condition = go) || (Filter1 = 0)) &&
((Filter2condition = no go) || (Filter2 = 0)) &&
((Filter3condition = go) || (Filter3 = 0)) 
{
Enter Trade
}
Basically, when evaluating, either the filter condition has to evaluate as true OR the filter has to be turned off to continue down the if statement. The example above would enter the trade because filter2, although in a no trade state, was turned off.

Reply With Quote
The following user says Thank You to Luger for this post:
 
  #6 (permalink)
Elite Member
Bala, PA, USA
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Mirus, IB
Favorite Futures: SPY, Oil, Euro
 
monpere's Avatar
 
Posts: 1,858 since Jul 2010
Thanks: 300 given, 3,276 received


seeker View Post
Hi programmers,

in order to test various trendfilters within my strategy (condition1 && condition2 && ...), I would like to be able to activate/deactivate them in the strategy menu (without having to change the code everytime).

So Im looking for the best way to integrate a bool for each one to switch it on and off.
Can anyone help me please?

Thank you,
seeker

When I want complex rules to be parameterized, I use string matching, and I can change the rule by changing the regular expression in a string parameter. You can apply very different and complex rules without changing the code:

string chosen_filters = "(Trending.*Reversal)"; //### default to Bar Reversal in a trend

void OnBarUpdate () {

string marketState="";
if ( ...Trending ...) marketState += "Trending ";
if ( ...MACD condition ...) marketState += "MACD ";
if ( ...RSI condition ...) marketState += "RSI ";
if ( ...Bar reversal ...) marketState += "Reversal ";
if ( ...Other condition ...) marketState += "Other ";

if ( Regex.Match(marketState, chosen_filters).Success {
//### Take the trade
}

}

Now I can go into the Indicator parameters window and change chosen_filters to:

chosen_filters: "(RSI|Reversal)" ---> Bar Revesal or RSI condition met
chosen_filters: "(Trending.*MACD.*Reversal)" ---> Trending and MACD condition and Bar reversal
chosen_filters: "RSI.*Reversal" ---> RSI condition with a Bar reversal
chosen_filters: "Reversal" ---> Just Bar reversals
chosen_filters: "Trending.*RSI.*Reversal" ---> Trending RSI Reversals
chosen_filters: "Trending RSI Reversal" ---> Trending RSI Reversal ONLY, but not if MACD condition is met

or any complex condition involving unlimited AND's, OR's etc, limited only by your proficiency with regular expressions.


Last edited by monpere; July 28th, 2012 at 06:00 PM.
Reply With Quote
The following 2 users say Thank You to monpere for this post:
 
  #7 (permalink)
Elite Member
Germany
 
Futures Experience: Intermediate
Platform: NT
Favorite Futures: ES,6E
 
seeker's Avatar
 
Posts: 21 since Mar 2012
Thanks: 73 given, 2 received

Thank you Luger ...

looks very plausible.
However, since Ive just started learning ninjascript, I dont know how to use 1/0 instead of a bool (true/false) to get a switch within the menu. Could you please explain it with a sample?


... and monpere,

looks very interesting, although Im not quite sure if I will get baked this. Im afraid I will have to learn a bit before ...

Thanks again,
seeker

Reply With Quote
 
  #8 (permalink)
Fiddler
Nashville, TN
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IB
Favorite Futures: NQ ES
 
Posts: 468 since Feb 2011
Thanks: 323 given, 542 received

Those variables that you had set as booleans, just need to be set as integers (int).

In the "Variables" region:

 
Code
private int filter1 = 0;
Way down at the bottom, there is a "Properties" region that you will have to expand:
 
Code
        [Description("")]
        [GridCategory("Parameters")]
        public int Filter1
        {
            get { return filter1; }
            set { filter1 = Math.Max(0, value); }
        }
You will want a section like that for each of the filter variables. Do make note that the Public variable starts with a capital letter, and the others do not, including the private one that was initialized in the "Variable" region.

Reply With Quote
The following user says Thank You to Luger for this post:
 
  #9 (permalink)
Elite Member
Germany
 
Futures Experience: Intermediate
Platform: NT
Favorite Futures: ES,6E
 
seeker's Avatar
 
Posts: 21 since Mar 2012
Thanks: 73 given, 2 received

Ok, thats quite simple - thanks a lot,
seeker

Reply With Quote
 
  #10 (permalink)
Elite Member
Wrocław, Poland
 
Futures Experience: Intermediate
Platform: NinjaTrader, Racket
Favorite Futures: Ockham's razor
 
gregid's Avatar
 
Posts: 651 since Aug 2009
Thanks: 321 given, 605 received


There were already few valid examples on how to achieve this.

Attached is sample strategy using ternary operators for filtering between conditions, e.g.:

 
Code
if (conditionCounter > 0
    && (useCond01 == 0 ? true : CrossAbove(SMA(v01),SMA(v02),v03))  //enter condition after the colon ":"
    && (useCond02 == 0 ? true : (SMA(v04)[v05] > SMA(v06)[v07]))  //enter condition after the colon ":"
    && (useCond03 == 0 ? true : true)  //enter condition after the colon ":"
)

Together with conditionCounter (which you could achieve simpler than I did by using reflection and simply add all values of useCondXX) you are ready to use it also for optimization and let NT show you which combination of conditions is beneficial for your strategy

Attached Files
Register to download File Type: zip g3ConditionFilter.zip (4.0 KB, 20 views)
Reply With Quote
The following user says Thank You to gregid for this post:

Reply



futures io > > > > > Filter switch

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
switch parameter enum Q baberg NinjaTrader Programming 4 September 23rd, 2013 07:06 PM
Do you ever switch time periods? drw112 Traders Hideout 7 November 6th, 2012 04:53 AM
Switch Statement DonStar AmiBroker 7 August 20th, 2012 04:15 PM
Help : Method + Switch wkmetal NinjaTrader Programming 3 October 25th, 2010 05:51 AM
Is it safe to switch to Ninja 7 yet ? markbbn Traders Hideout 13 May 31st, 2010 04:33 PM


All times are GMT -4. The time now is 11:42 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.12 seconds with 20 queries on phoenix via your IP 54.82.81.154