Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 CortexZenUSA, Today, 12:53 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by CortexZenUSA, Today, 12:46 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by usazencortex, Today, 12:43 AM
          0 responses
          5 views
          0 likes
          Last Post usazencortex  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          168 responses
          2,265 views
          0 likes
          Last Post sidlercom80  
          Started by Barry Milan, Yesterday, 10:35 PM
          3 responses
          12 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X