原本是在仓位等于0或者1的时候才开仓的,但是运行了发现不停开仓 ,根本不手0或1的影响?
Params
Numeric BH(60);
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);
Vars
series<Numeric> MinPoint(0); // 声明变量MinPoint,一个最小变动单位,也就是一跳。
Numeric MyEntryPrice(0); // 声明变量MyEntryPrice,英文好的,看英文意思都知道的,开仓价格,本例是开仓均价,也可根据需要设置为某次入场的价格。
Series<Numeric> FastMA; // 快速均线
Series<Numeric> SlowMA; // 慢速均线
Numeric NomMA;
Series<Numeric> x(0);
Series<Numeric> sig(1);
Series<Numeric> tt;
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;
Series<Numeric> xx(0);
Series<Numeric> xy(0); //跟踪Acceleration
Series<Numeric> HighestAfterEntry; //声明序列变量HighestAfterEntry,开仓后出现的最高价。
Series<Numeric> LowestAfterEntry; //声明序列变量LowestAfterEntry,开仓后出现的最低价。
Numeric StopPrice(0);
Series<Bool> Condition1(False);
series<Bool> Yun(False);
series<bool> condition(true);
series<bool> conditiona(true);
Numeric StopATR;
Series<Numeric> HH;
Numeric HHH; // 最近N根BAR的高点
Series<Numeric> LL;
Numeric PP;
Global Numeric h1;
Global Numeric h2;
Global Numeric L2;
Global Numeric l1; // 最近N根BAR的低
Numeric DDH;
Numeric Bigbar;
Numeric CL;
Series<Numeric> PPP;
Series<Numeric> LD;
Series<Numeric> H1d;
Series<Numeric> H2d;
Series<Numeric> L1d;
Series<Numeric> L2d;
Series<Numeric> op;
Series<Numeric> HD;
Series<Numeric> lld;
Series<Numeric> hhd;
Series<Bool> shang; //锤子线阳
Series<Bool> xia;// 吊头线阴
// Series<Bool> Condition1; // 条件1
// Series<Bool> Condition2; // 条件2
Numeric MyRange; //K线幅度
Events
OnInit()
{ Array<Numeric> timepoint;
timepoint[0] = 0.145950;
SetTriggerBarClose(timepoint);
}
OnBar(ArrayRef<Integer> indexs)
{
range[0:0]
{HD=Highest(high[1],dh);
LD=Lowest(Low[1],dh);
H2d=Highest(high[1],BH);
L2D=Lowest(Low[1],BH);
MinPoint = MinMove*PriceScale;//固定的最小跳动价公式。
HH=max(open,AvgEntryPrice-2*minpoint);
ll=min(open,AvgEntryPrice+2*minpoint);
Commentary("data1.h1d="+Text(data1.h1d));
Commentary("BarsSinceExit="+Text(BarsSinceExit));
Commentary("2*MinPoint="+Text(2*MinPoint));
Commentary("L1="+Text(L1));
Commentary("H1="+Text(H1));
SlowMA = Average(Close,SlowLen);
FastMA = Average(Close, FastLen);
PlotNumeric("FastMA",FastMA);
PlotNumeric("SlowMA",SlowMA);
}
if( (MarketPosition ==0) and High >HD )
{
Buy(0,max(hd,open));
L1=LOW;
xx=1;
}
if (BarsSinceEntry>0 and MarketPosition ==1 and low<l1)
{
Sell(0,l1);
}
}
// 开仓/
OnBarClose(ArrayRef<Integer> indexs)
{
if (MarketPosition ==1 and close>high[1])
{
Buy(0,close);
}
if (BarsSinceEntry>0 and MarketPosition ==1 and Low<FastMA)
{
Sell(0,close);
}
}
在恢复一下
你外国人吗?看不懂中文?
MarketPosition只会是 -1、0、1 三个值中的一个,做多后加仓它也是1,做空后加仓它也是-1,多空持仓相同或没有持仓它就是0。
不好意思 你这么说我就明白了
你再好好看看你这段代码的逻辑
在onbarclose域,也就是每根bar结束的时候,判断marketpoisition如果等于1,也就是现在开过多单了,并且收盘价比上一根bar的最高价高,然后开多。
有这段代码所以疯狂加仓,不是很正常吗?
加仓了就大于1了
?你从哪里看到的会大于1?
认真看过函数说明吗?这哪里有说会大于1?
BAITU
拜托
if (MarketPosition ==1 and close>high[1])
if( (MarketPosition ==0) and High >HD )
就这个指令,开仓限制仓位在0和1,后面为什么十几手以后还不停在开?
你这个问题问得我很疑惑。
这代码不就是会不停开吗?
if (MarketPosition ==1 and close>high[1])
如果现在已经有了多单,并且收盘价大于上一根bar开盘价
这不就是在描述加仓的逻辑吗?为什么不能不停开???
有的 ,如果它继续加仓,仓位就大于1了, market==1就不能存在了