0

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 not buy.

I tried to set a variable named Falling1 = true; and set Falling1=false; while the not buy conditions occur at the same time.

And then in my buy logic I need Falling1=true;.

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;
        }
        // Set 2
// 01-crossabovelower
        if (((CrossAbove(JurbolBBmacd1.Macd, JurbolBBmacd1.BollingerLower, 3))
&& (RSI1.Avg[0] < 67)&& (Falling1=true)
        {
            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.

williamfaith
  • 247
  • 2
  • 4
  • 9
  • 3
    you are asking people to help you with code, it is polite to indent the code to make it more readable – Hogan Sep 25 '19 at 21:38
  • A NOT check that is AND connected is a exclusion check. AND and OR are short-circuiting: If one of the parts solves the operation unabiligiously (flase for a AND, true for a OR), the others are never even queried. There is also the Exclusive or or XOR. – Christopher Sep 25 '19 at 22:03
  • 2
    In addition to Hogan's answer, two notes: 1) Just use the value `Falling1`. It's already what you want. The comparison is overly verbose. 2) The accidental assignment could've been avoided entirely if you had used the value directly in the first place. – madreflection Sep 25 '19 at 22:05
  • Thank you so much!@madreflection and @Christopher and everyone! – williamfaith Sep 26 '19 at 01:21

1 Answers1

3

you want

  && (Falling1==true)

The way you wrote it you are doing an assignment

Hogan
  • 69,564
  • 10
  • 76
  • 117