- 精华
- 0
- 在线时间
- 923 小时
- UID
- 397
- 积分
- 4818
- 帖子
- 87
- 阅读权限
- 80
- 注册时间
- 2007-9-22
- 最后登录
- 2021-6-8
- 精华
- 0
- UID
- 397
- 积分
- 4818
- 帖子
- 87
- 主题
- 13
- 阅读权限
- 80
- 注册时间
- 2007-9-22
- 最后登录
- 2021-6-8
|
原帖由 xuelei7107 于 2007-9-28 07:43 发表
我要是打算根据3日的高低价平仓呢?想法如下
我想实现这样一个一个想法:价格突破5天最高价,开多仓,把当天和前一天的K线做比较,取两日的最低价格做为止损,当价格突破3日最低价时,平多仓。
价格突破5日最低价,开空仓,把今天和 ...
你看看哦,代码大致如此:
Params
vars
NumericSeries EntryHi;
NumericSeries EntryLo;
NumericSeries ShortStop;
NumericSeries LongStop;
NumericSeries SellHi;
NumericSeries SellLo;
Numeric myEntryPrice;
Numeric myExitPrice;
begin
EntryHi = Highest(high[1],5);
EntryLo = Lowest(low[1],5);
SellHi=Highest(high[1],3);
SellLo= Lowest(low[1],3);
ShortStop= Highest(high[1],2);
LongStop=Lowest(low[1],2);
if(MarketPosition ==0)
{
If(CrossOver(high,EntryHi))
{
myEntryPrice = min(high,EntryHi );
myEntryPrice = IIF(myEntryPrice < Open, Open,myEntryPrice);
Buy(0,myEntryPrice);
}
If(CrossUnder(Low,EntryLo ))
{
myEntryPrice = max(low,EntryLo );
myEntryPrice = IIF(myEntryPrice > Open, Open,myEntryPrice);
SellShort(0,myEntryPrice);
}
}
If(MarketPosition ==1)
{
if (CrossUnder(Low,LongStop))
{
myExitPrice = max(low,LongStop );
myExitPrice = IIF(myExitPrice > Open, Open,myExitPrice);
Sell(0,myExitPrice);
}Else
if (CrossUnder(Low,SellLo))
{
myExitPrice = max(low,SellLo );
myExitPrice = IIF(myExitPrice > Open, Open,myExitPrice);
Sell(0,myExitPrice);
}
}
If(MarketPosition ==-1)
{
if (CrossOver(high,ShortStop))
{
myExitPrice = min(high,ShortStop );
myExitPrice = IIF(myExitPrice < Open, Open,myExitPrice);
BuyToCover(0,myExitPrice);
}Else
if (CrossOver(high,SellHi))
{
myExitPrice = min(high,SellHi );
myExitPrice = IIF(myExitPrice < Open, Open,myExitPrice);
BuyToCover(0,myExitPrice);
}
}
end |
|