求助,一个简单的程序,请教高手指出问题所在 - TradeBlazer公式 [开拓者 TB]
- 咨询内容:
今日价格突破前一日最高价,则买入开仓一手;价格跌破前一日最低价,卖出开仓一手。止损为开仓价回撤5个点(股指期货),否则收盘时以收盘价平仓。
Params
Numeric StopLossSet(25);
Vars
Bool Condition1;
Bool Condition2;
Numeric MinPoint;
Numeric MyEntryPrice;
Numeric MyExitPrice;
NumericSeries HighD(0);
NumericSeries LowD(0);
Numeric price1;
Numeric price2;
Begin
MinPoint = MinMove*PriceScale;
Condition1 = HighD>HighD[1];
Condition2 = LowD <LowD[1];
if (Condition1) Price1=HighD;
{
Buy(1,Price1);
}
if (Condition2) Price2=LowD;
{
SellShort(1,Price2);
}
If(MarketPosition==1)
if(Low <= MyEntryPrice - StopLossSet*MinPoint)
{
MyExitPrice = MyEntryPrice - StopLossSet*MinPoint;
Sell(0,MyExitPrice);
}Else Sell(0,CloseD(0));
if(MarketPosition==-1)
if(High >= MyEntryPrice + StopLossSet*MinPoint)
{
MyExitPrice = MyEntryPrice + StopLossSet*MinPoint;
BuyToCover(0,MyExitPrice);
}Else BuyToCover(0,CloseD(0));
End - TB技术人员:
Params
Numeric StopLossSet(25);
Vars
Bool Condition1;
Bool Condition2;
Numeric MinPoint;
Numeric MyEntryPrice;
Numeric MyExitPrice;
NumericSeries HighD(0);
NumericSeries LowD(0);
Numeric price1;
Numeric price2;
Begin
MinPoint = MinMove*PriceScale;
Condition1 = HighD>HighD[1];
Condition2 = LowD <LowD[1];
if (Condition1) Price1=HighD;
{
Buy(1,Price1);
}最好判断持仓情况,不然有可能不停开仓, Price1=HighD也应该放在花括号内,还有,这个价格不一定能成交
if (Condition2) Price2=LowD;
{
SellShort(1,Price2);
}
If(MarketPosition==1)
if(Low <= MyEntryPrice - StopLossSet*MinPoint)
{
MyExitPrice = MyEntryPrice - StopLossSet*MinPoint;
Sell(0,MyExitPrice)可能不成交;
}Else Sell(0,CloseD(0))都收盘了,还能交易?只能用来历史测试;
if(MarketPosition==-1)
if(High >= MyEntryPrice + StopLossSet*MinPoint)
{
MyExitPrice = MyEntryPrice + StopLossSet*MinPoint;
BuyToCover(0,MyExitPrice);
}Else BuyToCover(0,CloseD(0));
End
这玩意不能用。。。 - TB客服:
回复 2# edwardzhangxu
现在还处在学习编程的初级阶段,离应用还远着的。问题还很多,在1分钟线上测试出来是每分钟都有开仓平仓。第二个问题关于收盘的如何修改成以15:14分价格成交? - 网友回复:
本帖最后由 飞跃 于 2012-2-29 20:43 编辑
由于手头没有TB软件,临时发一个修改好的,可能中间有些不太合适,可以在调整下。
Params
Numeric StopLossSet(0.5);
Vars
Bool Condition1;
Bool Condition2;
Numeric MinPoint;
Numeric MyEntryPrice;
Numeric StopLine;
NumericSeries HigherAfterEntry;
NumericSeries LowerAfterEntry;
NumericSeries PreEntryPrice;
NumericSeries DayOpen;
NumericSeries HighDD(0);
NumericSeries LowDD(0);
Numeric MyExitPrice;
BoolSeries bLongStoped;
BoolSeries bShortStoped;
Begin
MinPoint = MinMove*PriceScale;
HighDD = HighD(1);
LowDD = LowD(1);
PlotNumeric("HighDD",HighDD);
PlotNumeric("LowDD",LowDD);
Condition1 = High >HighDD;
Condition2 = Low <LowDD;
Commentary("Condition1="+IIFString(Condition1,"True","False"));
Commentary("Condition2="+IIFString(Condition2,"True","False"));
If(CurrentBar==0 || Date!=Date[1])
{
bLongStoped = False;
bShortStoped = False;
}Else
{
bLongStoped = bLongStoped[1];
bShortStoped = bShortStoped[1];
}
if(MarketPosition == 0 && Condition1 && bLongStoped==False && Time < 0.1455)
{
MyEntryPrice = HighDD + MinPoint;
if(Open > HighDD)
MyEntryPrice = Open;
Buy(1,MyEntryPrice);
bLongStoped==False;
}
if(MarketPosition == 0 && Condition2 && bShortStoped == False && Time < 0.1455)
{
MyEntryPrice = LowDD - MinPoint;
If(Open < LowDD)
MyEntryPrice = Open;
SellShort(1,MyEntryPrice);
bShortStoped = False;
}
If(MarketPosition==1 && Low <= MyEntryPrice - StopLossSet*MinPoint)
{
MyExitPrice = PreEntryPrice - StopLossSet*MinPoint;
If(Open < MyExitPrice)
MyExitPrice = Open;
Sell(0,MyExitPrice);
bLongStoped==True;
}Else
if(MarketPosition==-1 && High >= MyEntryPrice + StopLossSet*MinPoint )
{
MyExitPrice = PreEntryPrice + StopLossSet*MinPoint;
if(Open > MyExitPrice)
MyExitPrice = Open;
BuyToCover(0,MyExitPrice);
bShortStoped = True;
}
if(Time >= 0.1455)
{
BuyToCover(0,Open);
Sell(0,Open);
}
End - 网友回复:
你这个还可以把开仓的线画出来,也应该加一个止盈的策略,呵呵
相关文章
-
没有相关内容