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

building complex conditions

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

    building complex conditions

    I am trying to build a simple strategy that uses a whole bunch of conditions or cases but I cannot seem to figure out how to program them togeather.

    The overview of the program is fairly simple, something like this.

    Case #1: Between 10:30 - 12:30am, if all market prices are above the 10min MA, then set case 1 = true.

    Case #2. If condition 1 = true, and time is between 12:30 - 2:30, if market price == 10min MA, then enter long

    I can program the simple if statements through the strategy wizard but I cannot seem to get the whole strategy working. Am I going about the whole process incorrectly??

    Also, any thoughts on how to build conditions (like I did in condition #1) based on OTHER markets (ie Use the SPY for condition 1 but then execute condition #2 or AAPL or something)

    Any thoughts would be greatly appreciated.

    #2
    You would need to work with user variables for the 'linking' of conditions together, here's a sample on this - http://www.ninjatrader-support2.com/...ad.php?t=15417

    BertrandNinjaTrader Customer Service

    Comment


      #3
      thanks bertrand for your quick reply

      i looked back at my code, and I did do exactly what you suggested, setting a variable to 0 or 1 (true or untrue as well) but I cant seem to get the strategy to work. Perhaps it has something to do with the fact that the "cases" involved are in different time periods.

      Here is a sample of my code

      Any ideas??

      // Condition set 1
      if (Low[0] >= EMA(14)[0]
      && ToTime(Time[0]) > ToTime(3, 15, 0)
      && ToTime(Time[0]) < ToTime(5, 16, 0))
      {
      Variable0 = 1;
      }

      // Condition set 2
      if (Variable0 == 1
      && ToTime(Time[0]) > ToTime(5, 15, 0)
      && ToTime(Time[0]) < ToTime(9, 17, 0)
      && Low[0] == EMA(14)[0])
      {
      EnterLong(DefaultQuantity, "");
      }

      // Condition set 3
      if (High[0] <= EMA(14)[0]
      && ToTime(Time[0]) > ToTime(4, 15, 0)
      && ToTime(Time[0]) < ToTime(5, 16, 0))
      {
      Variable1 = 1;
      }

      // Condition set 4
      if (Variable1 == 1
      && ToTime(Time[0]) > ToTime(5, 15, 0)
      && ToTime(Time[0]) < ToTime(9, 17, 0)
      && High[0] == EMA(14)[0])
      {
      EnterShort(DefaultQuantity, "");
      }

      Comment


        #4
        eurostoxx trader, that should not be the issue, if the condition in time1 is true it would set the variable and thus it stays set to this value until you set it otherwise...I would add Print statement to check that all variables have the values you would expect them to be - http://www.ninjatrader-support2.com/...ead.php?t=3418

        Next try another condition for the EMA entry, due to rounding it's unlikely the Close is exactly the EMA value so it may never trigger to enter.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ZeroKuhl, Yesterday, 04:31 PM
        4 responses
        28 views
        0 likes
        Last Post ZeroKuhl  
        Started by cupir2, Yesterday, 07:44 PM
        3 responses
        21 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by reynoldsn, Yesterday, 07:26 PM
        2 responses
        14 views
        0 likes
        Last Post reynoldsn  
        Started by MartinT, 05-17-2023, 06:00 AM
        18 responses
        173 views
        0 likes
        Last Post flybuzz
        by flybuzz
         
        Started by sgordet, Today, 05:24 AM
        2 responses
        21 views
        0 likes
        Last Post sgordet
        by sgordet
         
        Working...
        X