NexusFi: Find Your Edge


Home Menu

 





Strategy: ignore parts entry condition (failing per bool)


Discussion in NinjaTrader

Updated
    1. trending_up 382 views
    2. thumb_up 4 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 2 attachments




 
Search this Thread

Strategy: ignore parts entry condition (failing per bool)

  #1 (permalink)
 
Renkotrader's Avatar
 Renkotrader 
Frankfurt, Hessen, Germany
 
Experience: Advanced
Platform: NinjaTrader 8
Broker: APEX & NinjaTrader Brokerage
Trading: 6E, 6J, CL, ES, FDAX, FGBL, GC, HG, NQ, RTY, SI, YM
Posts: 547 since May 2012
Thanks Given: 1,419
Thanks Received: 227

Hello strategy programmers,

I am having the situation, that I want in the parameter list switch on and off parts of my entry condition. But they are all linked with an AND ("&&"). So I cant use a bool with true or false for ignoring the part of the condition.

 
Code
Entry Long Example (with stupid conditions): it works!	
if
  (																		
    (aktivLong == true)
    && (Close[0] > High[1])
    && (CrossAbove(Close, Swing1.SwingHigh, 5))
    && ...
//    && (Close[1] > Close[2])
//    && (Close[2] > Close[3])
    && (Low[1] > Low[2])
    && (High[0] > Close[1])
    ...
  )
   {
     EnterLong(Convert.ToInt32(contracts), @"EntryLong");
   }

 
Code
Entry Long Example (with stupid conditions): it does not works!		
if
  (																		
    (aktivLong == true)
    && (Close[0] > High[1])
    && (CrossAbove(Close, Swing1.SwingHigh, 5))
    && ...
    && (Close[1] > Close[2] && activCondition1 == false)
    && (Close[2] > Close[3] && activCondition2 == true)
    && (Low[1] > Low[2])
    && (High[0] > Close[1])
    ...
  )
   {
     EnterLong(Convert.ToInt32(contracts), @"EntryLong");
   }

So my idea is, that I am using a "//"-button. But for that I am having no idea, how to solve or: is it possible to switch on and off from parameter list with the "//"?

It is possible to solve this - no matter, how complex a line (a condition from the set) is?

Thank you for your ideas

Best regards,
Renkotrader

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
Deepmoney LLM
Elite Quantitative GenAI/LLM
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
  #2 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,171
Thanks Received: 6,018

 
Code
private bool aktivLong = true; // A property to determine if you should enter long

private bool activCondition1 = true; // A property to determine if activCondition1 is active
private bool activCondition2 = true; // A property to determine if activCondition2 is active
private bool activCondition3 = true; // A property to determine if activCondition3 is active
// Define other condition functions that should be checked

private bool Condition1()
{
    return Close[0] > High[1];
}

private bool Condition2()
{
    return CrossAbove(Close, Swing1.SwingHigh, 5);
}

private bool Condition3()
{
    return Close[1] > Close[2];
}

// Define other condition functions as needed

protected override void OnBarUpdate()
{
    // Create a List<bool> to represent whether each condition should be evaluated
    List<bool> conditionEnabled = new List<bool>();

    // Set the conditionEnabled values based on your configuration
    conditionEnabled.Add(aktivLong); // This represents the aktivLong condition
    if (activCondition1) conditionEnabled.Add(Condition1());
    if (activCondition2) conditionEnabled.Add(Condition2());
    if (activCondition3) conditionEnabled.Add(Condition3());

    // Check if all conditions in the list are true
    // The .All() method returns true if all elements in the list satisfy 
    // the condition specified in the lambda expression.
    bool shouldEnterLong = conditionEnabled.All(condition => true);

    if (shouldEnterLong)
    {
        EnterLong(Convert.ToInt32(contracts), @"EntryLong");
    }
}

Renkotrader View Post
Hello strategy programmers,

I am having the situation, that I want in the parameter list switch on and off parts of my entry condition. But they are all linked with an AND ("&&"). So I cant use a bool with true or false for ignoring the part of the condition.

 
Code
Entry Long Example (with stupid conditions): it works!	
if
  (																		
    (aktivLong == true)
    && (Close[0] > High[1])
    && (CrossAbove(Close, Swing1.SwingHigh, 5))
    && ...
//    && (Close[1] > Close[2])
//    && (Close[2] > Close[3])
    && (Low[1] > Low[2])
    && (High[0] > Close[1])
    ...
  )
   {
     EnterLong(Convert.ToInt32(contracts), @"EntryLong");
   }

 
