luohuo1 发表于 2020-7-2 11:56:53

Aberration交易系统源码整理:

Aberration交易系统源码整理:青蜂侠 微信adu3341 ;QQ 994206922 ;
交易开拓者 代码
Params
        Numeric Length(90);
        Numeric StdDevUp(2.0);  //标准差参数
        Numeric StdDevDn(-2.0); //标准差参数
        Numeric Lots(1);
Vars
        Series<Numeric> UpperBand;
        Series<Numeric> LowerBand;
        Series<Numeric> AveMa;
        Numeric StdValue;
Events
    onBar(ArrayRef<Integer> indexs)
    {   
        //布林指标计算
            AveMa=Average(Close,Length);
            StdValue = StandardDev(Close,Length);
           
            UpperBand=Avema+StdDevUp*StdValue;   //标准差参数
            LowerBand=Avema-StdDevUp*StdValue;   //标准差参数
           
            PlotNumeric("UpperBand",UpperBand);
            PlotNumeric("LowerBand",LowerBand);
            PlotNumeric("AveMa",AveMa);
            //
            If(MarketPosition!=1 &&CrossOver(Close,UpperBand))
            {
             Buy(Lots,Open);
            }
     
            If(MarketPosition!=-1 &&CrossUnder(Close,LowerBand))
            {
             SellShort(Lots,Open);
            }
     
            If(MarketPosition==1 && Close<AveMa)
            {
             Sell(Lots,Open);
            }
     
            If(MarketPosition==-1 && Close>AveMa)
            {
     
            BuyToCover(Lots,Open);
            }
     
}

===========================================================

TBQuant
Params
        //此处添加参数
        Numeric lots(0);
        Numeric Length(80);
Vars
        //此处添加变量
        Series<Numeric> UpperBand;
        Series<Numeric> LowerBand;
        Series<Numeric> AveMa;
        Numeric StdValue;
        bool buycon;
        bool sellcon;
Defs
        //此处添加公式函数
Events
        //此处实现事件函数
        //初始化事件函数,策略运行期间,首先运行且只有一次
        OnInit()
        {       
        }
        //Bar更新事件函数,参数indexs表示变化的数据源图层ID数组
        OnBar(ArrayRef<Integer> indexs)
        {
        //布林指标计算
                AveMa=Average(close,Length);
                StdValue=StandardDev(close,Length);
                UpperBand=AveMa+2*StdValue;
                LowerBand=AveMa-2*StdValue;
                PlotNumeric("UpperBand",UpperBand);
                PlotNumeric("LowerBand",LowerBand);
                PlotNumeric("AveMa",AveMa);
        //开仓条件计算
                buycon=CrossOver(close,UpperBand);
                sellcon=CrossUnder(close,LowerBand);
        //突破中轨平仓
                If(MarketPosition==1 && close<AveMa)sell(0,Open);
                If(MarketPosition==-1 && close>AveMa)BuyToCover(0,Open);
        //突破上下轨道开仓
                If(MarketPosition!=1 && buycon)buy(lots,Open);
                If(MarketPosition!=-1 && sellcon)SellShort(lots,Open);               
        }
===========================================================
在Tradestation下
Input: Length(35), StdDevUp(2.0), StdDevDn(-2.0);
Vars: UpBand(0), DnBand(0), Ave(0);
UpBand=BollingerBand(Close, Length, StdDevUp);
DnBand=BollingerBand(Close, Length, StdDevDn);
Ave=Average(Close, Length);
{--------Enter Long--------}
if (MarketPosition=0) and (Close > UpBand) then
Buy("BE") tomorrow at market;
{--------Enter Short--------}
if (MarketPosition=0) and (Close < DnBand) then
Sell("SE") tomorrow at market;
{--------Exit Long--------}
if (MarketPosition=1) and (Close < Ave) then
ExitLong("LX") today at Close;
{--------Exit Short--------}
if (MarketPosition=-1) and (Close > Ave) then
ExitShort("SX") today at Close;
==========================================================
MC(MultiCharts)平台上的源码:
inputs: Len(35),Dev(2),type(0);
variables: ma(0),std(0),up(0),down(0);
ma = AverageFC(Close,Len);
std = StandardDev(Close, Len,1); //StandardDev( Close, Period, 1 ) ;
up = ma + Dev * std;
down = ma - Dev * std;
if(type=0) then
begin
    if(marketposition=0 and close>up) then
    begin
        buy("b") next bar at market;
    end;
    if(marketposition=0 and close<down) then
    begin
        sellshort("s") next bar at market;
    end;
    if(marketposition>0 and close<ma) then sell("sp") next bar at market;
    if(marketposition<0 and close>ma) then buytocover("bp") next bar at market;
end
else
begin
    if(marketposition=0) then
    begin
        buy("b2") next bar at up stop;
        sellshort("s2") next bar at down stop;
    end;   
    if(marketposition>0) then sell("sp2") next bar at ma stop;
    if(marketposition<0) then buytocover("bp2") next bar at ma stop;
end;
=========================================================
页: [1]
查看完整版本: Aberration交易系统源码整理: