开拓者期货期权程序化系统交易论坛
标题:
如何表达:当K线满足条件con1之后的5根K线之内同时满足条件con2,则开仓
[打印本页]
作者:
huangshuangyang
时间:
2014-7-12 07:48:00
标题:
如何表达:当K线满足条件con1之后的5根K线之内同时满足条件con2,则开仓
有哪位帅哥可以帮忙表达TB的一个编程,拜托了,一直写了很多很多次都编译不,需要变量可以自己定,我看得懂:
5分钟周期,当K线满足条件con1之后的5根K线之内同时满足条件con2,则开仓。
(备注:重点是表达5根K线之内,意思是满足条件con1之后的第一根K线,或第二根,或第三根,或第四根K线,或第五根K线,再次满足条件con2则开仓;
作者:
米小兔
时间:
2014-7-13 11:48:30
仅看楼主描述写了一点代码, 如果知道策略上下文, 可能还可以简化写法.
Params
Numeric CounterLimit(5);
Vars
BoolSeries Con1(false);
BoolSeries Con2(false);
Bool Entry(false);
NumericSeries Counter(0); //计数器;
Begin
//满足con1的k线将couter赋值为1;
if (Con1 and Counter[1] == 0)
{
Counter = 1;
}
//前一k线的计数器的数值未超限,则当前k线将计数器的值加一;
if(Counter[1] > 0 and Counter[1] < CounterLimit)
{
Counter = Counter + 1;
//计数器范围内,满足con2,将开仓条件赋值为真;
Entry = Counter <= CounterLimit and Con2;
}
//计数器的值达到范围上限的k线未满足条件con2,初始化值Conter为0;
if(Counter == CounterLimit and !Con2)
{
Counter = 0;
}
End
复制代码
作者:
huangshuangyang
时间:
2014-7-14 14:15:01
米小兔 发表于 2014-7-13 11:48
仅看楼主描述写了一点代码, 如果知道策略上下文, 可能还可以简化写法.
感谢帅哥的指点,我整个的策略是这样的,我以下的代码可以帮忙修改吗:1、做多条件:MACD 上穿0轴后完成后正值柱线不超过 5 根且价格在20期指数移动平均线上M个点处做多,分批出场策略:初步止损2手在entrprice-8*MinPoint,当价格上涨至entrprice+13*MinPoin时止盈1手,剩余1手若价格下落则在entryprice保本出场,若价格继续上涨则止盈设置在20期指数移动平均线下M个点;做空条件,MACD 下穿0轴后完成后负值柱线不超过 5 根且价格在20期指数移动平均线下方M个点处做空2手,分批出场策略:初步止损2手在entrprice+8*MinPoint,当价格下跌至entrprice-13*MinPoin时止盈1手,剩余1手若上涨则在entryprice保本出场,若价格继续下跌则止盈设置在20期指数移动平均线上M个点;
作者:
米小兔
时间:
2014-7-14 14:25:27
加我QQ55297268
作者:
huangshuangyang
时间:
2014-7-14 14:42:39
米小兔 发表于 2014-7-13 11:48
仅看楼主描述写了一点代码, 如果知道策略上下文, 可能还可以简化写法.
Params
Numeric FastLength(12);
Numeric SlowLength(26);
Numeric MACDLength(9);
Numeric Length(20);//20日指数移动平均
Numeric M(4);//进场必须距离20日指数移动平均的距离,目的是过滤假突破;剩余一半仓位距离20日指数平均的距离后出场
Vars
NumericSeries MACDValue;
Numeric AvgMACD;
Numeric MACDDiff;
Bool con1;
Bool con2;
Bool con3;
Bool con4;
Numeric MinPoint;
NumericSeries EMA20;
Numeric myEntryprice;//进场价格
Numeric myExitPrice;
NumericSeries a(0);
NumericSeries b(0);
Begin
MinPoint=MinMove*PriceScale;
MinPoint = MinMove*PriceScale;
EMA20=XAverage(Close, Length);
PlotNumeric("EMA20",EMA20);
MACDValue = XAverage( Close, FastLength ) - XAverage( Close, SlowLength ) ;
AvgMACD = XAverage(MACDValue,MACDLength);
MACDDiff = MACDValue - AvgMACD;
Commentary("MACD="+Text(MACDDiff));
con1=(MACDDiff>0);
con2=(high>=(EMA20[1]+M*MinPoint));
con3=(MACDDiff<0);
con4=(low<=(EMA20[1]-M*MinPoint));
if(MarketPosition<>1 and (countif(con1,5))>=1 and con2)
{
myEntryprice=EMA20[1]+M*MinPoint;
If(Open>myEntryprice)myEntryprice=Open;
buy(1,myEntryprice);
a=0;
}
if(MarketPosition==1)
{
if(high>=entryprice+13*MinPoint and a==0)
{ myExitprice=entryprice+13*MinPoint;
if(Open>entryprice+13*MinPoint)myExitprice=Open;
sell(1,myExitPrice);
a=1;
}
if(low<=entryPrice)
{ myExitprice=entryprice;
if(open<entryPrice)myExitPrice=entryPrice;
sell(1,myExitPrice);
}
if(low<=entryPrice-8*MinPoint)
{
myExitprice=entryPrice-8*MinPoint;
if(open<entryPrice-8*MinPoint)myExitprice=open;
sell(0,myExitPrice);
}
}
If(MarketPosition<>-1 and (countif(con3,5))>=1 and con4)
{
myEntryprice=EMA20[1]-M*MinPoint;
If(Open<myEntryprice)myEntryprice=Open;
SellShort(1,myEntryprice);
}
if(MarketPosition==-1)
{
if(low<=entryprice-13*MinPoint and b==0)
{ myExitprice=entryprice-13*MinPoint;
if(Open<entryprice-13*MinPoint)myExitprice=Open;
buyToCover(1,myExitPrice);
b=1;
}
if(high>=entryPrice)
{ myExitprice=entryprice;
if(open>entryPrice)myExitPrice=entryPrice;
buyToCover(1,myExitPrice);
}
if(high>=entryPrice+8*MinPoint)
{
myExitprice=entryPrice+8*MinPoint;
if(open<entryPrice+8*MinPoint)myExitprice=open;
buyToCover(0,myExitPrice) ;
}
}
End
欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/)
Powered by Discuz! X2