Turtle Trader海龟交易法则 程序化交易系统 交易开拓者必学源码
//------------------------------------------------------------------------
// ?ò?Æ: TurtleTrader
// Ãû?Æ: º??ê??Ò×ϵÍ?
// Àà?ð: ??Ê?Ó?ÓÃ
// ÀàÐÍ: ÄÚ??Ó?ÓÃ
//------------------------------------------------------------------------
Params
Numeric RiskRatio(1); // % Risk Per N ( 0 - 100)
Numeric ATRLength(20); // Æ??ù????ÖÜÆÚ ATR Length
Numeric boLength(20); // ?ÌÖÜÆÚ BreakOut Length
Numeric fsLength(55); // ??ÖÜÆÚ FailSafe Length
Numeric teLength(10); // ÀëÊÐÖÜÆÚ Trailing Exit Length
Bool LastProfitableTradeFilter(True); // Ê?ÓÃÈëÊÐ?ýÂËÌõ?þ Vars
Numeric MinPoint; // ×îÐ??ä??µ?Î?
NumericSeries AvgTR; // ATR
Numeric N; // N Öµ
Numeric TotalEquity;
// ??×îÐÂÊÕÅÌ?Û?ÆËã?öµÄ×Ü×Ê?ú
Numeric TurtleUnits; // ??Ò×µ?Î?
NumericSeries DonchianHi; //
ÌÆÆæ??Í?µÀÉÏ?ì??ÑÓºó1?öBar
NumericSeries DonchianLo; //
ÌÆÆæ??Í?µÀÏÂ?ì??ÑÓºó1?öBar
NumericSeries fsDonchianHi; //
ÌÆÆæ??Í?µÀÉÏ?ì??ÑÓºó1?öBar????ÖÜÆÚ
NumericSeries fsDonchianLo; //
ÌÆÆæ??Í?µÀÏÂ?ì??ÑÓºó1?öBar????ÖÜÆÚ
Numeric ExitHighestPrice; //
ÀëÊÐÊ?ÅÐ?ÏÐèÒªµÄNÖÜÆÚ×î?ß?Û
Numeric ExitLowestPrice; //
ÀëÊÐÊ?ÅÐ?ÏÐèÒªµÄNÖÜÆÚ×îµÍ?Û
Numeric myEntryPrice; // ?ª?Ö?Û?ñ
Numeric myExitPrice; // Æ??Ö?Û?ñ
Bool SendOrderThisBar(False); // µ?Ç?BarÓÐ?ý??Ò×
NumericSeries preEntryPrice(0); // Ç?Ò??Î?ª?ÖµÄ?Û?ñ
BoolSeries PreBreakoutFailure(false); // Ç?Ò??ÎÍ?ÆÆÊÇ?ñÊ??Ü Begin
If(BarStatus == 0)
{
preEntryPrice = InvalidNumeric;
PreBreakoutFailure = false;
}
MinPoint = MinMove*PriceScale;
AvgTR = XAverage(TrueRange,ATRLength);
N = AvgTR[1];
TotalEquity = Portfolio_CurrentCapital() + Portfolio_UsedMargin();
TurtleUnits = (TotalEquity*RiskRatio/100) /(N * ContractUnit()*BigPointValue());
TurtleUnits = IntPart(TurtleUnits); // ?ÔÐ?ÊýÈ?Õû
DonchianHi = HighestFC(High[1],boLength);
DonchianLo = LowestFC(Low[1],boLength);
fsDonchianHi = HighestFC(High[1],fsLength);
fsDonchianLo = LowestFC(Low[1],fsLength);
ExitLowestPrice = LowestFC(Low[1],teLength);
ExitHighestPrice = HighestFC(High[1],teLength);
Commentary("N="+Text(N));
Commentary("preEntryPrice="+Text(preEntryPrice));
Commentary("PreBreakoutFailure="+IIFString(PreBreakoutFailure,"True","False"));
//
µ???Ê?ÓÃ?ýÂËÌõ?þ???òÕßÊ?ÓÃ?ýÂËÌõ?þ??ÇÒÌõ?þΪPreBreakoutFailureΪTr
ue?øÐкóÐø?Ù×?
If(MarketPosition == 0 && ((!LastProfitableTradeFilter) Or (PreBreakoutFailure)))
{
// Í?ÆÆ?ª?Ö
If(High > DonchianHi && TurtleUnits >= 1)
{
//
?ª?Ö?Û?ñÈ?Í?ÆÆÉÏ?ì+Ò??ö?ÛÎ?ºÍ×î?ß?ÛÖ??äµÄ?ÏÐ?Öµ??ÕâÑùÄÜ?ü?Ó?üÕæʵÇ
é?ö????ÄÜ??Á???Ö??É??
myEntryPrice = min(high,DonchianHi + MinPoint);
myEntryPrice = IIF(myEntryPrice < Open, Open,myEntryPrice);
// ?óÌø?ÕµÄÊ?ºòÓÃ?ªÅÌ?Û?úÌæ
preEntryPrice = myEntryPrice;
Buy(TurtleUnits,myEntryPrice);
SendOrderThisBar = True;
PreBreakoutFailure = False;
}
If(Low < DonchianLo && TurtleUnits >= 1)
{
//
?ª?Ö?Û?ñÈ?Í?ÆÆÏÂ?ì-Ò??ö?ÛÎ?ºÍ×îµÍ?ÛÖ??äµÄ?Ï?óÖµ??ÕâÑùÄÜ?ü?Ó?üÕæʵÇé?ö????ÄÜ??Á???Ö??É??
myEntryPrice = max(low,DonchianLo - MinPoint);
myEntryPrice = IIF(myEntryPrice > Open, Open,myEntryPrice);
// ?óÌø?ÕµÄÊ?ºòÓÃ?ªÅÌ?Û?úÌæ
preEntryPrice = myEntryPrice;
SendOrderThisBar = True;
SellShort(TurtleUnits,myEntryPrice);
SendOrderThisBar = True;
PreBreakoutFailure = False;
}
}
// ??ÖÜÆÚÍ?ÆÆ?ª?Ö Failsafe Breakout point
If(MarketPosition == 0)
{
Commentary("fsDonchianHi="+Text(fsDonchianHi));
If(High > fsDonchianHi && TurtleUnits >= 1)
{
//
?ª?Ö?Û?ñÈ?Í?ÆÆÉÏ?ì+Ò??ö?ÛÎ?ºÍ×î?ß?ÛÖ??äµÄ?ÏÐ?Öµ??ÕâÑùÄÜ?ü?Ó?üÕæʵÇé?ö????ÄÜ??Á???Ö??É??
myEntryPrice = min(high,fsDonchianHi + MinPoint);
myEntryPrice = IIF(myEntryPrice < Open, Open,myEntryPrice);
// ?óÌø?ÕµÄÊ?ºòÓÃ?ªÅÌ?Û?úÌæ
preEntryPrice = myEntryPrice;
Buy(TurtleUnits,myEntryPrice);
SendOrderThisBar = True;
PreBreakoutFailure = False;
}
Commentary("fsDonchianLo="+Text(fsDonchianLo));
If(Low < fsDonchianLo && TurtleUnits >= 1)
{
//
?ª?Ö?Û?ñÈ?Í?ÆÆÏÂ?ì-Ò??ö?ÛÎ?ºÍ×îµÍ?ÛÖ??äµÄ?Ï?óÖµ??ÕâÑùÄÜ?ü?Ó?üÕæʵÇé?ö????ÄÜ??Á???Ö??É??
myEntryPrice = max(low,fsDonchianLo - MinPoint);
myEntryPrice = IIF(myEntryPrice > Open, Open,myEntryPrice); // ?óÌø?ÕµÄÊ?ºòÓÃ?ªÅÌ?Û?úÌæ
preEntryPrice = myEntryPrice;
SellShort(TurtleUnits,myEntryPrice);
SendOrderThisBar = True;
PreBreakoutFailure = False;
}
}
If(MarketPosition == 1) // ÓÐ?à?ÖµÄÇé?ö
{
Commentary("ExitLowestPrice="+Text(ExitLowestPrice));
If(Low < ExitLowestPrice)
{
myExitPrice = max(Low,ExitLowestPrice - MinPoint);
myExitPrice = IIF(myExitPrice > Open, Open,myExitPrice); // ?óÌø?ÕµÄÊ?ºòÓÃ?ªÅÌ?Û?úÌæ
Sell(0,myExitPrice); // ÊýÁ?ÓÃ0µÄÇé?öÏÂ??È???Æ??Ö
}Else
{
If(preEntryPrice!=InvalidNumeric && TurtleUnits >= 1)
{
If(Open >= preEntryPrice + 0.5*N) // Èç?û?ªÅÌ?Í???ýÉè??µÄ1/2N,ÔòÖ??ÓÓÃ?ªÅÌ?ÛÔö?Ö??
{
myEntryPrice = Open;
preEntryPrice = myEntryPrice;
Buy(TurtleUnits,myEntryPrice);
SendOrderThisBar = True;
}
while(High >= preEntryPrice + 0.5*N) // ÒÔ×î?ß?ÛΪ?ê×???ÅÐ?ÏÄÜ?øÐÐ???ÎÔö?Ö
{
myEntryPrice = preEntryPrice + 0.5 * N;
preEntryPrice = myEntryPrice;
Buy(TurtleUnits,myEntryPrice);
SendOrderThisBar = True;
}
}
// Ö?ËðÖ?Áî
If(Low <= preEntryPrice - 2 * N && SendOrderThisBar == false)
// ?Ó?ÖBar??Ö?Ëð
{
myExitPrice = preEntryPrice - 2 * N;
Sell(0,myExitPrice); // ÊýÁ?ÓÃ0µÄÇé?öÏÂ??È???Æ??Ö
PreBreakoutFailure = True;
}
}
}Else If(MarketPosition ==-1) // ÓÐ?Õ?ÖµÄÇé?ö
{
// Çó?ö?Ö?Õ?ÖÊ?ÀëÊеÄÌõ?þ?È?ÏÖµ
Commentary("ExitHighestPrice="+Text(ExitHighestPrice));
If(High > ExitHighestPrice)
{
myExitPrice = Min(High,ExitHighestPrice + MinPoint);
myExitPrice = IIF(myExitPrice < Open, Open,myExitPrice); // ?óÌø?ÕµÄÊ?ºòÓÃ?ªÅÌ?Û?úÌæ
BuyToCover(0,myExitPrice); //
ÊýÁ?ÓÃ0µÄÇé?öÏÂ??È???Æ??Ö
}Else
{
If(preEntryPrice!=InvalidNumeric && TurtleUnits >= 1)
{
If(Open <= preEntryPrice - 0.5*N) // Èç?û?ªÅÌ?Í???ýÉè??µÄ1/2N,ÔòÖ??ÓÓÃ?ªÅÌ?ÛÔö?Ö??
{
myEntryPrice = Open;
preEntryPrice = myEntryPrice;
SellShort(TurtleUnits,myEntryPrice);
SendOrderThisBar = True;
}
while(Low <= preEntryPrice - 0.5*N) // ÒÔ×îµÍ?ÛΪ?ê×???ÅÐ?ÏÄÜ?øÐÐ???ÎÔö?Ö
{
myEntryPrice = preEntryPrice - 0.5 * N;
preEntryPrice = myEntryPrice;
SellShort(TurtleUnits,myEntryPrice);
SendOrderThisBar = True;
}
}
// Ö?ËðÖ?Áî
If(High >= preEntryPrice + 2 * N &&SendOrderThisBar==false) // ?Ó?ÖBar??Ö?Ëð
{
myExitPrice = preEntryPrice + 2 * N;
BuyToCover(0,myExitPrice); //
ÊýÁ?ÓÃ0µÄÇé?öÏÂ??È???Æ??Ö
PreBreakoutFailure = True;
}
}
}
End
//----------------------------------------------------------------
--------
// ?àÒë?æ?? GS2010.12.08
// ?æÈ?ËùÓÐ TradeBlazer Software 2003?,2010 // ?ü?ÄÉùÃ? TradeBlazer Software??Áô?ÔTradeBlazerÆ? // Ì?Ã?Ò??æ??µÄTradeBlazer??Ê?ÐÞ?ĺÍÖØÐ?µÄÈ?Àû //----------------------------------------------------------------
--------
本文档为【Turtle Trader海龟交易法则 程序化交易系统 交易开拓者必学源码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。