- 精华
- 0
- 在线时间
- 67 小时
- UID
- 232
- 积分
- 1532
- 帖子
- 152
- 阅读权限
- 70
- 注册时间
- 2007-8-31
- 最后登录
- 2019-3-31
- 精华
- 0
- UID
- 232
- 积分
- 1532
- 帖子
- 152
- 主题
- 6
- 阅读权限
- 70
- 注册时间
- 2007-8-31
- 最后登录
- 2019-3-31
|
海龟消化笔记(四)3----限制住损失
// 加上止损指令
If(Close <= MyEntryPrice - 2 * N)
{
myExitPrice = MyEntryPrice - 2 * N;
Sell(0,myExitPrice); // 数量用0的情况下将全部平仓
}
}Else
{
preEntryPrice = GetGlobalVar(0); // 取出上一次开仓的价格
If(preEntryPrice!=InvalidNumeric && TurtleUnits >= 1)
{
If(Open >= preEntryPrice + 0.5*N) // 如果开盘就超过设定的1/2N,则直接用开盘价增仓。
{
myEntryPrice = Open;
prePosition = CurrentContracts();
Buy(TurtleUnits,myEntryPrice);
If(CurrentContracts() != prePosition)
{
preEntryPrice = myEntryPrice;
IsAddThisBar = True;
SetGlobalVar(0,preEntryPrice); // 保存最后一次开仓的价格
}
}
while(High >= preEntryPrice + 0.5*N) // 以最高价为标准,判断能进行几次增仓
{
myEntryPrice = preEntryPrice + 0.5 * N;
prePosition = CurrentContracts();
Buy(TurtleUnits,myEntryPrice);
preEntryPrice = myEntryPrice;
If(CurrentContracts() != prePosition)
{
IsAddThisBar = True;
SetGlobalVar(0,preEntryPrice); // 保存最后一次开仓的价格
}
}
}
// 止损指令
If(IsAddThisBar)
{
// 当前Bar有过增仓,此时不能直接按Low来判断是否止损,因为不能确定Bar的价格的走势,只按收盘价进行止损判断。
If(Close <= preEntryPrice - 2 * N)
{
myExitPrice = preEntryPrice - 2 * N;
Sell(0,myExitPrice); // 数量用0的情况下将全部平仓
}
}Else
{
If(Low <= preEntryPrice - 2 * N)
{
myExitPrice = preEntryPrice - 2 * N;
Sell(0,myExitPrice); // 数量用0的情况下将全部平仓:lol :lol :lol
}
}
}
}Else If(MarketPosition ==-1) // 有空仓的情况
{
If(IsEntryThisBar)
{
// 当前Bar开过仓的情况,如果Close比myEntryPrice小于1/2N.用收盘价加仓。
If(Close <= myEntryPrice - 0.5 * N && TurtleUnits >= 1)
{
myEntryPrice = myEntryPrice - 0.5 * N;
prePosition = CurrentContracts();
SellShort(TurtleUnits,myEntryPrice);
If(CurrentContracts() != prePosition)
{
SetGlobalVar(0,myEntryPrice); // 保存最后一次开仓的价格
}
}
// 加上止损指令
If(Close >= MyEntryPrice + 2 * N)
{
myExitPrice = MyEntryPrice + 2 * N;
BuyToCover(0,myExitPrice); // 数量用0的情况下将全部平仓:lol :lol
}
}Else
{
preEntryPrice = GetGlobalVar(0); // 取出上一次开仓的价格
If(preEntryPrice!=InvalidNumeric && TurtleUnits >= 1)
{
If(Open <= preEntryPrice - 0.5*N) // 如果开盘就超过设定的1/2N,则直接用开盘价增仓。
{
myEntryPrice = Open;
prePosition = CurrentContracts();
SellShort(TurtleUnits,myEntryPrice);
If(CurrentContracts() != prePosition)
{
preEntryPrice = myEntryPrice;
IsAddThisBar = True;
SetGlobalVar(0,preEntryPrice); // 保存最后一次开仓的价格 :lol :lol :lol
}
}
while(Low <= preEntryPrice - 0.5*N) // 以最低价为标准,判断能进行几次增仓
{
myEntryPrice = preEntryPrice - 0.5 * N;
prePosition = CurrentContracts();
SellShort(TurtleUnits,myEntryPrice);
preEntryPrice = myEntryPrice;
If(CurrentContracts() != prePosition)
{
IsAddThisBar = True;
SetGlobalVar(0,preEntryPrice); // 保存最后一次开仓的价格
}
}
}
// 止损指令 If(IsAddThisBar:lol )
{ // 当前Bar有过增仓,此时不能直接按High来判断是否止损,因为不能确定Bar的价格的走势,只按收盘价进行止损判断。
If(Close >= preEntryPrice + 2 * N)
{
myExitPrice = preEntryPrice + 2 * N;
BuyToCover(0,myExitPrice); // 数量用0的情况下将全部平仓:lol :lol
}
}Else {
If(High >= preEntryPrice + 2 * N)
{
myExitPrice = preEntryPrice + 2 * N;
BuyToCover(0,myExitPrice); // 数量用0的情况下将全部平仓:lol :lol :lol
End
[ 本帖最后由 sandboy2005 于 2007-10-10 01:57 编辑 ] |
|