[求助]请文华老师帮俺写个公式模型。 [文华财经]
- 咨询内容:
下面是公式的源码,好像是开拓者的,请转化成文华的,谢谢!
---------------------------------------------------------------
海龟交易系统公式源码如下:
//------------------------------------------------------------------------
// 简称: 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); // 前一次开仓的价格,存放到全局变量0号位置
BoolSeries PreBreakoutFailure(false); // 前一次突破是否失败
Begin
If(BarStatus == 0)
{
preEntryPrice = InvalidNumeric;
PreBreakoutFailure = false;
}Else
{
preEntryPrice = preEntryPrice[1];
PreBreakoutFailure = PreBreakoutFailure[1];
}
MinPoint = MinMove*PriceScale;
AvgTR = XAverage(TrueRange,ATRLength);
N = AvgTR[1];
TotalEquity = CurrentCapital()+ Abs(CurrentContracts()*Close*ContractUnit()*BigPointValue()*MarginRatio());
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);
Commentary("N="+Text(N));
Commentary("preEntryPrice="+Text(preEntryPrice));
Commentary("PreBreakoutFailure="+IIFString(PreBreakoutFailure,"True","False"));
// 当不使用过滤条件,或者使用过滤条件并且条件为PreBreakoutFailure为True进行后续操作
If(MarketPosition == 0 && ((!LastProfitableTradeFilter) Or (PreBreakoutFailure)))
{
// 突破开仓
If(CrossOver(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(CrossUnder(Low,DonchianLo) && TurtleUnits >= 1)
{
// 开仓价格取突破下轨-一个价位和最低价之间的较大值,这样能更接近真实情况,并能尽量保证成交
myEntryPrice = max(low,DonchianLo - MinPoint);
myEntryPrice = IIF(myEntryPrice > Open, Open,myEntryPrice); // 大跳空的时候用开盘价代替
preEntryPrice = myEntryPrice;
SendOrderThisBar = True;
SellShort(TurtleUnits,myEntryPrice);//本海龟交易系统来自智冠丰银www.fxsola.com
SendOrderThisBar = True;
PreBreakoutFailure = False;//sg
}
}
// 长周期突破开仓 Failsafe Breakout point
If(MarketPosition == 0)
{
Commentary("fsDfsDExitLowestPrice="+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) // 有空仓的情况
{
// 求出持空仓时离市的条件比较值
ExitHighestPrice = Highest(High[1],teLength);
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);//本海龟交易系统来自智冠丰银www.fxsola.com
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
- 文华技术人员:
海龟交易系统公式源码如下:
//------------------------------------------------------------------------
// 简称: 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); // 前一次开仓的价格,存放到全局变量0号位置
BoolSeries PreBreakoutFailure(false); // 前一次突破是否失败
Begin
If(BarStatus == 0)
{
preEntryPrice = InvalidNumeric;
PreBreakoutFailure = false;
}Else
{
preEntryPrice = preEntryPrice[1];
PreBreakoutFailure = PreBreakoutFailure[1];
}MinPoint = MinMove*PriceScale;
AvgTR = XAverage(TrueRange,ATRLength);
N = AvgTR[1];
TotalEquity = CurrentCapital()+ Abs(CurrentContracts()*Close*ContractUnit()*BigPointValue()*MarginRatio());
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);Commentary("N="+Text(N));
Commentary("preEntryPrice="+Text(preEntryPrice));
Commentary("PreBreakoutFailure="+IIFString(PreBreakoutFailure,"True","False"));
// 当不使用过滤条件,或者使用过滤条件并且条件为PreBreakoutFailure为True进行后续操作
If(MarketPosition == 0 && ((!LastProfitableTradeFilter) Or (PreBreakoutFailure)))
{
// 突破开仓
If(CrossOver(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(CrossUnder(Low,DonchianLo) && TurtleUnits >= 1)
{
// 开仓价格取突破下轨-一个价位和最低价之间的较大值,这样能更接近真实情况,并能尽量保证成交
myEntryPrice = max(low,DonchianLo - MinPoint);
myEntryPrice = IIF(myEntryPrice > Open, Open,myEntryPrice); // 大跳空的时候用开盘价代替
preEntryPrice = myEntryPrice;
SendOrderThisBar = True;
SellShort(TurtleUnits,myEntryPrice);//本海龟交易系统来自智冠丰银www.fxsola.com
SendOrderThisBar = True;
PreBreakoutFailure = False;//sg
}
}// 长周期突破开仓 Failsafe Breakout point
If(MarketPosition == 0)
{
Commentary("fsDfont-family: 宋体; font-size: 12px;"> Commentary("fsDfont-family: 宋体; font-size: 12px;"> If(MarketPosition == 1) // 有多仓的情况
{
// 求出持多仓时离市的条件比较值
ExitLowestPrice = Lowest(Low[1],teLength);
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) // 有空仓的情况
{
// 求出持空仓时离市的条件比较值
ExitHighestPrice = Highest(High[1],teLength);
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);//本海龟交易系统来自智冠丰银www.fxsola.com
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 - 文华客服:
RiskRatio:=1; // % Risk Per N ( 0 - 100) 账户的1%
ATRLength:=20; // 平均波动周期 ATR Length
boLength:=20; // 短周期BreakOut Length
fsLength:=55; // 长周期FailSafe Length
teLength:=10; // 离市周期 Trailing Exit Length
DW:=300; //合约的单位(请自行设定)
TR:= MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));
ATR:= MA(TR,ATRLength);
N:=REF(ATR,1);
TU:=FLOOR(MONEYTOT*RiskRatio/100)/(N*DW);
DonchianHi:= HHV(REF(H,1),boLength);//系统一:20日高点突破
DonchianLo:= LLV(REF(L,1),boLength);//系统一:20日低点突破
fsDonchianHi:= HHV(REF(H,1),fsLength);//系统二:55日高点突破
fsDonchianLo:= LLV(REF(L,1),fsLength);//系统二:55日低点突破
ExitLowestPrice:= LLV(REF(L,1),teLength);//系统一多头离市
ExitHighestPrice:= HHV(REF(H,1),teLength);//系统一空头离市
H>DonchianHi&&BKVOL=0&&NOT(ISLASTBK||ISLASTSK)&&TU>=1,BK(TU);
L<DonchianLo&&SKVOL=0&&NOT(ISLASTBK||ISLASTSK)&&TU>=1,SK(TU);
H>fsDonchianHi&&BKVOL=0&&NOT(ISLASTBK||ISLASTSK)&&TU>=1,BK(TU);
L<fsDonchianLo&&SKVOL=0&&NOT(ISLASTBK||ISLASTSK)&&TU>=1,SK(TU);
L<ExitLowestPrice&&BKVOL>0,SP(BKVOL);
L>=ExitLowestPrice&&H>=BKPRICE+N&&BKVOL<3*TU,BK(TU);
L<=BKPRICE-2*N&&BKVOL>0,SP(BKVOL);
H>ExitHighestPrice&&SKVOL>0,BP(SKVOL);
H>ExitHighestPrice&&L<=SKPRICE-N&&SKVOL<3*TU,SK(TU);
H>=SKPRICE+2*N&&SKVOL>0,BP(SKVOL);
MONO_SIGNAL; - 网友回复:
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 511411198 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容