请教一下我这个代码都改版好多次了 ,就是平不了第二次仓
疑问1, Else If(MarketPosition==1 And x4 )
{ pcj=Min(Open, sg-1);
pcj= kcj;
Sell(ss1,pcj);
Commentary("pcj"); }
这段平仓直接给我把两手平仓平掉 ,我设计的是只平一手,导致我后面一段代码平仓1手没有执行
疑问2 为什么平仓后不符合条件也一直开仓,平仓,能不能帮忙看看改改呀
Params
Numeric ss2(2);
Numeric ss1(1);
Numeric ss4(2);
Vars
Series<Numeric> HHV_120; // 120周期内的最高价
Series<Numeric> LLV_120; // 120周期内的最低价
Series<Numeric> xg; // 加权平均值
Series<Numeric> xg1;
Series<Numeric> sg;
Series<Numeric> kc;
Series<Bool> kg;
Series<Bool> kg1;
Series<Numeric>kcj;
Series<Numeric>kcj1;
Series<Numeric>pcj;
Series<Numeric>pcj1;
Series<Numeric>qpc;
Series<Bool> x1;
Series<Bool> x2;
Series<Bool> x3;
Series<Bool> x4;
Series<Bool> x5;
Events
//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
OnBar(ArrayRef<Integer> indexs)
{ HHV_120 =Highest(High[1], 120);
LLV_120 = Lowest(Low[1], 120);
PlotNumeric("HHV_120 ",HHV_120);
PlotNumeric("LLV_120 ", LLV_120 );
xg = 0.4 *HHV_120 + 0.6 * LLV_120;
PlotNumeric("xg ", xg);
xg1 = 0.2 *HHV_120 + 0.8 * LLV_120;
PlotNumeric("xg1 ", xg1);
sg = 0.9 * HHV_120 + 0.1 * LLV_120;
PlotNumeric("sg ", sg);
x3 =(Low[1]>xg[1] );
x2 =(High>xg1);
x4=( High[1]>sg[1]);
x1=(Low[1]<LLV_120[1]);
x5=(High[1]> HHV_120[1]);
If(MarketPosition==0 And x2 )
{ kcj1=Max( Open,xg1+1);
Buy(ss2,kcj1);
kcj==kcj1;
Commentary("kcj1");
}
Else If(MarketPosition==1 And x1)
{ pcj=Min( Open,LLV_120-1);
Sell (ss2,pcj);
Commentary("kcj1");
}
Else If(MarketPosition==1 And x4 )
{ pcj=Min(Open, sg-1);
pcj= kcj;
Sell(ss1,pcj);
Commentary("pcj");
}
Else If(MarketPosition==1 And x5 )
{ pcj=Min(Open, HHV_120-1);
pcj= pcj1 ;
Sell(ss1,pcj1);
Commentary("pcj1");
}
}
建议看置顶的投稿贴
另外请教代码问题请把代码发完整,只取一段不一定能分析出问题。