Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to create an Analyzing condition through strategy builder

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

    #16
    Thank you for your reply.
    But it didn't help me.

    Let me show you my code:


    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class JJcrossCode : Strategy
    {
    private bool Falling1;
    ........

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "JJcrossCode";
    ......

    Falling1 = true;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    SetProfitTarget(@"Short", CalculationMode.Ticks, 20);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 7)
    return;

    // Set 1
    if ((Open[0] > Close[0])
    && (High[0] < High[1])
    && (Low[0] < Low[1]))
    {
    Falling1 = false;
    Draw.Text(this, @"Falling1", "", 0, 0);
    Console.WriteLine("Hello World!");
    }

    // Set 2
    if (
    // 01-crossabovelower
    ((CrossAbove(JurbolBBmacd1.Macd, JurbolBBmacd1.BollingerLower, 3))
    && (Times[0][0].TimeOfDay >= new TimeSpan(8, 30, 0))
    && (Times[0][0].TimeOfDay <= new TimeSpan(15, 0, 0))
    && (RSI1.Avg[0] < 67)
    && (Falling1=true)

    // 02-crossaboveuper
    || ((CrossAbove(JurbolBBmacd1.Macd, JurbolBBmacd1.BollingerUpper, 3))
    && (IsFalling(ParabolicSAR1) == false)
    && (IsFalling(AuSuperTrendU111.StopDot) == false)
    && (Times[0][0].TimeOfDay >= new TimeSpan(8, 30, 0))
    && (Times[0][0].TimeOfDay <= new TimeSpan(15, 0, 0))
    && (RSI1.Avg[0] < 67)
    && (IsFalling(Momentum1) == false)

    {
    EnterLong(Convert.ToInt32(Size), @"Long");
    }
    }


    The issue is that it seems the system can't recognize && (Falling1=true) in // 01-crossabovelower,I guess there are some structure issues in my code.

    Comment


      #17
      Hello williamzz,

      Once Falling1 is set to true in your code, it is never set to false ever again.

      How can the system fail to recognize '&& (Falling1=true)' if its never set to true?

      Are you printing the value of Falling1 to show that its true?

      My suggestion is that you set it to false on each new bar. I have demonstrated this with a video in post #17.
      However, from the code you have provided in post #18 shows you have decided not to take this advice and add this as the first set with no conditions.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Thank you for your reply.

        Sorry I didn't express clear about what I want.

        I'm coding a trading system using C#.Most of my logic is if some conditions occur at the same time,enter buy. But in some scenario,I need an exclude logic:if some conditions occur at the same time...


        Please help me check my stackover flow,I ask more clearer there.

        Thank you!

        Comment


          #19
          Hello williamzz,

          You will need to be familiar with C# operators in order to properly build these conditions. "=" is an assignment operator and "==" checks equality. It will also be necessary to use prints to observe what is being evaluated in each condition to ensure the code is written properly.

          While we do not provide programming education services, we do have light programming education material in the NinjaTrader 7 help guide. More robust C# educational materials can be found externally to NinjaTrader. Using the View Code button on the Strategy Builder can also help to learn the syntax by observing what the Strategy Builder generates.

          Basic Programming Concepts - https://ninjatrader.com/support/help...g_concepts.htm

          Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

          Debugging in the Strategy Builder - https://www.screencast.com/t/8uvjfM8h

          We look forward to being of further assistance.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          48 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
          66 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