以文本方式查看主题 - 金字塔客服中心 - 专业程序化交易软件提供商 (http://222.73.7.161/bbs/index.asp) -- 公式模型编写问题提交 (http://222.73.7.161/bbs/list.asp?boardid=4) ---- TB转金字塔 (http://222.73.7.161/bbs/dispbbs.asp?boardid=4&id=184947) |
-- 作者:你幸福吗 -- 发布时间:2021/3/30 8:38:47 -- TB转金字塔 老师好,请您帮忙改成金字塔的交易模型吧,TB的我实在是适应不了,谢谢您啦! 代码如下: Params Numeric OFF(0);
Numeric M(85);
Numeric ZJL(10);
Numeric STPRATE(3.5); Vars
Numeric MN2;
Numeric MN3;
Series<Numeric> MA2;
Series<Numeric> MA3;
Numeric P;
Series<Numeric> MID1;
Series<Numeric> UPPER1;
Series<Numeric> LOWER1;
Series<Numeric> BLDK1;
Series<Bool> BuyConPre;
Series<Bool> SelConPre;
Bool BuyCon;
Bool SelCon;
Numeric BuyPrice;
Numeric SelPrice;
Numeric MINDIFF;
Numeric BuySTPPrice;
Numeric SelSTPPrice;
Series<Bool> BuyExitCon2PRE;
Series<Bool> BuyExitCon3PRE;
Series<Bool> BuyExitCon8PRE;
Series<Bool> SelExitCon2PRE;
Series<Bool> SelExitCon3PRE;
Series<Bool> SelExitCon8PRE;
Bool BuyExitCon2;
Bool BuyExitCon3;
Bool BuyExitCon8;
Bool SelExitCon2;
Bool SelExitCon3;
Bool SelExitCon8;
Numeric BuyExitPrice2;
Numeric SelExitPrice2;
Numeric BuyExitPrice3;
Numeric SelExitPrice3;
Numeric BuyExitPrice8;
Numeric SelExitPrice8;
Numeric LotsOrder;
Series<Numeric> XH;
Series<Numeric> XL;
Series<Numeric> MAH;
Series<Numeric> MAL;
Series<Numeric> ZH;
Series<Numeric> ZL; Events onBar(ArrayRef<Integer> indexs) {
//------------------------------------------------------------------
XH=(H+C)/2;
XL=(L+C)/2;
MAH=(AverageFC(XH,2)+AverageFC(XH,4))/2;
MAL=(AverageFC(XL,2)+AverageFC(XL,4))/2;
ZH=MAH*(1+1/10000);
ZL=MAL*(1-1/10000);
//------------------------------------------------------------------
P=2;
MID1 = AverageFC(CLOSE,M);
UPPER1= MID1 + P*StandardDev(CLOSE,M,2);
LOWER1= MID1 - P*StandardDev(CLOSE,M,2);
BLDK1 = (UPPER1-LOWER1)/MID1;
//------------------------------------------------------------------
MN2=INTPART(M/2);
MN3=INTPART(2*M);
MA2 = AverageFC(CLOSE,MN2);
MA3 = AverageFC(CLOSE,MN3);
//------------------------------------------------------------------
MINDIFF = MinMove*PriceScale;
//------------------------------------------------------------------
BuyConPre = (CLOSE>MA2 AND MA2>=MID1 AND MID1>=MID1[1] AND MA3>=MA3[1] AND CLOSE>=UPPER1 AND ZH>=ZH[1]);
SelConPre = (CLOSE<MA2 AND MA2<=MID1 AND MID1<=MID1[1] AND MA3<=MA3[1] AND CLOSE<=LOWER1 AND ZL<=ZL[1]);
BuyCon = BuyConPre[1];
SelCon = SelConPre[1];
//---------------------------------------------------------------
BuyPrice = OPEN+OFF*MINDIFF;
SelPrice = OPEN-OFF*MINDIFF;
//---------------------------------------------------------------
LotsOrder = Max(1,max(FLOOR(ZJL*10000/(CLOSE[1]*ContractUnit*0.1),1),1));
//---------------------------------------------------------------
If(BuyCon and MarketPosition<=0)
{
If(MarketPosition<0)
{
BuyToCover(LotsOrder,BuyPrice);
}
If(BuyCon)
{
Buy(LotsOrder,BuyPrice);
}
}
If(SelCon and MarketPosition>=0)
{
If(MarketPosition>0)
{
Sell(LotsOrder,SelPrice);
}
If(SelCon)
{
SELLSHORT(LotsOrder,SelPrice);
}
}
//---------------------------------------------------------------
BuySTPPrice = AvgEntryPrice*(1 - STPRATE/100);
SelSTPPrice = AvgEntryPrice*(1 + STPRATE/100);
//-------------------------------------------------------------------------
//平仓条件区
BuyExitCon2PRE = (CLOSE<MID1);
SelExitCon2PRE = (CLOSE>MID1);
BuyExitCon3PRE = (MA2<=MA3 AND CLOSE<MA2);
SelExitCon3PRE = (MA2>=MA3 AND CLOSE>MA2);
BuyExitCon8PRE = (LOW<=BuySTPPrice);
SelExitCon8PRE = (High>=SelSTPPrice);
//-------------------------------------------------------------------------
BuyExitCon2 = (MarketPosition>0 and BuyExitCon2PRE[1]);
SelExitCon2 = (MarketPosition<0 and SelExitCon2PRE[1]);
BuyExitCon3 = (MarketPosition>0 and BuyExitCon3PRE[1]);
SelExitCon3 = (MarketPosition<0 and SelExitCon3PRE[1]);
BuyExitCon8 = (MarketPosition>0 and BuyExitCon8PRE);
SelExitCon8 = (MarketPosition<0 and SelExitCon8PRE);
//-------------------------------------------------------------------------
BuyExitPrice2 = OPEN-OFF*MINDIFF;
BuyExitPrice3 = OPEN-OFF*MINDIFF;
SelExitPrice2 = OPEN-OFF*MINDIFF;
SelExitPrice3 = OPEN-OFF*MINDIFF;
BuyExitPrice8 = Min(OPEN,BuySTPPrice)-OFF*MINDIFF;
SelExitPrice8 = Max(OPEN,SelSTPPrice)-OFF*MINDIFF;
//-------------------------------------------------------------------------
If(BuyExitCon2)
{
Sell(LotsOrder,BuyExitPrice2);
}
If(BuyExitCon3)
{
Sell(LotsOrder,BuyExitPrice3);
}
If(BuyExitCon8)
{
Sell(LotsOrder,BuyExitPrice8);
}
If(SelExitCon2)
{
BuyToCover(LotsOrder,SelExitPrice2);
}
If(SelExitCon3)
{
BuyToCover(LotsOrder,SelExitPrice3);
}
If(SelExitCon8)
{
BuyToCover(LotsOrder,SelExitPrice8);
}
} //------------------------------------------------------------------------ |
-- 作者:FireScript -- 发布时间:2021/3/30 8:44:32 -- 抱歉,这种没发改的。通常我们只会尝试帮客户改一些语法相近的代码。但是这种差异较大的通常我们没办法做的。 |
-- 作者:你幸福吗 -- 发布时间:2021/3/30 16:19:11 -- 语法差异大?您指的是文华和金字塔的差异小,TB和金字塔的差异大吗? |
-- 作者:FireScript -- 发布时间:2021/3/30 16:27:46 -- 只是相对而言是这样。代码每一家软件都不是通用的,能语法相似已经算比较友好了,比如文华的,底层具体实现以及一些机制方面的差异往往都很多。 TB我们了解也不多,所以不好进行转换。我要转换这个 我还要先去单独学习TB的东西,这个不太现实。 所以通常我们建议客户能以文字形式描述思路,其他软件的代码 理解误差再加上实现过程中的偏差,效果一般都不太好的。 |