大神帮我看下我这几个地方为什么会开仓,我的逻辑应该不会开仓才对
2023-08-08 23:24

// ------------------------------------------------------------------------

//  简称: NoHurrySystem_S

//  名称: 基于平移通道的交易系统空

//  类别: 公式应用

//  类型: 内建应用

//  输出:

// ------------------------------------------------------------------------

// ----------------------------------------------------------------------//

//  策略说明:

// 本策略基于平移后的高低点通道判断入场条件,结合ATR止损

//  系统要素:

data-href=

//   1. 平移后的高低点通道

//    2. atr止损

//

//  入场条件:

//   1.当高点上穿平移通道高点时,开多仓

//   2.当低点下穿平移通道低点时,开空仓

//

//  出场条件:

//   1.ATR跟踪止盈

//   2.通道止损

//

//     注:当前策略仅为做空系统, 如需做多, 请参见CL_NoHurrySystem_L

// ----------------------------------------------------------------------//

Params

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

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

Numeric LineLength(60);// 长期指数平均线参数

Vars

Series<Numeric>  MA_LINE;

Series<Numeric>  MA_ten;

Series<Numeric>  MA_five;

Series<Numeric>  NO_SELL;

bool con_sell;

bool con_buy; // bool中间变量

Numeric minpoint; // 最小变动价位

Series<Numeric> stopline; // 止损线计算

Series<Numeric> Price_buy;

Series<Numeric> Price_sell;

Series<Numeric> WinPrice_buy; //止赢价多单

Series<Numeric> WinPrice_sell; //止赢价空单

Series<Numeric> LosePrice_buy; //止损价多单

Series<Numeric> LosePrice_sell; //止损价空单

Series<Bool> EnterFlag(True);

Events

OnBar(ArrayRef<Integer> indexs)

{

// 指标计算

MA_LINE = AverageFC(Close,LineLength);

MA_ten = AverageFC(Close,SlowLength);

MA_five = AverageFC(Close,FastLength);

NO_SELL = 0;

If(DateTimeDiff(CurrentTime,EndTime) > 10)

{

EnterFlag = False ;

}

//If(DateTimeDiff(CurrentTime,EndTime) < 2 And EnterFlag == False)

{

// 系统入场,开空

If(MarketPosition != -1)

{

If(CrossUnder(MA_ten,MA_LINE))

{

If(MarketPosition == 1 And BarsSinceEntry > 0)

{

Sell(0,Close);

//Sell(0,Q_BidPrice(0));

Commentary(止损多单1:);

}

SellShort(0,Close);

//SellShort(0,Q_BidPrice(0));

EnterFlag = True ;

Price_sell = Close;

WinPrice_sell = Close * 0.98;

LosePrice_sell = Close * 1.015;

Commentary(WinPrice_sell_1:+Text(WinPrice_sell));

Commentary(LosePrice_sell:+Text(LosePrice_sell));

}

else If(MA_ten < MA_LINE)

{

If(CrossUnder(MA_five,MA_ten) Or CrossUnder(MA_five,MA_LINE))

//If(CrossUnder(MA_five,MA_ten))

{

If(MarketPosition == 1 And BarsSinceEntry > 0)

{

Sell(0,Close);

//Sell(0,Q_BidPrice(0));

Commentary(止损多单1:);

}

SellShort(0,Close);

//SellShort(0,Q_BidPrice(0));

EnterFlag = True ;

Price_sell = Close;

WinPrice_sell = Close * 0.98;

LosePrice_sell = Close * 1.015;

Commentary(ma_five:+Text(MA_five));

Commentary(ma_ten:+Text(MA_ten));

Commentary(WinPrice_sell_2:+Text(WinPrice_sell));

Commentary(LosePrice_sell:+Text(LosePrice_sell));

}

}

}

// 系统入场,开多仓

If(MarketPosition != 1)

{

If(CrossOver(MA_ten,MA_LINE))

{

If(MarketPosition == -1 And BarsSinceEntry > 0)

{

BuyToCover(0,Close);

//BuyToCover(0,Q_AskPrice(0));

Commentary(止损空单1:);

}

Buy(0,Close);

//Buy(0,Q_AskPrice(0));

EnterFlag = True ;

Price_buy = Close;

WinPrice_buy = Close * 1.02 ;

LosePrice_buy = Close * 0.985;

Commentary(WinPrice_buy_1:+Text(WinPrice_buy));

Commentary(LosePrice_buy:+Text(LosePrice_buy));

}

else If(MA_ten > MA_LINE)

{

If(CrossOver(MA_five,MA_ten) Or CrossOver(MA_five,MA_LINE))

{

If(MarketPosition == -1 And BarsSinceEntry > 0)

{

BuyToCover(0,Close);

//BuyToCover(0,Q_AskPrice(0));

Commentary(止损空单1:);

}

Buy(0,Close);

//Buy(0,Q_AskPrice(0));

EnterFlag = True ;

Price_buy = Close;

WinPrice_buy = Close * 1.02 ;

LosePrice_buy = Close * 0.985;

Commentary(WinPrice_buy_2:+Text(WinPrice_buy));

Commentary(LosePrice_buy:+Text(LosePrice_buy));

}

}

}

}


// 系统出场 平空

If(MarketPosition == -1 And BarsSinceEntry > 0)

{

If(Low < WinPrice_sell)

{

WinPrice_sell = Low;

LosePrice_sell = Price_sell-(Price_sell - WinPrice_sell)*0.7;

}

If(Close > LosePrice_sell)

{

BuyToCover(0,LosePrice_sell);

//BuyToCover(0,Q_AskPrice(0));

Commentary(止损空单3:);

Commentary(LosePrice_sell:+Text(LosePrice_sell));

}

}

// 系统出场 平多

If(MarketPosition == 1 And BarsSinceEntry > 0)

{

If(High > WinPrice_buy)

{

WinPrice_buy = high;

LosePrice_buy = Price_buy + (WinPrice_buy - Price_buy)*0.7;

}

If(Close < LosePrice_buy)

{

Sell(0,LosePrice_buy);

//Sell(0,Q_BidPrice(0));

Commentary(止损多单3:);

Commentary(LosePrice_buy:+Text(LosePrice_buy));

}

}

}

//------------------------------------------------------------------------

// 编译版本 GS2014.10.25

// 版权所有 TradeBlazer Software 2003-2025

// 更改声明 TradeBlazer Software保留对TradeBlazer平

// 台每一版本的TradeBlazer公式修改和重写的权利

//------------------------------------------------------------------------

评论区
顶部