全部 智大领峰 TBQuant功能 TBL语言 TB开户 问答专区 高手圈 其他
已解决
用了全局变量Global Integer num(0);没有平仓信号了,看下代码哪里写错了
ghtfff 分享到
2023-07-12 06:56

//------------------------------------------------------------------------

// 简称: rx

// 名称: 荣轩

// 类别: 公式应用

// 类型: 用户应用

// 输出: Void

//------------------------------------------------------------------------

Params

//此处添加参数

   Numeric FastLength(26);// 短期指数平均线参数

Vars

//此处添加变量

Global Integer num(0);

Series<Numeric> firstlow;

   Series<Numeric> AvgValue1;

   Series<Numeric> AvgValue2;

   Numeric         MinPoint; // 一个最小变动单位,也就是一跳

   

   Series<Numeric> D7;

   Series<Numeric> D71;

   Series<Numeric> D11;

   Series<Numeric> D111;

   

   Series<Numeric> baramount;

   Series<Numeric> barvol;

   Series<Numeric> dayavg;

   

   Series<Numeric> MyEntryPrice; // 开仓价格,例中为开仓均价,可设置为某次入场价

   Series<Numeric> MyExitPrice; // 平仓价格

   Series<Numeric> TakeProfitSet(2); // 止赢设置

   Series<Numeric> StopLossSet(6); // 止损设置

   

   

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

   

   OnInit()


  {


   array<Numeric> timepoint;


   timepoint[0] = 0.112450;


   timepoint[1] = 0.145450;

   

   timepoint[2] = 0.225450;


   SetTriggerBarClose(timepoint);


  }

   

   

   OnBarClose(ArrayRef<Integer> indexs)


   {


    if(time == 0.1120 or time == 0.1450 or time == 0.2250)


    {


    sell(0,close);


    BuyToCover(0,close);


    Commentary(\"收盘平仓\");


    }


  }

   


OnBar(ArrayRef<Integer> indexs)

{  

   

       

AvgValue2 = AverageFC(Close,FastLength);

AvgValue1 = AverageFC(Close,5);

   PlotNumeric(\"AvgValue1\",AvgValue1);//布林均线显示

   PlotNumeric(\"AvgValue2\",AvgValue2);//布林均线显示

   

   D7=Lowest(low,5);

       D71=NthCon(CrossUnder(C,D7[1]));


       D11=Highest(High,5);

       D111=NthCon(CrossOver(C,D11[1]));


       PlotNumeric(\"D7\",D7);//最近5日的最低点画线

       PlotNumeric(\"D11\",D11);//最近5日的最高点画线

       

       

       if(truedate(0)!=truedate(1))//分时均线

           {

                   baramount=close*Vol;

                   barvol=vol;

           }else

           {

                   baramount = baramount+close*vol;

                   barvol = barvol+vol;

           }

       dayavg = baramount / barvol;

       Plotnumeric(\"dayavg\",dayavg);

       

       

       

       MinPoint = MinMove*PriceScale;

       //开仓条件

       If(MarketPosition ==0  && D71[1]>D111[1] && H[1]>dayavg[1] && H[1]>AvgValue1[1]  && High>High[1] && (TIME>=0.0900&&TIME<0.1125||TIME>=0.1330&&TIME<0.1455||TIME>=0.2100&&TIME<0.2255) && num<>1 )//开仓情形15分种分型向上,分时均线上方,昨天收盘价大于5日均线,当价格大于昨高

   

{

firstlow=Low;

num=1;

If(High[1]>firstlow)

{

Buy(2,High[1]-1*MinPoint);

}Else

Buy(2,firstlow+1*MinPoint);// 当记录的最低値大于前个k线的高点时,再用High[1]-1*MinPoint肯定买不进,这里需要对盘买。

}

 

         MyEntryPrice = AvgEntryPrice;

         

         If( MarketPosition==1  && L<firstlow) // 止损

         {

         Sell(0,min(open,firstlow-1*MinMove*PriceScale));

         num=3;

         }

 If(MarketPosition == 1 && CurrentContracts ==2) // 止赢条件表达式

         {

         MyExitPrice = MyEntryPrice*1.00191+TakeProfitSet*MinPoint;

       

         Commentary(\"MyExitPrice=\"+text(MyExitPrice));  

         }

       

         If(MarketPosition==1 && CurrentContracts ==2 && H>MyExitPrice)//固定止盈

         {

         Sell(1,MyExitPrice+1*MinPoint);//多头平仓

         num=4;

        }

       

       

       

 //If(BarsSinceLastEntry==0 && Low <= MyEntryPrice - StopLossSet*MinPoint) // 止损条件表达式

         //{

         //MyExitPrice = MyEntryPrice - StopLossSet*MinPoint;

         //如果该 Bar 开盘价即跳空触发,则用开盘价代替

         //If(Open < MyExitPrice) MyExitPrice = Open;

         //Sell(0,MyExitPrice-1*MinPoint);

         //}

       

If( MarketPosition==1 && BarsSinceLastEntry>0 && L<L[1]) // 止赢条件表达式

        {

        Sell(0,min(open,L[1]-1*MinMove*PriceScale));

        num=5;

        }

        If(L<D7[1])//多头平仓加的一个保险

        {

        Sell(0,min(open,D7[1]-1*MinMove*PriceScale));

        num=6;

        }

   

}



//------------------------------------------------------------------------

// 编译版本 2023-06-11 115636

// 版权所有 ghtfff

// 更改声明 TradeBlazer Software保留对TradeBlazer平台

// 每一版本的TradeBlazer公式修改和重写的权利

//------------------------------------------------------------------------






















kyover

从来没有教过用全局变量作为状态变量去控制buysellshort信号命令的写法

你一定要用全局变量去控制,我也不知道怎么处理

2023-07-12 08:41
您未登录,请先 登录注册 后发表评论
顶部