|
本帖最后由 20140711 于 2015-9-19 08:47 编辑
以下为均线交易逻辑部分源码
Params
Numeric lots(1);
Numeric TimeFrame(1440); // 目标时间周期参数,参数说明参见MtBar
Numeric BarsBack(1); // 目标时间周期BAR偏移参数,说明见MtBar函数
Numeric Length(60); // 大周期的均线周期 括号里参数可以自己修改
Numeric InitialStop(100); // 止损比例*10000 括号里参数可以自己修改
Vars
Numeric oMA1;
NumericSeries MA60;
Numeric UpLine;
Numeric DwLine;
Numeric MyPrice;
Numeric StopLine(0);
Numeric YesClose;
NumericSeries Deci(0);
Numeric MinPoint;
Begin
MtMa(TimeFrame,BarsBack,Length,oMA1);
MA60 = oMA1;
PlotNumeric("MA60",MA60);
YesClose=CloseD(1);
MinPoint = MinMove*PriceScale;
//PlotNumeric("UpLine",UpLine);
//PlotNumeric("DwLine",DwLine);
If (YesClose>MA60[1]) // 昨日收盘价大于日线60周期均线,多头趋势
{
if (MarketPosition!=1 and High>=UpLine And Deci==0)
{
MyPrice = UpLine+ MinPoint;
MyPrice = IIF(Open > MyPrice, Open,MyPrice);
Buy(Lots,MyPrice);
Return;
}
}
If (YesClose<MA60[1]) // 昨日收盘价小于日线60周期均线,空头趋势
{
if (MarketPosition!=-1 and Low<=DwLine And Deci==0)
{
MyPrice = DwLine- MinPoint;
MyPrice = IIF(Open < MyPrice, Open,MyPrice);
If(Open < MyPrice) MyPrice = Open;
SellShort(Lots,MyPrice );
Return;
}
}
//止损--------------------------------------------------
If(MarketPosition==1) // 持多头
{
StopLine = EntryPrice * (1-InitialStop/10000);
If(Low <= StopLine)
{
MyPrice = StopLine;
MyPrice = IIF(Open < MyPrice , Open,MyPrice);
Sell(Lots,MyPrice);
Deci = 1;
}
}Else If(MarketPosition==-1) // 持空
{
StopLine = EntryPrice * (1+InitialStop/10000);
If(High >= StopLine)
{
MyPrice = StopLine;
MyPrice = IIF(Open > MyPrice, Open,MyPrice);
BuyToCover(Lots,MyPrice);
Deci = 1;
}
}
//平仓----------------------------------------------
If(Low <= ma60)//多头止盈
{
MyPrice = ma60;
If(Open < MyPrice) MyPrice = Open;
Sell(Lots,MyPrice);
Return;
}
If(High >= ma60)//空头止盈
{
MyPrice =ma60;
If(Open > MyPrice) MyPrice = Open;
BuyToCover(Lots,MyPrice);
Return;
}
End
声明:本帖本人发表观点均属于本人所有 如有人转载 源码部分本人享有专利权 以上源码部分只是逻辑部分 无法进行实盘交易或测试 本人只是跟大家提供一种逻辑 敬请注意 |
|