- 精华
- 0
- 在线时间
- 41 小时
- UID
- 131362
- 积分
- 32
- 帖子
- 20
- 阅读权限
- 10
- 注册时间
- 2012-7-25
- 最后登录
- 2021-1-22
- 精华
- 0
- UID
- 131362
- 积分
- 32
- 帖子
- 20
- 主题
- 9
- 阅读权限
- 10
- 注册时间
- 2012-7-25
- 最后登录
- 2021-1-22
|
我想实现一个信号盈利超过一定范围后暂停交易几根K线(例如螺纹盈利超过1000(100点)后,自平仓K线起50根K线不在交易),我利用entryprice,exitprice进行判断不行,利用持仓盈利也不行。请大神们帮忙指点一下,源码如下:
Params
Numeric Length1(13);
Numeric Length2(55);
Numeric lev1_profit(200);//止盈参数
Numeric lev2_profit(500);
Numeric lev3_profit(1000);
Numeric LV1(0);
Numeric LV2(0.5);
Numeric LV3(0.9);
Numeric Maxloss(0.01);//止损参数
Numeric Lots(1);//交易手数
Vars
NumericSeries BuyPosition(0);
NumericSeries SellPosition(0);
Bool Conbuy(False);
Bool ConSellShort(False);
NumericSeries Tradecontrol(0);//盈利后暂停交易控制器,1为暂停50根K线,2为暂停100根K线
NumericSeries Tradebutton(1);//是否交易的开关,1为交易,0为暂停交易
Begin
//指标公式
BuyPosition = XAverage(C,Length1);
SellPosition = XAverage(LinearRegSlope(C,21)*20+C,Length2);
PlotNumeric("买线",BuyPosition,0);
PlotNumeric("卖线",SellPosition,0);
//入场条件
Conbuy=CrossOver(BuyPosition[1],SellPosition[1]);
ConSellShort=CrossUnder(BuyPosition[1],SellPosition[1]);
if(Tradebutton==1)
{
if (Conbuy )
{
Buy(Lots,open);
PlotString("多开","多开",Low-5,Yellow,1);
}
if (ConSellShort)
{
SellShort(Lots,open);
PlotString("空开","空开",High+5,Yellow,1);
}
}
// 初始止损
if (marketposition>0 and close[1]<entryprice*(1-Maxloss))
{
sell(0,open);
PlotString("多损","多损",High+5,Yellow,1);
}
if (marketposition<0 and close[1]>entryprice*(1+Maxloss))
{
buytocover(0,open);
PlotString("空损","空损",Low-5,Yellow,1);
}
// 多单盈利离场
if (marketposition>0 and maxpositionprofit>lev3_profit)
{
if (positionprofit<maxpositionprofit*LV3)
{
sell (0,open);
PlotString("多离3","多离3",High+5,Yellow,1);
Tradecontrol=2;
}
}
if (marketposition>0 and maxpositionprofit>lev2_profit)
{
if (positionprofit<maxpositionprofit*LV2)
{
sell (0,open);
PlotString("多离2","多离2",High+5,Yellow,1);
Tradecontrol=1;
}
}
if (marketposition>0 and maxpositionprofit>lev1_profit)
{
if (positionprofit<maxpositionprofit*LV1)
{
sell (0,open);
PlotString("多离1","多离1",High+5,Yellow,1);
}
}
// 空单盈利离场
if (marketposition<0 and maxpositionprofit>lev3_profit)
{
if (positionprofit<maxpositionprofit*LV3)
{
buytocover(0,open);
PlotString("空离3","空离3",Low-5,Yellow,1);
Tradecontrol=2;
}
}
if (marketposition<0 and maxpositionprofit>lev2_profit)
{
if (positionprofit<maxpositionprofit*LV2)
{
buytocover(0,open);
PlotString("空离2","空离2",Low-5,Yellow,1);
Tradecontrol=1;
}
}
if (marketposition<0 and maxpositionprofit>lev1_profit)
{
if (positionprofit<maxpositionprofit*LV1)
{
buytocover(0,open);
PlotString("空离1","空离1",Low-5,Yellow,1);
}
}
//大幅盈利之后暂停交易
if (Tradecontrol==2 and BarsSinceExit<50 )
{
Tradebutton=0;
}else
if (Tradecontrol==1 and BarsSinceExit<30 )
{
Tradebutton=0;
}else
{
Tradebutton=1;
}
End |
|