

为什么到这下一根K线 这个变量就归0了?
代码如下Params
Numeric BH(30);
Numeric dh(40);
Numeric lot(0);
Numeric FastLen(60); // 分钟线
Numeric SlowLen(30); //分钟
Numeric NomLen(20); //日线
Numeric NomL(10); //10日高低点
Numeric Ch(5); //前多少根日线
Numeric Length(100); //多少根分钟线
Numeric signbuy(0);
Numeric signsell(0);
Numeric ReBar(200);
Numeric TrailingStart1(5); // 声明变量TrailingStart1,初始值为50,这是止盈启动设置1。
Numeric TrailingStart2(15); // 声明变量TrailingStart2,初始值为80,这是止盈启动设置2。
Numeric TrailingStart3(30);
Numeric TrailingStop1(1); // 声明变量TrailingStop1,初始值为30,这是真正跟踪止盈设置1。
Numeric TrailingStop2(5); // 声明变量TrailingStop2,初始值为20,这是真正跟踪止盈设置2。
Numeric TrailingStop3(15);
Numeric W(3.0);
Vars
Numeric SurgeHigh(0);
Numeric SurgeLow(0);
Numeric NextHigh(0);
Numeric NextLow(0);
Bool BreakevenActivated(false); // ← 全局状态变量(替代 static)
Bool isBottomFractal(False);
Bool isTopFractal(False); // 是否出现顶分型
Numeric MinPoint(0); // 声明变量MinPoint,一个最小变动单位,也就是一跳。
Numeric MyEntryPrice(0); // 声明变量MyEntryPrice,英文好的,看英文意思都知道的,开仓价格,本例是开仓均价,也可根据需要设置为某次入场的价格。
Series<Numeric> FastMA; // 快速均线
Series<Numeric> SlowMA; // 慢速均线
Numeric NomMA;
Bool ShortBE(false);
Numeric ShortSL(0); Series<Numeric> sig(1);
Series<Numeric> CCC;
Series<Numeric> ReEntryCount; // 跟踪止损后记录BAR序号
Numeric MyExitPrice; // 声明变量MyExitPrice,平仓价格。
Series<Numeric> ATR;
Series<Numeric> StopPri; //跟踪止损价
Series<Numeric> StopLPri;
Series<Numeric> stopwin;
Series<Numeric> HighValue; //多头进场之后的盈利峰值价
Series<Numeric> AF; //跟踪Acceleration
Series<Numeric> HighestAfterEntry; //声明序列变量HighestAfterEntry,开仓后出现的最高价。
Series<Numeric> LowestAfterEntry; //声明序列变量LowestAfterEntry,开仓后出现的最低价。
Numeric StopPrice(0);
Series<Bool> Condition1(False);
series<Bool> Yun(False);
Numeric StopATR;
Numeric HH;
Numeric HHH; // 最近N根BAR的高点
Numeric B1;
Numeric B2;
Numeric B3;
Numeric B4;
Numeric B5;
Numeric B6;
Numeric B7;
Numeric B8;
Numeric B9;
Numeric B10;
Numeric BigVol;
Numeric BigV; // 最近N根BAR的低
Numeric DDH;
Numeric Bigbar;
Bool IsExcludedTime(false);
Bool IsSurgeBar(false);
Bool LastBarIsSurge(false);
Bool SurgeProcessed(false);
Series<Numeric> PPP;
Series<Numeric> LD;
Series<Numeric> op;
Series<Numeric> HD;
Series<Numeric> ll;
Series<Numeric> hhd;
Series<Bool> shang; //锤子线阳
Series<Bool> xia;// 吊头线阴
// Series<Bool> Condition1; // 条件1
// Series<Bool> Condition2; // 条件2
Numeric MyRange; //K线幅度
Numeric LongSL(0);
Numeric StopLossPrice(0);
Bool LongBE(false);
Events
OnInit()
{ Array<Numeric> timepoint;
timepoint[0] = 0.145950;
SetTriggerBarClose(timepoint);
}
OnBar(ArrayRef<Integer> indexs)
{
HD=Highest(high[1],dh);
LD=Lowest(Low[1],dh);
Commentary("B1="+Text( B1));
Commentary("ReEntryCount="+Text(ReEntryCount));
Commentary("BigV="+Text(BigV));
Commentary("op="+Text(op));
MinPoint = MinMove*PriceScale;//固定的最小跳动价公式。
/* If(BarsSinceEntry>0 And MarketPosition==1 AND VOL >0 and Time >=0.1331 And close <=LD AND TIME <=0.1500 ) // 有多仓的情况下。
{Sell(0,LD);
}
If(BarsSinceEntry>0 and MarketPosition==-1 AND VOL >0 And Time >=0.1331 And close >=HD AND TIME <=0.1500 )
{BuyToCover(0,HD);}*/
//
}
OnBarClose(ArrayRef<Integer> indexs)
{
if(vol[1]>=2*vol[2] and vol[1] >vol*2 and vol[1]>=2*NthHigher(Vol, 35, 3))
{
BigV= NthHigher(Vol, 35, 1);//巨量的定义
hh=Highest(high,3);
ll=Lowest(low,3);
}
if(time!=0.0900 and time!=0.2100 and time!=0.1330 )
{B1 = NthHigher(Vol, 1000, 1);
B2 = NthHigher(Vol, 1000, 2);
B3 = NthHigher(Vol, 1000, 3);
B4 = NthHigher(Vol, 1000, 4);
B5 = NthHigher(Vol, 1000, 5);
B6 = NthHigher(Vol, 1000, 6);
B7 = NthHigher(Vol, 1000, 7);
B8 = NthHigher(Vol, 1000, 8);
B9 = NthHigher(Vol, 1000, 9);
B10 = NthHigher(Vol, 1000, 10);
BigVol=(B1+B2+B3+B4+B5+B6+B7+B8+B9+B10)/10;} //巨量的最低标准
if(bigv>=BigVol and vol <=0.4*vol[1] and time!=0.0900 and time!=0.0901 and time !=0.1300 and time!=0.1331 and time!=0.2100 and time!=0.2101 )
{if(low<close[5] AND MarketPosition==0)
{ buy(0,close);}
if(high>close[5] AND MarketPosition==0)
{SellShort(0,close);}
}
range[1:1]
{
isBottomFractal =
(Low[1] < Low[2]) And (Low[1] < Low[0]) And // 中间最低
(High[1] < High[2]) And (High[1] < High[0]); // 中间最高也更低(严格底分型)
isTopFractal =
(High[1] > High[2]) And (High[1] > High[0]) And // 中间最高
(Low[1] > Low[2]) And (Low[1] > Low[0]);
} // 中间最低也更高(严格顶分型)
// 触发止损
Numeric ProfitPercent = 0;
// 计算盈利比例
if (MarketPosition == 1) // 多单
{ProfitPercent = (Close - EntryPrice) / EntryPrice * 100;}
if(MarketPosition == -1)
{ ProfitPercent = (EntryPrice - Close) / EntryPrice * 100;}
Numeric BreakevenLevel = 0.1 * W;
// 触发保本
if ( ProfitPercent >= BreakevenLevel)
{
StopLossPrice=AvgEntryPrice;
BreakevenActivated = true;
}
// 计算止损价
if (BreakevenActivated = false and MarketPosition == 1) // 多单
{
StopLossPrice = ll - MinMove;
}
if(BreakevenActivated = false and MarketPosition == -1)
{
StopLossPrice = HH + MinMove;
}
Commentary("StopLossPrice="+Text(StopLossPrice));
Commentary("ll="+Text(ll));
// 止损平仓(手数=0 表示全部)
if (MarketPosition == 1 && Close <= StopLossPrice and BarsSinceEntry>5)
{ Sell(0, CLOSE);
// BreakevenActivated = false; // 重置状态
PlotString("止损", "SL", Red);
}
If (MarketPosition == -1 && Close >= StopLossPrice and BarsSinceEntry>5) // 平所有多单
{ BuyToCover(0, CLOSE);
BreakevenActivated = false; // 重置状态
PlotString("止损", "SL", Red); } // 平所有空单
If (MarketPosition == -1 And DATA1.isBottomFractal and BarsSinceEntry>1)
{BuyToCover(0, CLOSE); } //
If (MarketPosition == 1 And DATA1.isTopFractal and BarsSinceEntry>1 )
{
Sell(0, Close);
}
If(BarsSinceEntry>0 And MarketPosition==1 AND VOL >0 And (time >= 0.1457 AND TIME <0.1500) or (time>=0.2257 and time<0.2300) or (time>=0.0227 and time<0.0230)) // 有多仓的情况下。
{Sell(0,Close);
}
If(BarsSinceEntry>0 and MarketPosition==-1 AND VOL >0 And (time >= 0.1457 AND TIME <0.1500) or (time>=0.2257 and time<0.2300) or (time>=0.0227 and time<0.0230))
{BuyToCover(0,Close);}
}
普通变量本来就没有传递特性
看一下零基础课程里关于数据类型的特征内容
麻烦稍微打几个字告之一下该怎么做,否则我得看几个小时视频也不一定会啊
我是很想告诉你该怎么做,但是你也没说明你想达成什么效果啊?
你问的是为什么这个变量到了下一根就变成0了,我的回答是因为你定义的是普通变量。这个回答不对吗?
提问的时候是不是应该把问题明确一下?
如果你是想说,怎样让变量能够在bar之间继承或者传递内容,那回答就是定义成序列变量。
你的问题我也回答过很多次了,全都是零基础里的内容。我应该很早就给你发过视频链接了,都是很久很久以前的事情了。你但凡看过一次,都不会再有这种问题。这套零基础课程内容很多学员看过都说简单易懂,你如果看过视频还是看不懂,那我很难用语言再告诉你应该是什么样