多头不止损,而空头第二根bar就平仓,是什么原因? - TradeBlazer公式 [开拓者 TB]
- 咨询内容:
一个简单的股指程序,高于upline开空,低于downline开多,开仓比较顺利,但止损问题很大,多头不止损,而空头第二根bar就平仓,是什么原因?请高手指点
Params
Numeric offset(10);
Numeric stoplossSet(5);
Vars
Numeric EntryPrice;
NumericSeries upline;
NumericSeries downline;
Bool Condition1;
Bool Condition2;
BoolSeries bShortStoped ;
BoolSeries bLongStoped ;
Begin
if(CurrentBar == 0 || Date != Date[1])
{
bShortStoped = False ;
bLongStoped = False ;
} Else
{
upline = Close[1] + offset ;
downline = Close[1] - offset;
Condition1 =( MarketPosition == 0 && High> upline && bShortStoped == False && Time < 0.151000);
Condition2 = (MarketPosition == 0 && Low< downline && bLongStoped == False && Time < 0.151000);
Commentary("Condition1="+IIFString(Condition1,"True","False"));
Commentary("Condition2="+IIFString(Condition2,"True","False"));
PlotNumeric ("upline",upline) ;
PlotNumeric ("dowmline",downline) ;
}
if (Condition1)
{
EntryPrice=Min(open,upline-0.2);
SellShort(1,EntryPrice);
}
if (Condition2)
{
EntryPrice = Max(open,downline+0.2);
Buy(1,EntryPrice);
}
If(MarketPosition==1 /*&& Low <= EntryPrice - StopLossSet */&& BarsSinceEntry>0)
{
Sell(1,Min(Open,EntryPrice - StopLossSet));
bLongStoped = True;
}
if(MarketPosition==-1 /*&& High >= EntryPrice + StopLossSet */&& BarsSinceEntry>0)
{
BuyToCover(1,Max(EntryPrice + StopLossSet,open));
bShortStoped = True;
}
if(Time >= 0.1513)
{
BuyToCover(1,Open);
Sell(1,Open);
}
End - TB技术人员:
为什么你的EntryPrice要在不同条件下分别计算?直接用AvgEntryPrice代替试试?
- TB客服:
nopain 发表于 2012-5-18 14:15
为什么你的EntryPrice要在不同条件下分别计算?直接用AvgEntryPrice代替试试?
谢谢。可试了还是不行啊。。。纠结。开仓部分没什么问题,止损部分问题大 - 网友回复:
你的upline,dnline计算有问题。
完整代码如下:- Params
- Numeric offset(10);
- Numeric stoplossSet(5);
- Vars
- Numeric MyEntryPrice;
- NumericSeries upline;
- NumericSeries downline;
- Bool Condition1;
- Bool Condition2;
- BoolSeries bShortStoped;
- BoolSeries bLongStoped;
- Begin
- if(CurrentBar == 0 || Date != Date[1])
- {
- bShortStoped = False ;
- bLongStoped = False ;
- upline = Close[1] + offset;
- downline = Close[1] - offset;
- } Else
- {
- Condition1 =( MarketPosition == 0 && High> upline && bShortStoped == False && Time < 0.151000);
- Condition2 = (MarketPosition == 0 && Low< downline && bLongStoped == False && Time < 0.151000);
-
- Commentary("Condition1="+IIFString(Condition1,"True","False"));
- Commentary("Condition2="+IIFString(Condition2,"True","False"));
- PlotNumeric ("upline",upline) ;
- PlotNumeric ("dowmline",downline) ;
- }
-
- if (Condition1)
- {
- MyEntryPrice=Min(open,upline-0.2);
- SellShort(1,MyEntryPrice);
- }
-
- if (Condition2)
- {
- MyEntryPrice = Max(open,downline+0.2);
- Buy(1,MyEntryPrice);
- }
-
-
- If(MarketPosition==1 && Low <= AvgEntryPrice - StopLossSet && BarsSinceEntry>0)
- {
- Sell(1,Min(Open,AvgEntryPrice - StopLossSet));
- bLongStoped = True;
- }
- if(MarketPosition==-1 && High >= AvgEntryPrice + StopLossSet && BarsSinceEntry>0)
- {
- BuyToCover(1,Max(AvgEntryPrice + StopLossSet,open));
- bShortStoped = True;
- }
-
- if(Time >= 0.1513)
- {
- BuyToCover(1,Open);
- Sell(1,Open);
- }
- End
- Params
- 网友回复:
nopain 发表于 2012-5-18 15:55
你的upline,dnline计算有问题。
完整代码如下:
多谢多谢,可以正常止损了。值得好好总结
如果以上指标公式不适用于您常用的行情软件
或者您想改编成选股公式,以便快速选出某种形态个股的话,
相关文章
-
没有相关内容