全部 智大领峰 TBQuant功能 TBL语言 TB开户 问答专区 高手圈 其他
我想写一个跟踪止损,奈何怎么就是不成功,是哪里的问题?
2021-01-29 15:36

Params
    Numeric zs(30); //跟踪止损点数
Vars
    Numeric rand; //随机数
    Numeric zg(0); //最高价
    Numeric zd(9999999); //最低价
Defs
    
Events
    OnInit(){
        
    }

    OnBar(ArrayRef<Integer> indexs){
        If(O>zg){   //在控制台每次都输出两个一样的价格,好像这个判断总是成立的
            zg = O;
            Print(Text(zg)); 
        }
        If(O<zd){
            zd = O;
            Print(Text(zd));
        }
        
        If(MarketPosition == 0){
            Print("持仓=0");
            rand = IntPart(Rand(1,3));//随机数1或2
            If(rand == 1){
                Buy(1,0);
                Print("多开");
            }
            If(rand == 2){
                SellShort(1,0);
                Print("空开");
            }
        }Else{
            Print("持仓不为0");
            
            If(MarketPosition == 1 And zg - O > zs){
                Sell(1,0);
                SellShort(1,0);
                Print("多反");
            }
            If(MarketPosition == -1 And O - zd > zs){
                BuyToCover(1,0);
                Buy(1,0);
                Print("空反");
            }
            
        }
        
    }

    

kyover

zg zd定义成序列变量

 

2021-01-29 15:57
kyover

跟踪止损在开发手册里是有专门案例的 仔细学习一下

 

2021-01-29 15:57
您未登录,请先 登录注册 后发表评论
顶部