Search code examples
c#quantitative-financequantitative

How to build a exclude condition in C#


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.


Solution

  • you want

      && (Falling1==true)
    

    The way you wrote it you are doing an assignment