等级: 超级版主
- 注册:
- 2021-5-18
- 曾用名:
|
if barpos<20 then exit;
UpperBand := hhv(High, 20);
LowerBand := llv(Low, 20);
// 计算振幅
Numeric amplitude := (UpperBand - LowerBand) / ref(open,20);
// 判断振幅是否在上下百分之 0.5 内
ref1:=ref(UpperBand,1);
ref2:=ref(LowerBand,1);
If amplitude <:= 0.005 Then
Begin
// 向上突破判断
UpBreakout := Close > ref1;
// 向下突破判断
DownBreakout := Close < ref2;
// 开仓逻辑
If UpBreakout and holding=0 Then
Begin
OpenPrice := Close;
StopLossPrice := OpenPrice + 50;
Buy(1, 1, limitr,OpenPrice);
End
Else If DownBreakout and holding<0 Then
Begin
OpenPrice := Close;
StopLossPrice := OpenPrice - 50;
buyShort(1, 1, limitr,OpenPrice);
End
End
// 止损逻辑
If holding>0 and Low <= StopLossPrice Then
Begin
Sell(1, 1, Market);
End
Else If holding<0 and High >= StopLossPrice Then
Begin
sellshort(1, 1, Market);
End
// 止盈逻辑(简单判断反向趋势,可优化)
If holding>0 and Close < OpenPrice Then
Begin
Sell(1, 1, Market);
End
Else If holding<0 and Close > OpenPrice Then
Begin
sellshort(1, 1, Market);
End
|
|