全部 智大领峰 TBQuant功能 TBL语言 TB开户 问答专区 高手圈 其他
那位老师帮忙写个公式策略谢谢
2024-03-31 14:01


N:=F;


HH:=HHV(HIGH,N);


LL:=LLV(LOW,N);


HH1:=BARSLAST((HH>REF(HH,D)));


LL1:=BARSLAST((LL<REF(LL,D)));


A:=IF((HH1 < LL1),1,IF((HH1 > LL1),-1,0));


IF(A>=0,LL,HH),COLORYELLOW;


STICKLINE((HH1 < LL1),CLOSE,OPEN,2,0),COLORRED;


STICKLINE((HH1 < LL1),HIGH,LOW,0,0),COLORRED;


STICKLINE((HH1 > LL1),CLOSE,OPEN,2,0),COLORGREEN;


STICKLINE((HH1 > LL1),HIGH,LOW,0,0),COLORGREEN;

kyover

直接用简语言版 ,和这个风格是一致的。

2024-04-01 09:20
yang081112
@kyover

老师  给个编辑 好的策略  谢谢

2024-04-15 02:39
yang081112

Params

  Numeric length(20);          //周期

  Numeric  lots(1);        

Vars

  Series<numeric>  avgout(0);   //均线1

  Series<numeric>  avgout2(0);   //均线2

  Series<numeric>  avgout3(0);  //均线3

  Series<numeric>  avgout4(0);  //均线4

  Series<numeric>  avgout5(0);  //均线5


 

  Series<numeric>  myvolav(0);

  Series<numeric>  lps(0);

  Series<numeric>   sps(0);

  Series<numeric>    ps(0);

  Series<numeric>    crit(0);

 

  Series<numeric>    leprice(0);

  Series<numeric>    seprice(0);

  Series<numeric>    sigma(0);

 

  Events

    OnBar(ArrayRef<Integer> indexs)

    { //+过滤开盘集合竞价函数

       

        //均线指标计算   +

        Avgout = Average(close,length);                         //均线1  80

        Avgout2 = Average(close,length-intpart( length/8));  //均线2     70

        Avgout3 = Average(close,length-intpart( length/8)*2);  //均线3   60

        Avgout4 = Average(close,length-intpart( length/8)*3); //均线4    50

        Avgout5 = Average(close,length-intpart( length/8)*4); //均线5    40

        PlotNumeric( \"Avgout\",Avgout);PlotNumeric( \"Avgout2\",Avgout2);PlotNumeric( \"Avgout3\",Avgout3);PlotNumeric( \"Avgout4\",Avgout4);PlotNumeric( \"Avgout5\",Avgout5);

       

      sigma = (StandardDev( close,length)*2);  //标准差

      myvolav=( sigma+sigma[1]+sigma[2])/3;    //最近三天标准差的平均值

      leprice=avgout+sigma;                    //上轨道  均线+标准差

      seprice= avgout-sigma;                   //下轨道  均线-标准差

       PlotNumeric( \"leprice\",leprice);   PlotNumeric( \"seprice\",seprice);    

       

//突破一倍标准差,进行建仓。限制条件中,有一条是必须跌回了最长期的均线后才能开仓,即lps=0.      

if( MarketPosition< 1 And Close[1] > leprice[1] and sigma[1] > myvolav[1] And lps==0 )   //非多仓,收盘价大于上轨 and 标准差>近3个标准差平均值,    

{

   ps=Close[1]+sigma[1];

   crit=1;

   Buy(lots,Open) ;    //开多仓

   

   }

   

if( MarketPosition > -1 And Close[1] < seprice[1] And sigma[1] > myvolav[1] And sps==0 ) //非空仓,收盘价小于上轨 and 标准差>近3个标准差平均值,

{

   SellShort( lots ,Open) ;  //开空仓

   ps=Close[1]-sigma[1];

   crit=1;

   

}    


// 更新盈利级别,按照sigma递增

 If(MarketPosition ==1 And Close[1] > ps )    

 {

     crit=crit+1;                     //盈利一次,crit就加1

     ps=Close[1]+sigma[1];            //同时ps也加标准差

     

     }

     

     If( MarketPosition==-1 And Close[1] < ps)

     {

         crit=crit+1;

         ps=Close[1]-sigma[1];

     

     }

               

//跌破均线,进行平仓。盈利越多,跌破的均线周期越短        

if(MarketPosition==1 And close[1] < avgout[1] And crit==1 )   //盈利1个标准差,跌破均线就平仓

 {

     Sell(0,Open) ;

     lps=0;                    //跌破均线,lps=0,开关

         

   }

   

 If( MarketPosition ==1 And Close[1] < avgout2[1] And crit ==2 )   //盈利2个标准差,跌破均线就平仓

 {

     Sell(0,Open) ;

     lps=1;

     

 }

   

 If( MarketPosition ==1 And Close[1] < avgout3[1] And crit ==3  )  // //盈利3个标准差,跌破均线就平仓

 {

     Sell(0,Open) ;

     lps=1;

     

     }

         

 If( MarketPosition ==1 And Close[1] < avgout4[1] And crit ==4  )  // //盈利4个标准差,跌破均线就平仓

 {

     Sell(0,Open) ;

     lps=1;

     

     }            

                 

If( MarketPosition ==1 And Close[1] < avgout5[1] And crit ==5  )   // //盈利5个标准差,跌破均线就平仓

 {

     Sell(0,Open) ;

     lps=1;

     

     }                    

                         

 If( MarketPosition ==1 And crit ==6  )   //盈利6个标准差,跌破均线就平仓

 {

     Sell(0,Open) ;

     lps=1;

     

     }                            

                                 

     //空仓时,                                

 If( MarketPosition ==-1 And Close[1] > Avgout[1] And crit ==1  )

 {

     BuyToCover(0,Open) ;

     sps=1;

     

     }

                                         

If( MarketPosition ==-1 And Close[1] > Avgout2[1] And crit ==2  )

 {

     BuyToCover(0,Open) ;

     sps=1;

     

     }                                                                                  

                                                                                                                           

If( MarketPosition ==-1 And Close[1] > Avgout3[1] And crit ==3  )

 {

     BuyToCover(0,Open) ;

     sps=1;

     

     }                                                                                                                                                                    

                                                                                                                                                                                                             

If( MarketPosition ==-1 And Close[1] > Avgout4[1] And crit ==4  )

 {

     BuyToCover(0,Open) ;

     sps=1;

     

     }                                                                                                                                                                                                                                                      

                                                                                                                                                                                                                                                                                               

If( MarketPosition ==-1 And Close[1] > Avgout5[1] And crit ==5  )

 {

     BuyToCover(0,Open) ;

     sps=1;

     

     }                                                                                                                                                                                                                                                                                                                                                                                  

                                                       

 if(MarketPosition ==-1 And crit ==6 )        //盈利6个标准差就直接平仓

 {

     BuyToCover(0,Open) ;

     sps=1;

     

     }

     

     

 //只有当跌破最长期的均线后,才能准备下一次的开仓

 If( sps ==1 And close[1] > Avgout[1])  sps=0;    //收盘价大于80均线,sps=0,开空仓库条件

 

  If( lps ==1 And close[1] < Avgout[1])  lps=0;   //收盘价小于80均线,lps=0,开多仓库条件

     

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

                     

        }

 

 

 

 

 

 

2024-06-08 00:29
yang081112

Params

Numeric Num(1.5);

Numeric Lots(1);

Vars

Numeric Scal;

Numeric UpBand;

Numeric LoBand;

Numeric MyEntryPrice;

Events

   onBar(ArrayRef<Integer> indexs)

   {    

   Scal = Max((HighD(1)-CloseD(1)),(CloseD(1)-LowD(1)));

   UpBand = OpenD(0) + Num * Scal;

   LoBand = OpenD(0) - Num * Scal;

   

   PlotNumeric(\"UpBand\",UpBand);

   PlotNumeric(\"LoBand\",LoBand);

   if( MarketPosition<>1 And Close[1] > UpBand )

   {

     MyEntryPrice = Max(Close,UpBand);

     Buy(Lots,Close);

   }

   If(MarketPosition <>-1 And Close[1] <LoBand)

   {

     MyEntryPrice = Min(Close,LoBand);

     SellShort(Lots,Close);

   }

   

   

   

   }


2024-06-11 03:44
yang081112

Params

 Numeric length(20);          //周期

 Numeric  lots(1);        

Numeric  fr(3);//盈利倍数

Numeric  frs(3);//2仓盈利倍数


Numeric  er(2);//轨高倍数

Vars


 Series<numeric>  avgout(0);   //均线1


 Series<numeric>  avgout2(0);   //均线2


 Series<numeric>  avgout3(0);  //均线3


 Series<numeric>  avgout4(0);  //均线4


 Series<numeric>  avgout5(0);  //均线5





 Series<numeric>  myvolav(0);


 Series<numeric>  lps(0);


 Series<numeric>   sps(0);


 Series<numeric>    ps(0);


 Series<numeric>    crit(0);



 Series<numeric>    leprice(0);


 Series<numeric>    seprice(0);


 Series<numeric>    sigma(0);



 Events


   OnBar(ArrayRef<Integer> indexs)


   { //+过滤开盘集合竞价函数


     


       //均线指标计算   +


       Avgout = Average(close,length);                         //均线1  80


       Avgout2 = Average(close,length-intpart( length/8));  //均线2     70


       Avgout3 = Average(close,length-intpart( length/8)*2);  //均线3   60


       Avgout4 = Average(close,length-intpart( length/8)*3); //均线4    50


       Avgout5 = Average(close,length-intpart( length/8)*4); //均线5    40


     


     sigma = (StandardDev( close,length)*er);  //标准差


     myvolav=( sigma+sigma[1]+sigma[2])/3;    //最近三天标准差的平均值


     leprice=avgout+sigma;                    //上轨道  均线+标准差


     seprice= avgout-sigma;                   //下轨道  均线-标准差


      PlotNumeric( \"leprice\",leprice);   PlotNumeric( \"seprice\",seprice);    


     


//突破一倍标准差,进行建仓。限制条件中,有一条是必须跌回了最长期的均线后才能开仓,即lps=0.      


if( MarketPosition< 1 And Close[1] > leprice[1] and  lps==0 )   //非多仓,收盘价大于上轨 and 标准差>近3个标准差平均值,    


{


  ps=Close[1]+sigma[1];


  crit=1;


  Buy(lots,Open) ;    //开多仓


 


  }


 


if( MarketPosition > -1 And Close[1] < seprice[1] And sps==0 ) //非空仓,收盘价小于上轨 and 标准差>近3个标准差平均值,


{


  SellShort( lots ,Open) ;  //开空仓


  ps=Close[1]-sigma[1];


  crit=1;


 


}    




// 更新盈利级别,按照sigma递增


If(MarketPosition ==1 And Close[1] > ps )    


{


    crit=crit+1;                     //盈利一次,crit就加1


    ps=Close[1]+sigma[1];            //同时ps也加标准差


   


    }


   


    If( MarketPosition==-1 And Close[1] < ps)


    {


        crit=crit+1;


        ps=Close[1]-sigma[1];


   


    }


             


//跌破均线,进行平仓。盈利越多,跌破的均线周期越短        




If( MarketPosition ==1 And crit ==fr  )   //盈利6个标准差,跌破均线就平仓


{


    Sell(0,Open) ;


    lps=1;


   


    }                            

If( MarketPosition ==1 And crit ==frs  )   //盈利6个标准差,跌破均线就平仓


{


    Sell(0,Open) ;


    lps=1;


   


    }                            


                               


    //空仓时,                                



if(MarketPosition ==-1 And crit ==fr )        //盈利6个标准差就直接平仓


{


    BuyToCover(0,Open) ;


    sps=1;


   


    }


 if(MarketPosition ==-1 And crit ==frs )        //盈利6个标准差就直接平仓


{


    BuyToCover(0,Open) ;


    sps=1;


   


    }    


   




   


                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         


                   


       }

2024-06-14 02:12
yang081112

那位老师给加个亏损加仓谢谢老师

Params

 Numeric length(20);          //周期

 Numeric  lots(1);        

Numeric zhiying(200); //止盈


Numeric  er(3);//轨高倍数




Vars


 Series<numeric>  avgout(0);   //均线1

Series<Numeric> Avgout2;


 Series<numeric>  avgout3(0);  //均线3


 Series<numeric>  avgout4(0);  //均线4


 Series<numeric>  avgout5(0);  //均线5



                 Series<Numeric> MidLine; //中间线


 Series<numeric>  myvolav(0);


 Series<numeric>  lps(0);


 Series<numeric>   sps(0);


 Series<numeric>    ps(0);


 Series<numeric>    crit(0);



 Series<numeric>    leprice(0);


 Series<numeric>    seprice(0);


 Series<numeric>    sigma(0);



 Events


   OnBar(ArrayRef<Integer> indexs)


   { //+过滤开盘集合竞价函数


     


       //均线指标计算   +

MidLine = AverageFC(Close,Length);

       Avgout = Average(close,length);                         //均线1  80


   

       //Avgout2 = AverageFC(Close,SlowLength);

       Avgout3 = Average(close,length-intpart( length/8)*12);  //均线3   60


       Avgout4 = Average(close,length-intpart( length/8)*13); //均线4    50


       Avgout5 = Average(close,length-intpart( length/8)*14); //均线5    40

//PlotNumeric( \"Avgout2\",Avgout2);

     

     


     sigma = (StandardDev( close,length)*er);  //标准差


     myvolav=( sigma+sigma[1]+sigma[2])/3;    //最近三天标准差的平均值


     leprice=avgout+sigma;                    //上轨道  均线+标准差

     seprice= avgout-sigma;                   //下轨道  均线-标准差


      PlotNumeric( \"leprice\",leprice);   PlotNumeric( \"seprice\",seprice);     PlotNumeric(\"MidLine\",MidLine);


     


//突破一倍标准差,进行建仓。限制条件中,有一条是必须跌回了最长期的均线后才能开仓,即lps=0.      


if( MarketPosition< 1 And Close[1] > leprice[1] )   //非多仓,收盘价大于上轨 and 标准差>近3个标准差平均值,    


{


  ps=Close[1]+sigma[1];


  crit=1;


  Buy(lots,Open) ;    //开多仓


 


  }


 


if( MarketPosition > -1 And Close[1] < seprice[1]) //非空仓,收盘价小于上轨 and 标准差>近3个标准差平均值,


{


  SellShort( lots ,Open) ;  //开空仓


  ps=Close[1]-sigma[1];


  crit=1;


 


}    




// 更新盈利级别,按照sigma递增


If(MarketPosition ==1 And Close[1] > ps )    


{


    crit=crit+1;                     //盈利一次,crit就加1


    ps=Close[1]+sigma[1];            //同时ps也加标准差


   


    }


   


    If( MarketPosition==-1 And Close[1] < ps)


    {


        crit=crit+1;


        ps=Close[1]-sigma[1];


   


    }


             


//跌破均线,进行平仓。盈利越多,跌破的均线周期越短        




 


If( MarketPosition ==1 And Close[1] < MidLine[1]  )   //盈利2个标准差,跌破均线就平仓


{


    Sell(0,Open) ;


    lps=1;


   


}


                               


    //空仓时,                                


                                       


If( MarketPosition ==-1 And Close[1] > MidLine[1]  )


{


    BuyToCover(0,Open) ;


    sps=1;


   


    }                                                                                  

  If(h-AvgEntryPrice>=zhiying and MarketPosition==1 and abs(CurrentContracts)==2)

{

sell(1,max(o,AvgEntryPrice+zhiying));

Commentary(\"止盈\");

PlotString(\"多止赢\",\"多止赢\"+Text(ExitPrice),Low);

}

If(l<=AvgEntryPrice-zhiying and MarketPosition==-1 and abs(CurrentContracts)==2)

{

BuyToCover(1,Min(o,AvgEntryPrice-zhiying));

Commentary(\"止盈\");

PlotString(\"空止赢\",\"空止赢\"+Text(ExitPrice),High);

}

   



   


   


//只有当跌破最长期的均线后,才能准备下一次的开仓


If( sps ==1 And close[1] > MidLine[1])  sps=0;    //收盘价大于80均线,sps=0,开空仓库条件



 If( lps ==1 And close[1] < MidLine[1])  lps=0;   //收盘价小于80均线,lps=0,开多仓库条件


   


                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         


                   


       }

2024-06-22 03:01
yang081112

Params

 //此处添加参数

 Numeric length(979);    // 参数周期

 Integer S_lineType(9);  // 上下轨计算切换

Vars

 //此处添加变量

 Series<Numeric> upl;

 Series<Numeric> dnl;

 Series<Numeric> midl;


Defs

 //此处添加公式函数

 

Events

 //此处实现事件函数

 

 //初始化事件函数,策略运行期间,首先运行且只有一次

 OnInit()

   {

       // 针对数据源888的初始化,获得接近实盘得效果回测数据(固定形式)

       Range[0:DataCount - 1]

       {

           //=========数据源相关设置==============

           AddDataFlag(Enum_Data_RolloverBackWard());        //设置后复权    

           AddDataFlag(Enum_Data_RolloverRealPrice());        //设置映射真实价格    

           AddDataFlag(Enum_Data_AutoSwapPosition());        //设置自动换仓    

           AddDataFlag(Enum_Data_IgnoreSwapSignalCalc());      //设置忽略换仓信号计算

           

           SetSwapPosVolType(2);

       }

       Print(\"OnInit\");

   }



 //Bar更新事件函数,参数indexs表示变化的数据源图层ID数组

 OnBar(ArrayRef<Integer> indexs)

 {

   upl = HighestFC(H, length);    

   dnl = LowestFC(L, length);    

   If(S_lineType == 1)

   {

     upl = IIF(L<L[1], upl, upl[1]) ;

     dnl = IIF(H>H[1], dnl, dnl[1]) ;

   }

   Else

   {

     

   }

   midl = (upl + dnl) / 2 ;

   

   

   // 开平条件

   Bool l4e = CrossOver(H, upl[1]) ;  

   Bool l4x = CrossUnder(C[1], midl[1]) ;

   Bool s4e = CrossUnder(L, dnl[1]) ;

   Bool s4x = CrossOver(C[1], midl[1]) ;  


   // 进出场价格

   Numeric l4e_price = upl[1] ;

   Numeric l4x_price = Open ;

   Numeric s4e_price = dnl[1] ;

   Numeric s4x_price = Open ;  

   Numeric lots = 1;

   

   // 开平处理

   If(MarketPosition != 1 && l4e)

   {

     Buy(lots, l4e_price);

   }

   

   If(MarketPosition != -1 && s4e)

   {

     SellShort(lots, s4e_price);

   }

   

   If(MarketPosition == 1 && BarsSinceEntry > 0 && l4x)

   {

     Sell(0, l4x_price);

   }

   

   If(MarketPosition == -1 && BarsSinceEntry > 0 && s4x)

   {

     BuyToCover(0, s4x_price);

   }

   

   

   PlotNumeric(\"upl\", upl);

   PlotNumeric(\"dnl\", dnl);

   PlotNumeric(\"midl\", midl);

   

   

 }

2024-09-05 09:33
您未登录,请先 登录注册 后发表评论
顶部