开拓者期货期权程序化系统交易论坛
标题:
请大咖帮忙指正这段代码的错误
[打印本页]
作者:
zq950322
时间:
2019-4-19 08:31:59
标题:
请大咖帮忙指正这段代码的错误
Params
Numeric Length1(5);
Numeric Length2(20);
Numeric Lots(1);
Numeric ATRLength(20);
Numeric TrailStop(2);
Vars
NumericSeries MA1;
NumericSeries MA2;
NumericSeries ATRValue;
NumericSeries HiAfterEntry;
NumericSeries LoAfterEntry;
Numeric Stopline;
BoolSeries bLongStoped(false);
BoolSeries bShortStoped(false);
Begin
ATRValue = AvgTrueRange(ATRLength);
MA1 = AverageFC(Close,Length1);
MA2 = AverageFC(Close,Length2);
PlotNumeric("MA1",MA1);
PlotNumeric("MA2",MA2);
If (!bLongStoped and MarketPosition <> 1 and MA1[1] > MA2[1])
{
Buy(Lots,Open);
bShortStoped = false;
}
If (!bShortStoped and MarketPosition <> -1 and MA1[1] < MA2[1])
{
SellShort(lots,Open);
SellShort(lots,Open);
}
If (bLongStoped and MarketPosition <> 1 and High >= HiAfterEntry)
{
Buy(Lots, Max(Open, HiAfterEntry));
bShortStoped = false;
}
If (MarketPosition == 1 and BarsSinceEntry == 0) HiAfterEntry = High;
If (MarketPosition == 1 and BarsSinceEntry >= 1)
HiAfterEntry = Max(HiAfterEntry,High);
If (MarketPosition == -1 and BarsSinceEntry == 0) LoAfterEntry = Low;
If (MarketPosition == -1 and BarsSinceEntry >= 1)
LoAfterEntry = Min(LoAfterEntry,Low);
if (BarssinceEntry > 0 and MarketPosition == 1)
{
StopLine = HiAfterEntry[1] - TrailStop * ATRValue[1];
If (Low <= StopLine)
{
Sell(0, Min(Open, Stopline));
bLongStoped = true;
}
} Else If(BarsSinceEntry > 0 and MarketPosition == -1)
{
StopLine = LoAfterEntry[1] + TrailStop * ATRValue[1];
If(High >= StopLine)
{
BuyToCover(0, Max(Open, Stopline));
bShortStoped = true;
}
}
End
欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/)
Powered by Discuz! X2