- 精华
- 0
- 在线时间
- 30 小时
- UID
- 115532
- 积分
- 74
- 帖子
- 28
- 阅读权限
- 30
- 注册时间
- 2013-2-15
- 最后登录
- 2013-4-28
- 精华
- 0
- UID
- 115532
- 积分
- 74
- 帖子
- 28
- 主题
- 7
- 阅读权限
- 30
- 注册时间
- 2013-2-15
- 最后登录
- 2013-4-28
|
本帖最后由 任任任 于 2013-3-29 19:16 编辑
Params
Numeric Length(30); //N 30
Numeric SlowLength(10); //M1
Numeric SmoothLength(10); //M2
Numeric lots(1);
Numeric offset(2);
Numeric Stoploss(40);
Vars
NumericSeries HighestValue;
NumericSeries LowestValue;
NumericSeries KValue;//TB中的K值
NumericSeries DValue;//TB中的K值
NumericSeries RSV;
NumericSeries K1;//正规的K值
NumericSeries D1;//正规的D值
Numeric i_offset;//程序化交易
Numeric BuyPosition;
Numeric SellPosition;
Numeric myEntryPrice;
Numeric myExitPrice;
Begin
{
HighestValue = HighestFC(High, Length);
LowestValue = LowestFC(Low, Length);
RSV = (Close-LowestValue)/(HighestValue-LowestValue)*100;
K1 = SMA(RSV,SlowLength,1);
D1 = SMA(K1,SmoothLength,1);
KValue = SummationFC(Close - LowestValue,SlowLength)/SummationFC(HighestValue-LowestValue,SlowLength)*100;
DValue = AverageFC(KValue,SmoothLength);
PlotNumeric("RSV",RSV);
if(MarketPosition == 0)
{
if(K1 > D1)
{
buy(lots,high); //<---原来这里用的buy(lots,close[1]);
Return;
}
}
else if (MarketPosition == 1) //平多
{
if(K1 < D1)
{
sell(lots,open);//<--这里用的是sell(lots,close);
Return;//程序化交易 www.cxh99.com
}
}
//止损
If(MarketPosition == 1)
{
If(Low < EntryPrice - StopLoss * MinMove*PriceScale)
{
myExitPrice = EntryPrice - (StopLoss+1) * MinMove*PriceScale;
myExitPrice = max(low,myExitPrice);
Sell(lots,myExitPrice);
}
}
Else If(MarketPosition == -1)
{
If(High > EntryPrice + StopLoss * MinMove*PriceScale)
{
myExitPrice = EntryPrice + (StopLoss+1) * MinMove*PriceScale;
myExitPrice = min(high,myExitPrice);
BuyToCover(lots,myExitPrice);
}
}
}
end |
|