max和min在这里怎么取值不对?

                highsinceentry = Max(highsinceentry,High);

                lowsinceentry = Min(lowsinceentry,low);

请教老师, 我本意用这两行代码取成交后价格的最大值和最小值,但调试commentary输出发现价格没有锁定在最高/最低价一直在变化时什么原因?

//------------------------------------------------------------------------

// 简称: demo_bigsmall

// 名称: 大小周期结合

// 类别: 策略应用

// 类型: 用户应用

// 输出: Void

//------------------------------------------------------------------------

Params

  //此处添加参数

   //Numeric millsecs(1000);

   Numeric stoplossN(2);

   Numeric  breakevenN(2);

   Numeric  trailingstopN1(5);

   Numeric trailingstopN2(8);

   Numeric  takeprofitN(10);

   Numeric  diffN(12);

   Numeric  deaN(26);

   Numeric macdN(9);

   Numeric  atrN(10);

   Numeric maN(60);

   

Vars

   //此处添加变量

  // Numeric avg;

   //Global Integer timerId;

   Series<Numeric>  Diff;

   Series<Numeric>  Dea;

   Numeric MACDValue;

   series<Numeric> highsinceentry;

   Series<Numeric> lowsinceentry;

   Numeric Atr;

   Numeric losses;

   Numeric profits;

   Numeric myentryprice;

   Numeric trailingprice;

   Series<Numeric> MA;

   Plot  plt_macd;

   Plot  plt_atr;

   Bool con_crossover;

   Bool StopLoss(False);

   Bool StopProfit(False);

   Bool breakeven(False);

   Bool trailingstop1(False);

   Bool trailingstop2(False);

   Numeric stoplossline;

   Numeric takeprofitline;

   Numeric breakevenline;

   Numeric trailingstopline1;

   Numeric trailingstopline2;

   Numeric myexitprice;


