Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to... 4 condition strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to... 4 condition strategy

    I'm working on a 4 condition strategy to enter into the market.. long or short... These 4 conditions could all happen simultaneously or happen one at a time until all are true to trigger an entry. I do believe that I will need variables to make this strategy work but I'm not familiar with working with variables.. Could someone point me in the right direction, or post an example of what I'm looking to do..

    Thanks
    Michael

    #2
    Hello, you could increment a variable every time one of your conditions is true.

    When that variable reaches value 4 then execute a trade.

    your code could be something like this

    int var1, var2, var3, var4, total;

    if ( Close[0] > SMA(10)[0])
    var1 = 1;
    else
    var1 = 0;

    if ( Close[0] > SMA(20)[0])
    var2 = 1;
    else
    var2 = 0;

    if (Close[0] > SMA(50)[0])
    var3 = 1;
    else
    var3 = 0

    if (Close[0] > SMA(200)[0]
    var4 = 1;
    else
    var4 = 0;

    total = var1 + var2 + var3 + var4;

    if (total == 4) EnterLong();

    Comment


      #3
      Hello Mykro,

      It is possible to have multiple conditions in a condition set.

      Are you building this with the strategy builder?

      Click add to add another condition to the same condition set.

      Below is a link to a forum post with helpful information about getting started with NinjaScript. I recommend starting with the Strategy Builder 301 video.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by im197 View Post
        Hello, you could increment a variable every time one of your conditions is true.

        When that variable reaches value 4 then execute a trade.

        your code could be something like this

        int var1, var2, var3, var4, total;

        if ( Close[0] > SMA(10)[0])
        var1 = 1;
        else
        var1 = 0;

        if ( Close[0] > SMA(20)[0])
        var2 = 1;
        else
        var2 = 0;

        if (Close[0] > SMA(50)[0])
        var3 = 1;
        else
        var3 = 0

        if (Close[0] > SMA(200)[0]
        var4 = 1;
        else
        var4 = 0;

        total = var1 + var2 + var3 + var4;

        if (total == 4) EnterLong();
        Will only work if all conditions are simultaneously valid. Not quite what the OP stated as his want.

        Comment


          #5
          Originally posted by Mykro View Post
          I'm working on a 4 condition strategy to enter into the market.. long or short... These 4 conditions could all happen simultaneously or happen one at a time until all are true to trigger an entry. I do believe that I will need variables to make this strategy work but I'm not familiar with working with variables.. Could someone point me in the right direction, or post an example of what I'm looking to do..

          Thanks
          Michael
          First, write out what you want to do in English/pseudocode.
          Then translate that into C# code.

          Here is some pseudocode that you can use as a start:
          Code:
          [B]A. Declare variables[/B]
          bool (initialiize to [I]false[/I]): resetCount, condition1, condition2, condition3, condition4;
          int enterCount = 0;
          
          [B]B. Process in OnBarUpdate()[/B]
          1. resetCount: /*evaluate reset conditions; set [I]true[/I] if met*/
          2. condition1: /*evaluate setup and if met, increment [I]enterCount*[/I]/
          3. condition2: /*evaluate setup and if met, increment [I]enterCount[/I]*/
          4. condition3: /*evaluate setup and if met, increment [I]enterCount*[/I]/
          5. condition4: /*evaluate setup and if met, increment [I]enterCount*[/I]/
          
          6. if [I]resetCount[/I] is [I]true[/I], set [I]enterCount[/I] to zero and return (? do you also want to set [I]false [/I]condition(s) 1 to 4 fields ?);
          7. if [I]resetCount is 4[/I], enter trade
          You may also want to set resetCount to false, enterCount to zero, and set false condition(s) 1 to 4 fields, after you enter a trade, so that you do not have multiple entries to the same set being satisfied, unless that is actually what you seek. In which case, you have to make alternative arrangements to handle your multiple entries.
          Last edited by koganam; 08-19-2019, 09:38 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          69 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X