|
Params
Numeric FastLength(6); //短周期
Numeric SlowLength(24); //长周期
Numeric LosePoint(12); //止损点数
Numeric WinPoint(30); //止赢点数
Numeric TradeUint(5); //每次交易手数
Vars
NumericSeries AvgValue1;
NumericSeries AvgValue2;
BoolSeries bCrossOver(false);
BoolSeries bCrossDn(False);
NumericSeries LastCross(0);
Begin
AvgValue1 = AverageFC(CLOSE,FastLength);
AvgValue2 = AverageFC(CLOSE,SlowLength);
PlotNumeric("MA1",AvgValue1);
PlotNumeric("MA2",AvgValue2);
bCrossOver = CrossOver(AvgValue1,AvgValue2);
bCrossDn = CrossUnder(AvgValue1,AvgValue2);
//均线交叉时开仓
if(bCrossOver[1])
{
if(CurrentBar-LastCross>3 )
{
Buy(TradeUint,Q_AskPrice + MinMove * PriceScale);
PlotText(Q_AskPrice+MinMove* PriceScale,"上穿");
}
LastCross = CurrentBar;
}
Else if(bCrossDn[1])
{
if(CurrentBar-LastCross>3 )
{
SellShort(TradeUint,Q_BidPrice-MinMove* PriceScale);
PlotText(Q_BidPrice-MinMove* PriceScale,"下穿");
}
LastCross = CurrentBar;
}
//止损,止赢
if(MarketPosition > 0)
{
Numeric DiffPoint = Q_Close-A_BuyAvgPrice;
Numeric DiffPrice = DiffPoint * A_BuyPosition*ContractUnit;
if(DiffPoint < -1 * LosePoint)
{
Sell(0,Q_BidPrice-MinMove* PriceScale);
PlotText(Q_BidPrice-MinMove* PriceScale,"止损");
}
if(DiffPoint > WinPoint)
{
Sell(0,Q_BidPrice-MinMove* PriceScale);
PlotText(Q_BidPrice-MinMove* PriceScale,"止赢");
}
Print("当前盈利:"+Text(DiffPoint)+"点,价值"+ Text(DiffPrice)+"元");
}
if(MarketPosition <0)
{
Numeric DiffPoint = A_SellAvgPrice-Q_Close;
Numeric DiffPrice = DiffPoint * A_SellPosition*ContractUnit;
if(DiffPoint < -1 * LosePoint)
{
BuyToCover(0,Q_AskPrice+MinMove* PriceScale);
PlotText(Q_AskPrice+MinMove* PriceScale,"止损");
}
if(DiffPoint > WinPoint)
{
BuyToCover(0,Q_AskPrice+MinMove* PriceScale);
PlotText(Q_AskPrice+MinMove* PriceScale,"止赢");
}
Print("当前盈利:"+Text(DiffPoint)+"点,价值"+ Text(DiffPrice)+"元");
}
End |
|