等级: 专业版
- 注册:
- 2022-1-11
- 曾用名:
|
-----------------------------------------------------------------------
// 简称: Pro_02
// 名称:
// 类别: 公式应用
// 类型: 用户应用
// 输出: Void
//------------------------------------------------------------------------
Params
//此处添加参数
Numeric filter(3); // 每日过滤系数
Numeric Ayami_Multi(2); // 超级波段线系数
Numeric exit_mul_1(2); // 初始止损参数
Numeric rsi_trigger(80);
Numeric time_trigger(10); // 一级火箭加速参数(小于1)
Numeric lots(1);
Vars
//此处添加变量
//Numeric exit_mul_2(0.5); // 一级火箭加速参数(小于1)
Numeric length(20);
Numeric rsi_length(14);
Numeric Acceleration(0.05);
Series<Numeric> StopPrice;
Series<Numeric> HighValue;
Series<Numeric> AF;
Series<Numeric> StopATR;
Numeric MADDLength(5); // 跨日周期均线周期
Series<Numeric> Shunka;
Series<Numeric> Ayami ;
Series<Numeric> Ayami_2 ;
Series<Numeric> atr;
Series<Numeric> atrmd;
Series<Numeric> atrn;
Series<Numeric> xy;
Series<Numeric> sy;
Series<Numeric> mids;
Series<Numeric> v_max;
Series<Numeric> v1;
Series<Numeric> up;
Series<Numeric> down;
Series<Numeric> Tdown;
Series<Numeric> Tup;
Series<Numeric> dir(1);
Series<Numeric> Day_close;
Series<Numeric> WtdSum;
Series<Numeric> CumWt;
Series<Numeric> wDayMADD;
Series<Bool> long_exit;
Series<Bool> long_filter;
Series<Bool> long_filter_2;
Series<Numeric> HH;
Series<Numeric> entry_price;
Series<Numeric> long_exit_price;
Series<Numeric> change;
Series<Numeric> NetChg;
Series<Numeric> TotChg;
Series<Numeric> EffRatio;
Series<Numeric> spread;
Series<Numeric> spread_2;
Series<Numeric> pre_H;
Series<Numeric> minpoint;
Series<Bool> g;Series<Bool> rsi_jc;Series<Bool> rsi_again_entry;
Series<Numeric> RSIValue;
Series<Numeric> NetChgAvg( 0 );
Series<Numeric> TotChgAvg( 0 );
Series<Numeric> SF( 0 );
Series<Numeric> rsi_Change( 0 );
Series<Numeric> ChgRatio( 0 ) ;Series<Numeric> bench;
plot plt;
Series<Bool> rsi_exit;Series<Numeric> jc_count;
Events
//此处实现事件函数
//初始化事件函数,策略运行期间,首先运行且只有一次
OnInit()
{
//=========除权换月相关设置==============
AddDataFlag(Enum_Data_RolloverBackWard()); //设置后复权
AddDataFlag(Enum_Data_RolloverRealPrice()); //设置映射真实价格
AddDataFlag(Enum_Data_AutoSwapPosition()); //设置自动换仓
AddDataFlag(Enum_Data_IgnoreSwapSignalCalc()); //设置忽略换仓信号计算
plt.figure(0);
}
//Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
OnBar(ArrayRef<Integer> indexs)
{
minpoint = MinMove * PriceScale;
Shunka = IntPart((length - 1) / 2);
Ayami = XAverage(Close + (Close - Close[Shunka]), length);
//PlotNumeric("Ayami",Ayami);
atr = AvgTrueRange(length);
v1 = summation(abs(close - Open), length) / length;
v_max = Highest(summation(abs(close - Open), length) / length, length);
//PlotNumeric("v_max",v_max);
//PlotNumeric("v1",v1);
//Commentary("v_max"+Text(v_max));
up = Ayami + Ayami_Multi * v_max[1];
down = Ayami - Ayami_Multi * v_max[1];
//PlotNumeric("up_2",up_2,up_2, green);
Tup = IIF(Ayami[1]>Tup[1],Max(down, Tup[1]), down);
Tdown = IIF(Ayami[1]<Tdown[1], Min(up, Tdown[1]), up);
dir = IIF(Ayami>Tdown[1], 1, IIF(Ayami<Tup[1],-1,dir[1]));
if (dir==1)
{
Ayami_2 = Tup[1];
PlotNumeric("Ayami_2",Ayami_2,Ayami_2,red);
}
Else
{
Ayami_2 = Tdown[1];
PlotNumeric("Ayami_2",Ayami_2,Ayami_2,Green);
}
Commentary("dir[1]="+Text(dir[1]));
// 过滤1
wDayMADD = madd(MADDLength);
long_filter = close>wDayMADD;
// 过滤2
if (time == 0.090000)
{
bench = open;
}
HH = bench + v_max * filter;
long_filter_2 = close>= HH;
//PlotNumeric("wDayMADD",wDayMADD);
//PlotNumeric("HH",HH);
if (dir[1]==1 and MarketPosition==0 and long_filter[1] and long_filter_2[1] and rsi_jc==False)
{
entry_price = Open;
Buy(lots, entry_price);
Commentary("正常开仓");
}
if (rsi_jc[1])
{
jc_count = jc_count + 1;
}
Else
{
jc_count = 0;
}
rsi_again_entry = CrossOver(RSIValue, 100-rsi_trigger);
if (rsi_jc[1] and ((jc_count>time_trigger) or (rsi_again_entry[1])))
{
Buy(Roundup(lots/2,0), Open);
rsi_jc = False;
Commentary("减仓重新加回");
}
NetChg = Abs( close - close[10] );
TotChg = Summation( Abs( close - close[1] ), 10 );
EffRatio = IIF(TotChg > 0, NetChg / TotChg, 0);
Commentary("EffRatio"+Text(EffRatio));
//RSI
If(CurrentBar <= rsi_length - 1)
{
NetChgAvg = ( Close - Close[rsi_length] ) / rsi_length ;
TotChgAvg = Average( Abs( Close - Close[1] ), rsi_length ) ;
}Else
{
SF = 1/rsi_length;
rsi_Change = Close - Close[1] ;
NetChgAvg = NetChgAvg[1] + SF * ( rsi_Change - NetChgAvg[1] ) ;
TotChgAvg = TotChgAvg[1] + SF * ( Abs( rsi_Change ) - TotChgAvg[1] ) ;
}
If( TotChgAvg <> 0 )
{
ChgRatio = NetChgAvg / TotChgAvg;
}
else
{
ChgRatio = 0 ;
}
RSIValue = 50 * ( ChgRatio + 1 );
plt.line("RSI",RSIValue);
plt.line("rsi_trigger",rsi_trigger);
//出场
if (MarketPosition==1)
{
if (BarsSinceEntry==0)
{
//初始止盈止损设定 起飞
long_exit_price = low - atr[1]*exit_mul_1;
Commentary("atr[1]*exit_mul_1"+Text(atr[1]*exit_mul_1));
}
Else If(BarsSinceEntry>0)
{
// 自适应跟踪 常规巡航
if (close > close[1])
{
change = close - close[1];
long_exit_price = long_exit_price[1] + EffRatio[1]*change[1];
Commentary("change[1]"+Text(change[1]));
}
Else
{
long_exit_price = long_exit_price[1];
}
/*// 趋势度加强 一级火箭加速
g = CrossOver(EffRatio, er_trigger);
if(g[1])
{
spread = Low - long_exit_price[1];
long_exit_price = long_exit_price[1] + spread * exit_mul_2;
}*/
//
If(low<=long_exit_price[1])
{
Sell(0, min(Open,long_exit_price[1]));
rsi_jc = False;
Commentary("正常平仓");
}
}
PlotNumeric("long_exit_price[1]",long_exit_price[1]);
// 超买超卖出场
rsi_exit = CrossUnder( RSIValue, rsi_trigger);
if (rsi_exit[1] and rsi_jc==False)
{
Sell(Roundup(lots/2,0), Open);
rsi_jc = True;
Commentary("RSI减仓");
}
}
}
|
|