求解此程序的问题在哪里? [开拓者 TB]
- 咨询内容:
Params
Numeric N1(6);
Numeric N2(5);
Numeric FastLength(12);
Numeric SlowLength(26);
Numeric MACDLength(9);
Numeric Lots(1);
Numeric X(10);
Vars
Numeric HD;
Numeric MACDValue;
Numeric AvgMACD;
NumericSeries M1;
NumericSeries M2;
NumericSeries HH;
NumericSeries LL;
Numeric bartime;
String sectionname;
String PCName;
String MP;
Numeric OrderIndex;
Begin
HD=MinMove*PriceScale;
MACDValue = XAverage( Close, FastLength ) - XAverage( Close, SlowLength ) ;
AvgMACD = XAverage(MACDValue,MACDLength);
M1 = dema(c,5);
M2 = dema(c,22);
If(MarketPosition!=0) //画开仓价
{PlotNumeric("c",EntryPrice);}
If(CurrentBar < MaxBarsBack) Return;
// 当前BAR的日期和时间
bartime = Date*1000000+Time*1000000;
// 准备保存交易信号的数据库块名
sectionname = Symbol+"_"+IIFString(BarType==0,"D","M")+Text(BarInterval)+"_"+FormulaName;
PCName = Symbol+"_"+IIFString(BarType==0,"D","M")+Text(BarInterval)+"_"+FormulaName;
// 实时交易才记录交易信号
If(BarStatus == 2 And Date == CurrentDate)
{
MP = GetTBProfileString(sectionname,Text(bartime)+"_MP");
//If(MarketPosition <>1 && M1[1] > M2[1])
If( MP <> "1" And MarketPosition ==0 And MACDValue >=AvgMACD AND M1>=M2 )
{
// 按顺序给当前BAR的交易信号编号并记录在数据库中
OrderIndex = Value(GetTBProfileString(sectionname,Text(bartime)+"_OrderCnt"));
If(OrderIndex == InvalidNumeric) OrderIndex = 1;
Else OrderIndex = OrderIndex + 1;
SetTBProfileString(sectionname,Text(bartime)+"_TotalOrder",Text(OrderIndex));
// 记录数据库交易信号的MarketPosition
MP = "1";
SetTBProfileString(sectionname,Text(bartime)+"_MP",MP);
// 记录交易信号的方向和价格,1多 -1空
//Buy(Lots,Open);
SetTBProfileString(sectionname,Text(bartime)+"_Order_"+Trim(Text(OrderIndex)),"1");
SetTBProfileString(sectionname,Text(bartime)+"_Price_"+Trim(Text(OrderIndex)),Text(Close));
}
//If(MarketPosition <>-1 && M1[1] < M2[1])
If(MP <> "-1" And MarketPosition ==0 And MACDValue<=AvgMACD AND M1<=M2)
{
// 按顺序给当前BAR的交易信号编号并记录在数据库中
OrderIndex = Value(GetTBProfileString(sectionname,Text(bartime)+"_OrderCnt"));
If(OrderIndex == InvalidNumeric) OrderIndex = 1;
Else OrderIndex = OrderIndex + 1;
SetTBProfileString(sectionname,Text(bartime)+"_TotalOrder",Text(OrderIndex));
// 记录数据库交易信号的MarketPosition
MP = "-1";
SetTBProfileString(sectionname,Text(bartime)+"_MP",MP);
// 记录交易信号的方向和价格,1多 -1空
//SellShort(Lots,Open);
SetTBProfileString(sectionname,Text(bartime)+"_Order_"+Trim(Text(OrderIndex)),"-1");
SetTBProfileString(sectionname,Text(bartime)+"_Price_"+Trim(Text(OrderIndex)),Text(Close));
}
}
// 根据数据库中记录的该BAR的交易信号,顺序发出交易指令
// 第一笔交易
OrderIndex =1;
If(GetTBProfileString(sectionname,Text(bartime)+"_Order_"+Text(OrderIndex)) == InvalidString) // 没有记录则返回
{
Return;
}
Else // 否则发出交易指令
{
If(GetTBProfileString(sectionname,Text(bartime)+"_Order_"+Text(OrderIndex)) == "1")
{
Buy(0,Value(GetTBProfileString(sectionname,Text(bartime)+"_Price_"+Text(OrderIndex))));
}
Else If(GetTBProfileString(sectionname,Text(bartime)+"_Order_"+Text(OrderIndex)) == "-1")
{
SellShort(0,Value(GetTBProfileString(sectionname,Text(bartime)+"_Price_"+Text(OrderIndex))));
}
}
//定义开仓后的最高最低点
If(MarketPosition<>0)
{
If(GetTBProfileString(PCname,Text(bartime)+"HH") == InvalidString) //开仓时记录开仓价位高低点
{
SetTBProfileString(PCName,Text(bartime)+"HH",Text(EntryPrice));
SetTBProfileString(PCName,Text(bartime)+"LL",Text(EntryPrice));
}
Else
{
If(C>Value(GetTBProfileString(PCName,Text(bartime)+"HH"))) //开仓后更新高点
{
SetTBProfileString(PCName,Text(bartime)+"HH",Text(C));
}
If(C<Value(GetTBProfileString(PCName,Text(bartime)+"LL"))) //开仓后更新低点
{
SetTBProfileString(PCName,Text(bartime)+"LL",Text(C));
}
}
}
If(MarketPosition==1 )
{
If( Value(GetTBProfileString(pcname,Text(bartime)+"LL"))<=EntryPrice-X*HD)
{Sell(0,Min(o,EntryPrice-X*HD));} //止损
ELSE If(Value(GetTBProfileString(pcname,Text(bartime)+"HH"))>=EntryPrice+X*HD AND C<=Value(GetTBProfileString(pcname,Text(bartime)+"HH"))-X*HD) //跟踪止盈
{Sell(0,Min(o,Value(GetTBProfileString(pcname,Text(bartime)+"HH"))-X*HD));}
}
If(MarketPosition==-1 )
{
If( Value(GetTBProfileString(pcname,Text(bartime)+"HH"))>=EntryPrice+X*HD)
{BuyToCover(0,Max(o,EntryPrice+X*HD));}
ELSE If(Value(GetTBProfileString(pcname,Text(bartime)+"LL"))<=EntryPrice-X*HD AND C>=Value(GetTBProfileString(pcname,Text(bartime)+"LL"))+X*HD)
{BuyToCover(0,MAX(o,Value(GetTBProfileString(pcname,Text(bartime)+"LL"))+X*HD));}
}
END - TB技术人员: 你程序输出有什么问题
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 1145508240 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容