• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.
      https://ninjatrader.com/support/foru...040#post786040
      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:
          A. Declare variables
          bool (initialiize to false): resetCount, condition1, condition2, condition3, condition4;
          int enterCount = 0;
          
          B. Process in OnBarUpdate()
          1. resetCount: /*evaluate reset conditions; set true if met*/
          2. condition1: /*evaluate setup and if met, increment enterCount*/
          3. condition2: /*evaluate setup and if met, increment enterCount*/
          4. condition3: /*evaluate setup and if met, increment enterCount*/
          5. condition4: /*evaluate setup and if met, increment enterCount*/
          
          6. if resetCount is true, set enterCount to zero and return (? do you also want to set false condition(s) 1 to 4 fields ?);
          7. if resetCount is 4, 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 Steve L, Today, 03:50 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by kherzfeldt6953, Today, 06:11 PM
          0 responses
          1 view
          0 likes
          Last Post kherzfeldt6953  
          Started by Newtrader101, Today, 06:01 PM
          0 responses
          2 views
          0 likes
          Last Post Newtrader101  
          Started by Newtrader101, Today, 05:32 PM
          0 responses
          4 views
          0 likes
          Last Post Newtrader101  
          Started by ntbone, Yesterday, 11:53 AM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X