资源加载中... loading...

多级止盈趋势策略

Author: 扫地僧, Date: 2021-11-04 14:55:43
Tags: 商品期货趋势My语言

  • 策略名称: 多级止盈趋势策略

  • 数据周期:多周期

  • 支持:商品期货、数字货币

  • 官方网站:www.quantinfo.com

    img

  • 主图: 上线,公式 :UPPERLINE^^今开+BAND; 下线,公式 :LOWERLINE^^今开-BAND; 均线,公式 :均线^^MA(CLOSE,LENGTH);

  • 副图: 无


(*backtest
start: 2018-01-01 00:00:00
end: 2018-04-09 00:00:00
period: 1d
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}]
args: [["LENGTH",80]]
*)

STARTPER1:=5;  // 1级跟踪止盈,盈利5%启动
               // 1 level tracking take profit, if profit 5% then start

STOPPER1:=100; // 1级跟踪止盈,盈利回撤100%触发    
               // 1 level tracking take profit, if profit retracement is 100% then trigger
               
STARTPER2:=10; // 2级跟踪止盈,盈利10%启动
               // 2 level tracking take profit, if profit 10% then start

STOPPER2:=50;  // 2级跟踪止盈,盈利回撤50%触发   
               // 2 level tracking take profit, if profit retracement is 50% then trigger

STARTPER3:=20; // 3级跟踪止盈,盈利20%启动
               // 3 level tracking take profit, if profit 20% then start

STOPPER3:=20;  // 3级跟踪止盈,盈利回撤20%触发
               // 3 level tracking take profit, if profit retracement is 20% then trigger
    
// 上下区间
// Upper and lower intervals

NN:=BARSLAST(DATE<>REF(DATE,1))+1;  // 今天开盘到目前为止的周期数
                                    // The number of cycles since the opening today

TODAYOPEN:=VALUEWHEN(NN=1,O);       // 当天的开盘价
                                    // Opening price of the day

TODAYHIGH:=HHV(H,NN);                    // 今天全天的最高价,today’s highest price
TODAYLOW:=LLV(L,NN);                     // 今天全天的最低价,today’s lowest price
YESTDAYHIGH:=REF(TODAYHIGH,NN);          // 昨天全天的最高价,yesterday's highest price
YESTDAYLOW:=REF(TODAYLOW,NN);            // 昨天全天的最低价,yesterday's lowest price

BAND:=YESTDAYHIGH-YESTDAYLOW;
UPPERLINE^^TODAYOPEN+BAND;
LOWERLINE^^TODAYOPEN-BAND;
    
//均线
// MA
MALINE^^MA(CLOSE,LENGTH);
            
//开平仓条件
// When to open and close position
SKCOND: = C<LOWERLINE AND LOWERLINE<MALINE;
BKCOND: = C>UPPERLINE AND UPPERLINE>MALINE;
BPSHORT: = C>UPPERLINE OR C>MALINE;
SPLONG: = C<LOWERLINE OR C<MALINE;

//程序主体
//the mainbody of program
//开仓
//open position

SKCOND,SK;
BKCOND,BK;

//平仓
//close position
SPLONG,SP;
BPSHORT,BP;

//止盈        
//take profit     
SKLOW<=SKPRICE*(1-0.01*STARTPER3) AND HIGH>=SKLOW+(SKPRICE-SKLOW)*0.01*STOPPER3,BP;// 最大盈利达到"STARTPER3"%之后盈利回撤"STOPPER3"%,平空
                                                                                   // If profit get “STARTPER3”% and profit retracement get “STOPPER3”%, then close short position
BKHIGH>=BKPRICE*(1+0.01*STARTPER3) AND LOW<=BKHIGH-(BKHIGH-BKPRICE)*0.01*STOPPER3,SP;// 最大盈利达到"STARTPER3"%之后盈利回撤"STOPPER3"%,平多
                                                                                     // If profit get “STARTPER3”% and profit retracement get “STOPPER3”%, then close long position
SKLOW<=SKPRICE*(1-0.01*STARTPER2) AND HIGH>=SKLOW+(SKPRICE-SKLOW)*0.01*STOPPER2,BP;  // 最大盈利达到"STARTPER2"%之后盈利回撤"STOPPER2"%,平空
                                                                                     // If profit get “STARTPER2”% and profit retracement get “STOPPER2”%, then close short position
BKHIGH>=BKPRICE*(1+0.01*STARTPER2) AND LOW<=BKHIGH-(BKHIGH-BKPRICE)*0.01*STOPPER2,SP;// 最大盈利达到"STARTPER2"%之后盈利回撤"STOPPER2"%,平多
                                                                                     // If profit get “STARTPER2”% and profit retracement get “STOPPER2”%, then close long position
SKLOW<=SKPRICE*(1-0.01*STARTPER1) AND HIGH>=SKLOW+(SKPRICE-SKLOW)*0.01*STOPPER1,BP;// 最大盈利达到"STARTPER1"%之后盈利回撤"STOPPER1"%,平空
                                                                                   // If profit get “STARTPER1”% and profit retracement get “STOPPER1”%, then close short position
BKHIGH>=BKPRICE*(1+0.01*STARTPER1) AND LOW<=BKHIGH-(BKHIGH-BKPRICE)*0.01*STOPPER1,SP;// 最大盈利达到"STARTPER1"%之后盈利回撤"STOPPER1"%,平多
                                                                                     // If profit get “STARTPER1”% and profit retracement get “STOPPER1”%, then close long position

//止损
//stop loss
C>=SKPRICE*(1+STOPRANGE*0.01),BP; 
C<=BKPRICE*(1-STOPRANGE*0.01),SP; 
AUTOFILTER;

相关内容

更多内容