Code
Entry Long Example (with stupid conditions): it does not works!		
if
  (																		
    (aktivLong == true)
    && (Close[0] > High[1])
    && (CrossAbove(Close, Swing1.SwingHigh, 5))
    && ...
    && (Close[1] > Close[2] && activCondition1 == false)
    && (Close[2] > Close[3] && activCondition2 == true)
    && (Low[1] > Low[2])
    && (High[0] > Close[1])
    ...
  )
   {
     EnterLong(Convert.ToInt32(contracts), @"EntryLong");
   }

So my idea is, that I am using a "//"-button. But for that I am having no idea, how to solve or: is it possible to switch on and off from parameter list with the "//"?

It is possible to solve this - no matter, how complex a line (a condition from the set) is?

Thank you for your ideas

Best regards,
Renkotrader


Reply With Quote
Thanked by:
  #3 (permalink)
 
Renkotrader's Avatar
 Renkotrader 
Frankfurt, Hessen, Germany
 
Experience: Advanced
Platform: NinjaTrader 8
Broker: APEX & NinjaTrader Brokerage
Trading: 6E, 6J, CL, ES, FDAX, FGBL, GC, HG, NQ, RTY, SI, YM
Posts: 547 since May 2012
Thanks Given: 1,419
Thanks Received: 227


Hello trendisyourfriens,

thank you very much for your great idea!

I will test its later the day and then I will give you feedback.

Best wishes from a happy
Renkotrader

Started this thread Reply With Quote
Thanked by:
  #4 (permalink)
 
Renkotrader's Avatar
 Renkotrader 
Frankfurt, Hessen, Germany
 
Experience: Advanced
Platform: NinjaTrader 8
Broker: APEX & NinjaTrader Brokerage
Trading: 6E, 6J, CL, ES, FDAX, FGBL, GC, HG, NQ, RTY, SI, YM
Posts: 547 since May 2012
Thanks Given: 1,419
Thanks Received: 227

Hi trendisyourfriend,

I set your code in my test strategy. I am tinking, that I did its at best kind of doing, but so it does not work. To much trades is the result. The filter (on/off) does not work.

Fot this I changed the long entry - the short entry is original and works, so you can compare the resultat.

In the attachment you can find the file for analyzing.

I hope, we can solve this problem

Have a great day,
Renkotrader

Attached Files
Elite Membership required to download: ExampleActivFilter.cs
Started this thread Reply With Quote
  #5 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,171
Thanks Received: 6,018

I identified the problem. Here is the modified script.

I moved some of the lines around and the problem was with this command:
bool shouldEnterLong = conditionEnabled.All(condition => true);

which has become...

bool shouldEnterLong = conditionEnabled.All(condition => condition);

Attached Files
Elite Membership required to download: ExampleActivFilter.cs
Reply With Quote
Thanked by:
  #6 (permalink)
 
Renkotrader's Avatar
 Renkotrader 
Frankfurt, Hessen, Germany
 
Experience: Advanced
Platform: NinjaTrader 8
Broker: APEX & NinjaTrader Brokerage
Trading: 6E, 6J, CL, ES, FDAX, FGBL, GC, HG, NQ, RTY, SI, YM
Posts: 547 since May 2012
Thanks Given: 1,419
Thanks Received: 227

Good morning trendisyourfriend ,

thanks a lot for your great help!

I think, I had understooden the way of your solution to build the short version and the opposite: different exit conditions.

So the "key" for the entries is the direction = long or short (shouldEnterLong) (shouldEnterShort).

That means, that I am no more using a single entry signal and then some filters in my logic - I see its as a "paket" of conditions.

And the same I can do now with the stops: two oder three or four methodes and the "key" is using indicator stops. Here are "yes" or "no" possible, too. If i say "no", then a standard stop condition will take the job:

SetStopLoss(@"EntryShort", CalculationMode.Ticks, 60, false); (with a stop loss, who represents the maximum, that I want to loose as emergency stopp.

If I say "yes", the indicator stop will do the job and the "hard stop" will quit automatically.

So thank you very much, trendisyourfriend. Now one of my problems in programming is solved

Have a great Sunday,
Renkotrader

Started this thread Reply With Quote
Thanked by:




Last Updated on September 3, 2023


© 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