多頭不止損,而空頭第二根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計算有問題。
完整代碼如下:
多謝多謝,可以正常止損了。值得好好總結
如果以上指標公式不適用于您常用的行情軟件
或者您想改編成選股公式,以便快速選出某種形態個股的話,
相關文章
-
沒有相關內容