//------------------------------------------------------------------------
// 简称: sar01
// 名称: sar01
// 类别: 公式应用
// 类型: 内建应用
// 输出:
//------------------------------------------------------------------------
//----------------------------------------------------------------------//
// 策略说明:
// sar策略抛物线转向
//----------------------------------------------------------------------//
Params
Numeric AfStep( 0.02);
Numeric AfLimit( 0.2 ) ;
Numeric Length(5); // 强弱指标和通道计算的周期值
Numeric Stop_Len(5); // 止损通道的周期值
Numeric ProfitFactor(3); // 止盈相对止损的倍数
Numeric EntryStrength(95); // 强弱指标的进场值
Vars
Numeric oParCl( 0 );
Numeric oParOp( 0 );
Numeric oPosition( 0 );
Numeric oTransition( 0 );
Series<Numeric> sarNM;
Series<Numeric> sarPosition;
Series<Numeric> saroParOp;
Events
OnBar(ArrayRef<Integer> indexs)
{
Range[0:DataSourceSize() - 1]
{
ParabolicSAR( AfStep, AfLimit, oParCl, oParOp, oPosition, oTransition ) ;
sarNM=oParCl;
sarPosition=oPosition;
saroParOp=oParOp;
if(oPosition>0 )
{
PlotAuto( \"ParCl\" , oParCl,0,red,Enum_Dot) ;
}
if(oPosition<0 )
{
PlotAuto( \"ParCl\" , oParCl,0,Green,Enum_Dot) ;
}
}
// 开仓
If(MarketPosition == 0 and sarPosition[1]<0 and H>=saroParOp[1] )
{
Buy(0, Max(Open,saroParOp[1]));
Commentary(\"开仓\");
}
// 平仓
If(MarketPosition == 1 and sarPosition[1]>0 and L<=saroParOp[1] )
{
Sell(0,min(Open,saroParOp[1]));
Commentary(\"止盈\");
}
// 开仓
If(MarketPosition == 0 and sarPosition[1]>0 and L<=saroParOp[1])
{
SellShort(0, Min(Open,saroParOp[1]));
Commentary(\"开仓\");
}
// 平仓
If(MarketPosition == -1 and sarPosition[1]<0 and H>=saroParOp[1] )
{
BuyToCover(0,max(Open,saroParOp[1]));
Commentary(\"止盈\");
}
}
//------------------------------------------------------------------------
// 编译版本 GS2014.10.25
// 版权所有 TradeBlazer Software 2003-2025
// 更改声明 TradeBlazer Software保留对TradeBlazer平
// 台每一版本的TradeBlazer公式修改和重写的权利
//------------------------------------------------------------------------
MarketPosition == 0 表示判断是否没有仓位
我也没看到你哪里是专门翻仓的
图表上看上去都是空头
显然开多语句判断持仓条件不对