TB公式中加倉問題 [開拓者 TB]
- 咨詢內容:
問題描述:
1. 實盤操作加倉未成功(autotrade沒有加倉記錄,實際賬戶也沒有加倉記錄)
2. 我在加倉操作前面加了日志,卻記錄很多加倉記錄
本地記錄日志文件截取
20160111 90005 Add Sell: Unit=2, Price=5495
20160111 90005 Add Sell: Unit=2, Price=5495
20160111 90006 Add Sell: Unit=2, Price=5495
20160111 90006 Add Sell: Unit=2, Price=5495
20160111 90007 Add Sell: Unit=2, Price=5495
20160111 90007 Add Sell: Unit=2, Price=5495
20160111 90008 Add Sell: Unit=2, Price=5495
20160111 90008 Add Sell: Unit=2, Price=5495
20160111 90009 Add Sell: Unit=2, Price=5495
20160111 90009 Add Sell: Unit=2, Price=5495
20160111 90010 Add Sell: Unit=2, Price=5495
20160111 90010 Add Sell: Unit=2, Price=5495
20160111 90011 Add Sell: Unit=2, Price=5495
20160111 90011 Add Sell: Unit=2, Price=5495
....
參數定義源碼
Params
Numeric LongLength(60);
Numeric StopLossSet(20);
Numeric AvgLen(20); // 高低點均線計算周期
Numeric AbsDisp(5); // 高低點均線前移周期
Numeric AddSet(10); //加倉情況
Numeric FirstUnit(1);
Numeric AddUnit(2);
Numeric MaxUnit(5);
Numeric MaxLoss(2000);
Numeric TradeOffset(1); //交易滑點
Vars
//NumericSeries UpperAvg(0); // 通道上軌
NumericSeries LowerAvg(0); // 通道下軌
NumericSeries LongMA(0);
//NumericSeries ExitAvg(0); // 通道中軌
BoolSeries RangeLeadS(False); // 是否RangeLead
NumericSeries MedianPrice; // K線中價
NumericSeries range; // 振幅
NumericSeries HighestAfterEntry(0);
NumericSeries LowestAfterEntry(0);
Numeric MyPrice(0);
NumericSeries MyLastPrice(0);
NumericSeries MyUnit(0);
String LogFileName;
String Msg;
Bool ShouldCover(False);
加倉公式源代碼:
// 系統入場
//...省略代碼 參考 平移高低點均值通道與K線中值突破
// 系統出場或加倉
If(MarketPosition == -1) // 開倉后N根K線內用中軌止損,N根K線后用上軌止損,N=參數ExitBar
{
//初始化及計算動態止盈
MyPrice=Open;
ShouldCover=False;
if(BarsSinceEntry==0)
{
HighestAfterEntry=High;
LowestAfterEntry=Low;
}else
{
LowestAfterEntry = Min(LowestAfterEntry, Low);
HighestAfterEntry = Max(HighestAfterEntry, High);
}
Commentary("LowestAfterEntry"+Text(LowestAfterEntry));
Commentary("HighestAfterEntry"+Text( HighestAfterEntry));
//動態止損線
If(BarsSinceEntry>0)
{
Commentary(" LowestAfterEntry[1]"+Text( LowestAfterEntry[1]));
PlotNumeric("DynamicStopLossLine", LowestAfterEntry[1]+StopLossSet);
//動態止損
if(High>LowestAfterEntry[1]+StopLossSet)
{
ShouldCover=True;
MyPrice=LowestAfterEntry[1]+StopLossSet+TradeOffset;
}
//加倉
else if(Open<=MyLastPrice-AddSet and MyUnit<MaxUnit)
{
MyUnit=MyUnit+AddUnit;
MyLastPrice=Min(MyLastPrice-AddSet, Open-TradeOffset);
Sellshort(AddUnit,MyLastPrice);
Msg="Add Sell: Unit="+Text(AddUnit)+", Price="+Text(MyLastPrice);
LogMsg(Msg, BarStatus==2, LogFileName);
}
}
}
LogMsg函數源碼
Params
String Msg;
Bool Enabled(false);
String FileName("D:\\autotrade");
Vars
String LogTime;
String Path("D:\\Autotrade\\Trade_");
Begin
Commentary(Msg);
Path=Path+FileName+"_"+A_AccountID+"_"+Text(CurrentDate)+".log";
IF(Enabled)
{
LogTime=Text(CurrentDate)+" "+Text(CurrentTime*1000000)+" ";
FileAppend(Path, LogTime+Msg);
}
Return Msg;
End - TB技術人員:
追加系統入場代碼
// 集合競價和小節休息過濾
If(!CallAuctionFilter()) Return;
LogFileName="My_K_V3_S_"+Symbol;
// 指標計算
range = High - Low;
//UpperAvg = Average(High[AbsDisp], AvgLen); // 計算N周期前高點的MA,N=參數AbsDisp
LowerAvg = Average(Low[AbsDisp], AvgLen); // 計算N周期前低點的MA,N=參數AbsDisp
LongMA=Average(C, LongLength);
MedianPrice = (High + Low)*0.5; // 計算K線中點
PlotNumeric("LowMA",LowerAvg);
PlotNumeric("LongMA", LongMA);
PlotNumeric("LowerAvg", LowerAvg);
RangeLeadS = MedianPrice < Low[1] and Range > Range[1]; // 當K線中點小于前一根K線低點并且振幅〉上一根振幅時,RangeLeadS為真
//策略退出條件
if(NetProfit<=-MaxLoss)
{
If(MarketPosition!=0)
{
ShouldCover=True;
MyPrice=Open+TradeOffset;
}
PlotBool("Failed", false);
}
// 系統入場
Else If(MarketPosition == 0)
{
If(RangeLeadS[1] and Close[1] < LowerAvg[1] and LowerAvg<LowerAvg[1] and LongMA[1]<LongMA[2] ) // 上根K線RangeLeadS為真,并且上一根收盤價小于N周期前低點的MA,當前無空倉,則開空倉
{
MyUnit=FirstUnit;
MyLastPrice=Open-TradeOffset;
Sellshort(MyUnit, MyLastPrice);
Msg="SellShort: Unit="+Text(MyUnit)+", Price="+Text(MyLastPrice);
LogMsg(Msg, BarStatus==2, LogFileName);
}
}
- TB客服:
麻煩高手指點下問題所在,非常感謝!
- 網友回復:
sywg8011006110 發表于 2016-1-12 09:02
麻煩高手指點下問題所在,非常感謝!
先試一下在全局交易設置里設置為允許連續建倉,以及加倉次數設大一些,再看看信號有無加倉信號。 - 網友回復:
小米 發表于 2016-1-12 13:41
先試一下在全局交易設置里設置為允許連續建倉,以及加倉次數設大一些,再看看信號有無加倉信號。 ...
請問我的日志文件重復記錄日志怎么解釋?
有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友
可聯系技術人員 QQ: 511411198 進行 有償 編寫!(不貴!點擊查看價格!)
相關文章
-
沒有相關內容