分类: WINDOWS
2010-07-22 15:33:31
Params
Numeric TrailingSet(0.382); // 回撤开仓比例设置,从最高点下跌的比例
Numeric StopLossSet(0.5); // 止损比例设置
Vars
Bool startCondition(False); // 启动条件
Bool EntryCondition(False); // 开仓条件
Bool ExitCondition(False); // 平仓条件
NumericSeries highestValue(0); // 前2个周期的最高价
NumericSeries lowestValue(0); // 前2个周期的最低价
Numeric myEntryPrice(0); // 开仓价格
Numeric myExitPrice(0); // 平仓价格
Begin
highestValue = highestValue[1];
lowestValue = lowestValue[1];
If(MarketPosition ==0 ) // 当前空仓
{
If(Close[2]>Open[2] && Close[1] > Open[1]
&& Close[1] > Close[2])
{
startCondition = True;
highestValue = max(high[2],high[1]);
lowestValue = min(low[2],low[1]);
}
If(startCondition)
{
EntryCondition = ((highestValue - Open) / (highestValue -
lowestValue) > TrailingSet )&& // 开盘价即满足回撤条件,用开盘价进行交易
(Open > highestValue -((highestValue -
lowestValue)*StopLossSet)) ; // 开盘价不能低于预设的止损价
If( EntryCondition)
{
Buy(1,Open);
}Else // 再看其它价格是否满足
{
EntryCondition = (highestValue - Low) / (highestValue -
lowestValue) > TrailingSet ; // 最低价满足回撤条件,用低于TrailingSet设置的最近价位建仓
If(EntryCondition)
{
myEntryPrice = highestValue - (HighestValue -
LowestValue ) * TrailingSet;
myEntryPrice = IntPart(myEntryPrice /
(PriceScale()*MinMove)) *(PriceScale()*MinMove); // 对价格进行处理
If(myEntryPrice >= low && myEntryPrice
<= High)
{
Buy(1,MyEntryPrice);
}
}
}
}
}else If(MarketPosition == 1) // 当前多仓
{
ExitCondition = ( HighestValue - Low )/(highestValue -
lowestValue) > StopLossSet; // 止损条件满足
If(ExitCondition)
{
myExitPrice = highestValue - (HighestValue - LowestValue ) *
StopLossSet;
myExitPrice = IntPart(myExitPrice / (PriceScale()*MinMove))
*(PriceScale()*MinMove); // 对价格进行处理
Sell(CurrentContracts(),myExitPrice);
}Else // 获利平仓
{
ExitCondition = (high - AvgEntryPrice()) > (highestValue -
lowestValue); // 获利平仓条件满足
If(ExitCondition)
{
myExitPrice = AvgEntryPrice() + (HighestValue -
LowestValue );
myExitPrice = IntPart(myExitPrice /
(PriceScale()*MinMove)) *(PriceScale()*MinMove); // 对价格进行处理
If (myExitPrice >= low && myEntryPrice <=
high)
{
Sell(CurrentContracts(),myExitPrice);
}Else
{
Sell(CurrentContracts(),Close);
}
}
}
}
End