一些文华财经程序化交易模型分享给大家。
交易开拓者代码:
Params
Numeric lenth(2);
Numeric malen(12);
Numeric ratio2(4.25);
Numeric InitialStop(31); //初始止损(千分之N)
Numeric TrailingStop1(47); //追踪止损启动(千分之N)
Numeric TrailingStop2(15); //追踪止损回落(千分之N)
Numeric tradBegin(915); //开仓时间
Numeric tradEnd(1430); //开仓截止时间
Vars
NumericSeries ATRDD; //ATR吊灯止损
Numeric OffSet(0);
Numeric atr;
Numeric UpperBand;
Numeric lowerBand;
Numeric MinPoint;
NumericSeries HighestAfterEntry;
NumericSeries LowestAfterEntry;
Numeric StopLine;
Numeric MyPrice;
bool timeCondition;
Numeric tmp;
Numeric tmp2;
bool volCondition;
bool longCondition;
bool shortCondition;
Begin
timeCondition=Time>0.0001*tradBegin And Time <tradEnd * 0.0001;
//————————————————————–
if (BarsSinceEntry == 1)
{
HighestAfterEntry = AvgEntryPrice;
LowestAfterEntry = AvgEntryPrice;
}
Else If(BarsSinceEntry > 1)
{
HighestAfterEntry = Max(HighestAfterEntry[1],High[1]);
LowestAfterEntry = Min(LowestAfterEntry[1],Low[1]);
}
Else
{
HighestAfterEntry = HighestAfterEntry[1];
LowestAfterEntry = LowestAfterEntry[1];
}
// 通道
MinPoint = MinMove*PriceScale;
atr=Average(high[1]-low[1],lenth);
Upperband=Average(open,malen)+atr*ratio2;
LowerBand=Average(open,malen)-atr*ratio2;
//PlotNumeric(“ub”,upperband);
//PlotNumeric(“lb”,lowerband);
//————————————————————–
shortCondition=timeCondition and MarketPosition<>-1 && Low<=LowerBand ;
longCondition=timeCondition and MarketPosition<>1 && high>=UpperBand ;
//————————————————————–
If(shortCondition)
{
MyPrice = LowerBand-OffSet*MinPoint;
If(Open < LowerBand)
MyPrice = Open-OffSet*MinPoint;
sellshort(0,MyPrice);
Return;
}
//————————————————————–
If(longCondition)
{
MyPrice = UpperBand+OffSet*MinPoint;
If(Open > UpperBand)
MyPrice = Open+OffSet*MinPoint;
Buy(0,MyPrice);
Return;
}
//————————止损模块————————————–
//止损离场处理
If(MarketPosition==1 && BarsSinceEntry >0)
{
StopLine = EntryPrice * (1-InitialStop/1000); //固定止损
If (HighestAfterEntry >= EntryPrice * (1 + TrailingStop1/1000)) //跟踪止损
{
StopLine = HighestAfterEntry*(1-TrailingStop2/1000);
}
}
If(Low <= StopLine)
{
MyPrice = StopLine;
If(Open < MyPrice) MyPrice = Open;
Sell(0,MyPrice);
}
Else If(MarketPosition ==-1 && BarsSinceEntry >0)
{
StopLine = EntryPrice * (1+InitialStop/1000); //固定止损
If(LowestAfterEntry <= EntryPrice*(1-TrailingStop1/1000)) //跟踪止损
{
StopLine = LowestAfterEntry * (1+TrailingStop2/1000);
}
}
If(High >= StopLine)
{
MyPrice = StopLine;
If(Open > MyPrice) MyPrice =Open;
BuyToCover(0,MyPrice);
}
End
Params
Numeric K1(0.6);
Numeric K2(0.4);
Numeric Mday(5);
Numeric TrailingStart(39);
Numeric TrailingStop(6);
Vars
Numeric v_li1(1);
Bool v_zo1;
Bool v_zo2;
Numeric v_li2;
Numeric v_li4;
Numeric v_li5;
Numeric v_li6;
Numeric v_li7;
Numeric v_li8;
Numeric v_li9;
Numeric v_li10;
Numeric stop;
Numeric MyPrice;
NumericSeries HighestAfterEntry;
NumericSeries LowestAfterEntry;
Numeric Stopline;
BoolSeries bOut;
Begin
if(date>20180501)return;
If(!CallAuctionFilter()) Return;
v_li1=BarsSinceToday() ;
v_li5=Highest(HighD(1),(270/BarInterval * Mday) + v_li1) ;
v_li6=Highest(CloseD(1),(270/BarInterval * Mday) + v_li1) ;
v_li7=Lowest (LowD(1),(270/BarInterval * Mday) + v_li1) ;
v_li1=Lowest (CloseD(1),(270/BarInterval * Mday) + v_li1) ;
v_li7=(v_li6 – v_li7) ;
v_li5=(v_li5 – v_li1) ;
if (v_li5 >= v_li7)
{
v_li10=v_li5;
}
else
{
v_li10=v_li7;
}
If(BarType == 1 And Time == 0.1445)bOut=False;
If(BarType == 1 And Time == 0.1452)bOut=False;
if(Date != Date[1])bOut=False;
v_li5= v_li10 * K1 ;
v_li7= v_li10 * K2 ;
v_li1=OpenD(0) + v_li5 ;
v_li8=OpenD(0) – v_li7 ;
if ((CurrentBar > (270 / BarInterval * Mday)) and (Time > 0.0915))
{
if ((MarketPosition == 0) And !bOut)
{
if ((Close[1] >= v_li1))
{
Buy(0,Max(Open,v_li1) );
Return;
}
if ((Close[1] <= v_li8))
{
SellShort(0,Min(Open,v_li8));
Return;
}
}
}
if ((MarketPosition == -1) and (Close[1] >= v_li1))
{
Buy(0,Max(Open,v_li1));
Return;
}
if ((MarketPosition == 1) and (Close[1] <= v_li8))
{
SellShort(0,Min(Open,v_li8));
Return;
}
if (BarsSinceEntry == 1)
{
HighestAfterEntry = AvgEntryPrice;
LowestAfterEntry = AvgEntryPrice;
}
Else If(BarsSinceEntry > 1)
{
HighestAfterEntry = Max(HighestAfterEntry[1],High[1]);
LowestAfterEntry = Min(LowestAfterEntry[1],Low[1]);
}
Else
{
HighestAfterEntry = HighestAfterEntry[1];
LowestAfterEntry = LowestAfterEntry[1];
}
If( Marketposition == 1 And BarsSinceEntry>0)
{
if(Close[1] <= Entryprice – EntryPrice*TrailingStop/1000)
{
Sell(0, Open);
PlotString(“Mark”,“止损”,Low,White);
}
}
If(Marketposition ==-1 And BarsSinceEntry>0 )
{
if( Close[1] >= Entryprice + EntryPrice*TrailingStop/1000)
{
BuyToCover(0,Open);
PlotString(“Mark”,“止损”,Low,White);
}
}
If(MarketPosition==1 And BarsSinceEntry>0 And HighestAfterEntry>=EntryPrice*(1+TrailingStart/1000))
{
If(Low <= HighestAfterEntry[1]-EntryPrice*TrailingStop/1000)
{
MyPrice = HighestAfterEntry[1]-EntryPrice*TrailingStop/1000;
If(Open < MyPrice) MyPrice = Open;
Sell(0,myprice);
bOut = True;
}
}
If(MarketPosition==-1 And BarsSinceEntry>0 And LowestAfterEntry<=EntryPrice*(1-TrailingStart/1000))
{
If(High >= LowestAfterEntry[1] + EntryPrice*TrailingStop/1000)
{
MyPrice = LowestAfterEntry[1] + EntryPrice*TrailingStop/1000;
If(Open > MyPrice) MyPrice = Open;
BuyToCover(0,MyPrice);
bOut = True;
}
}
End
下载地址:https://www.vifaka.com/item/72c7a13a8eb480ef