NexusFi: Find Your Edge


Home Menu

 





Filter switch


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Luger with 4 posts (2 thanks)
    2. looks_two seeker with 4 posts (0 thanks)
    3. looks_3 monpere with 2 posts (2 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 4,127 views
    2. thumb_up 5 thanks given
    3. group 4 followers
    1. forum 9 posts
    2. attach_file 1 attachments




 
Search this Thread

Filter switch

  #1 (permalink)
 
seeker's Avatar
 seeker 
Germany
 
Experience: Intermediate
Platform: NT
Trading: ES,6E
Posts: 21 since Mar 2012
Thanks Given: 76
Thanks Received: 2

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 Iīm 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

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
Better Renko Gaps
The Elite Circle
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #3 (permalink)
 Luger 
Nashville, TN
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: NQ ES
Posts: 468 since Feb 2011
Thanks Given: 323
Thanks Received: 543


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

Reply With Quote
  #4 (permalink)
 
seeker's Avatar
 seeker 
Germany
 
Experience: Intermediate
Platform: NT
Trading: ES,6E
Posts: 21 since Mar 2012
Thanks Given: 76
Thanks Received: 2

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

Started this thread Reply With Quote
  #5 (permalink)
 Luger 
Nashville, TN
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: NQ ES
Posts: 468 since Feb 2011
Thanks Given: 323
Thanks Received: 543

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
Thanked by:
  #6 (permalink)
 
monpere's Avatar
 monpere 
Bala, PA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus, IB
Trading: SPY, Oil, Euro
Posts: 1,854 since Jul 2010
Thanks Given: 300
Thanks Received: 3,371


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 Iīm 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.

Reply With Quote
Thanked by:
  #7 (permalink)
 
seeker's Avatar
 seeker 
Germany
 
Experience: Intermediate
Platform: NT
Trading: ES,6E
Posts: 21 since Mar 2012
Thanks Given: 76
Thanks Received: 2

Thank you Luger ...

looks very plausible.
However, since Iīve just started learning ninjascript, I donīt 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 Iīm not quite sure if I will get baked this. Iīm afraid I will have to learn a bit before ...

Thanks again,
seeker

Started this thread Reply With Quote
  #8 (permalink)
 Luger 
Nashville, TN
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: NQ ES
Posts: 468 since Feb 2011
Thanks Given: 323
Thanks Received: 543

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
Thanked by:
  #9 (permalink)
 
seeker's Avatar
 seeker 
Germany
 
Experience: Intermediate
Platform: NT
Trading: ES,6E
Posts: 21 since Mar 2012
Thanks Given: 76
Thanks Received: 2

Ok, thatīs quite simple - thanks a lot,
seeker

Started this thread Reply With Quote
  #10 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 since Aug 2009
Thanks Given: 320
Thanks Received: 623


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
Elite Membership required to download: g3ConditionFilter.zip
Reply With Quote
Thanked by:




Last Updated on July 30, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts