全部 智大领峰 TBQuant功能 TBL语言 TB开户 问答专区 高手圈 其他
怎样做到连错三次才加仓
2024-08-27 10:34

Params

Numeric FastLength(9); // 短期指数平均线参数

Numeric SlowLength(19); // 长期指数平均线参数

Numeric Length(9); // RSI参数

Numeric OverSold(30); // 超卖

Numeric OverBought(70); // 超买

Numeric Lots(0); // 交易手数

Vars

Series<Numeric> AvgValue1; // 短期指数平均线

Series<Numeric> AvgValue2; // 长期指数平均线

Series<Numeric> NetChgAvg(0);

Series<Numeric> TotChgAvg(0);

Numeric SF(0);

Numeric Change(0);

Numeric ChgRatio(0);

Series<Numeric> RSIValue; // RSI

Series<Numeric> ExitHiBand(0); // 唐奇安通道上轨

Series<Numeric> ExitLoBand(0); // 唐奇安通道下轨

Series<Numeric> myEntryPrice(0); // 进场价格

Series<Numeric> myExitPrice(0); // 出场价格

Series<Numeric> myProfit(0); // 利润

Series<Numeric> myPosition(0); // 多空标志

Events

OnBar(ArrayRef<Integer> indexs)

{

// 短期指数平均线

AvgValue1 = Xaverage(Close,FastLength);

// 长期指数平均线参数

AvgValue2 = Xaverage(Close,SlowLength);

// 计算RSI

If(CurrentBar <= Length - 1)

{

NetChgAvg = (Close - Close[Length])/Length;

TotChgAvg = Average(Abs(Close - Close[1]),Length);

}Else

{

SF = 1/Length;

Change = Close - Close[1];

NetChgAvg = NetChgAvg[1] + SF*(Change - NetChgAvg[1]);

TotChgAvg = TotChgAvg[1] + SF*(Abs(Change) - TotChgAvg[1]);

}

If(TotChgAvg <> 0)

{

ChgRatio = NetChgAvg/TotChgAvg;

}Else

{

ChgRatio = 0;

}

RSIValue = 50*(ChgRatio + 1);

// 唐奇安通道上轨

ExitHiBand = Highest(High,20);

// 唐奇安通道下轨

ExitLoBand = Lowest(Low,20);

// 持有多单时下破唐奇安通道下轨,平多单

If(myPosition == 1 And myPosition[1] == 1 And Low <= ExitLoBand[1])

{

myExitPrice = Min(Open,ExitLoBand[1]);

Sell(0,myExitPrice);

myProfit = myExitPrice - MyEntryPrice;

myPosition = 0;

}

// 模拟交易产生一次亏损、短期均线在长期均线之上、RSI低于超买值、创新高,则开多单

If(myPosition == 0 And myPosition[1] == 0 And AvgValue1[1] > AvgValue2[1] And RSIValue[1] < OverBought And High >= High[1])

{

myEntryPrice = Max(Open,High[1]);

myPosition = 1;

If(myProfit < 0) Buy(Lots,myEntryPrice);

}

}


各位老师为什么这个幽灵者利润myProfit不可以回溯myProfit[1]第一次亏时开仓加一手  ,myProfit[2]第二次亏时开仓加一手,myProfit[3]第三次亏时开仓加一手

wangkaiming

回溯是基于K线的 ,myProfit[1] 表示回溯上一根的myProfit值

2024-08-27 11:04
ganjinji520
@wangkaiming

怎样回溯上一次交易值?

2024-08-27 11:17
您未登录,请先 登录注册 后发表评论
顶部