Events

   OnInit()

   {

        SubscribeBar(Symbol,"1m",BeginDateTime);//新增数据源

    }

  //Bar更新事件函数,参数indexs表示变化的数据源图层ID数组

   OnBar(ArrayRef<Integer> indexs)

   {

     

        Range[1:1]

   {

       Atr = AvgTrueRange(atrN);

       Commentary("Atr:"+Text(Atr));

   

       Data[0].MA = Data[0].AverageFC(Data[0].Close, maN); //计算30分钟指标

       Data[1].PlotNumeric("MA", Data[0].MA[1]);    //在5分钟周期中引用30分钟指标

       Data[0].PlotNumeric("MA", Data[0].MA[1]);    //在30分钟上同时显示指标

   

       Data[1].Diff = XAverage( Close, diffN ) - XAverage( Close, deaN ) ;

       Data[1].Dea = XAverage(Diff, macdN);

       Data[1].MACDValue = 2 * (Diff - Dea);

   

       Data[1].con_crossover = CrossOver(Data[1].Diff[1], Data[1].Dea[1] );

   

       If(MarketPosition == 0 And Data[1].Close[1] > Data[0].MA ) //多单进场

       {

           If(Data[1].Diff[1] < 0 And Data[1].Dea[1] < 0 And Data[1].con_crossover)

           {

                Buy(1, Max(Close[1],Open));            

           }

       }

                myentryprice = EntryPrice;//真实成交价???

                highsinceentry = EntryPrice;

                lowsinceentry = EntryPrice;

                highsinceentry = Max(highsinceentry,High);

                lowsinceentry = Min(lowsinceentry,low);

       If(Close < myentryprice)

       {

           losses = myentryprice-lowsinceentry;

            If(losses > stoplossN * Atr) //止损

            {

              myexitprice = myentryprice - stoplossN * Atr;

              sell(0,myexitprice);

              StopLoss = True;

            }

       }

     

       If(Close> myentryprice)//跟踪盈利

       {

           If(highsinceentry > myentryprice + takeprofitN * Atr ) //止盈

           {

               myexitprice = takeprofitN * Atr;

               sell(0,myexitprice);

               StopProfit = True;

           }

           If(highsinceentry > myentryprice + trailingstopN2 * Atr) //跟踪止盈8-5ATR

           {

               lowsinceentry = myentryprice + trailingstopN2 * Atr;

               lowsinceentry = Min(lowsinceentry,Low);

                If(lowsinceentry <  myentryprice + trailingstopN1 * Atr)

               {

                   myexitprice =  myentryprice + trailingstopN1 * Atr;

                   sell(0,myexitprice);

                   trailingstop2 = True;

               }

           }

            If(highsinceentry > myentryprice + trailingstopN1 * Atr) //跟踪止盈5-3ATR

           {

               lowsinceentry = myentryprice + trailingstopN1 * Atr;

               lowsinceentry = Min(lowsinceentry,Low);

               If(lowsinceentry <  myentryprice + breakevenN * Atr)

               {

                   myexitprice =  myentryprice + breakevenN * Atr;

                   sell(0,myexitprice);

                   trailingstop1 = True;

               }

           }

            If(highsinceentry > myentryprice + breakevenN * Atr) //跟踪止盈3-成本

           {

               lowsinceentry = myentryprice + breakevenN  * Atr;

               lowsinceentry = Min(lowsinceentry,Low);

               If(lowsinceentry < myentryprice)

               {

                   myexitprice = myentryprice;

                   sell(0, myexitprice);

                   breakeven = True;

               }

           }

       }

       If(myentryprice > 0)

       {

           stoplossline = myentryprice - stoplossN * Atr;

           takeprofitline = myentryprice + takeprofitN*Atr;

           breakevenline = myentryprice + breakevenN*Atr;

           trailingstopline1 = myentryprice + trailingstopN1*Atr;

           trailingstopline2 = myentryprice + trailingstopN2*Atr;

           PlotNumeric("stoplossline",stoplossline);

           PlotNumeric("takeprofitline",takeprofitline);

           PlotNumeric("breakevenline",breakevenline);

           PlotNumeric("trailingstopline1",trailingstopline1);

           PlotNumeric("trailingstopline2",trailingstopline2);

           //Commentary("stoplossline:" + Text(stoplossline));

       }

       

       //String Stoploss = IIFString(True, "True", "False");

       Commentary("highsinceentry:"+Text(highsinceentry));

       Commentary("lowsinceentry:"+Text(lowsinceentry));

       Commentary("stoploss:" + IIFString(Stoploss, "True", "False"));

       Commentary("StopProfit:" + IIFString(StopProfit, "True", "False"));

       Commentary("breakeven:" + IIFString(breakeven, "True", "False"));

       Commentary("trailingstop1:" + IIFString(trailingstop1, "True", "False"));

       Commentary("trailingstop2:" + IIFString(trailingstop2, "True", "False"));

           

       }  

   

   }


   -----------------------------------------------------------------------

// 编译版本    2025/12/21 213939

// 版权所有    gaoxuetai

// 更改声明    TradeBlazer Software保留对TradeBlazer平台

//            每一版本的TradeBlazer策略修改和重写的权利

//------------------------------------------------------------------------

buy怎么选择max,min
在这里找优化
Min(Min(Min(Open[2],Open[3]),Min(Open[4],Open[5])),Open[6])有没有简易写法
Max函数
)挎号不对,是照着视频例子看的。怎么就不对呢
序列数组变量如何按索引取值
发单和代码不对应
跳空开仓数不对,怎么办?
序列变量取值问题
Buy(1, Max(my_exitprice, Open));

你可以证明一下这个函数有问题,而不是你的逻辑有问题

你代入的参数有变量,自然结果也是可变的。


比如你问为什么变化,lowsinceentry = Min(lowsinceentry,Low);

lowsinceentry 这个首先就是你的变量一定是变化的

然后是low,low也是变化的。