如何在C#中建立排除条件

问题描述 投票:-1回答:1

我正在使用C#编写交易系统代码。我的大部分逻辑是,如果某些条件同时发生,请输入购买。

但是在某些情况下,我需要一个排除逻辑:如果某些情况同时发生,那就不要购买。

我试图设置一个名为Falling1 = true;的变量,并在同时发生非购买条件时设置了Falling1=false;

然后在我的购买逻辑中,我需要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");
        }
    }
}

[问题是系统似乎无法识别// 01-crossabovelower中的&& (Falling1=true),我想我的代码中存在一些结构问题。

c# quantitative-finance quantitative
1个回答
2
投票

您想要

  && (Falling1==true)

您编写作业的方式]

© www.soinside.com 2019 - 2024. All rights reserved.