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