Hãy thử một chút.
Sự tăng cường ngôn ngữ
Các nhà phát minh đã định lượng không chỉ thực hiện trình giải thích của ngôn ngữ Mac mà còn tăng cường để nó có thể lập trình hỗn hợp với ngôn ngữ cao cấp JavaScript, ví dụ:
%%
// 这里面可以调用发明者量化的任何API
scope.TEST = function(obj) {
return obj.val * 100;
}
%%
收盘价:C;
收盘价放大100倍:TEST(C);
上一个收盘价放大100倍:TEST(REF(C, 1)); // 鼠标移动到回测的K线上就会提示变量值
(*backtest start: 2018-11-01 00:00:00 end: 2018-12-19 00:00:00 period: 1d exchanges: [{"eid":"Futures_BitMEX","currency":"XBT_USD"}] args: [["ContractType","XBTUSD",126961]] *) // this demonstration mainly uses the Turtle Trading Rules to demonstrate the method of writing "position management, maximum position control and other fund management". // only the demonstration key content statement is annotated, other statements please consult customer service //This model is only used to demonstrate the use of this strategy, and enters the market accordingly, at your own risk. TR:=MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));// True volatility ATR:MA(TR,26); // Find a simple moving average of the true amplitude in 26 cycles, shown in the figure ZOOM:=IFELSE(ISCONTRACT('@Futures_(?!CTP).*'), CLOSE, 1); // Compatible with cryptocurrency futures as margin LOT:=((MONEYTOT*0.01*ZOOM)/(UNIT*ATR))*ZOOM;// Calculate the number of one hand based on 1% of equity TC..IFELSE(ISCONTRACT('@Futures.*'), INTPART(LOT), LOT); // Compatible futures and spot ISCONTRACT starts with @ to indicate matching exchange name, support MTC..4*TC; // Total position HH^^HV(H,20); // Attached to the main image display LL^^LV(L,20); // Attached to the main image display CROSSUP(C,HH)&&ISLASTBK=0&&ISLASTSK=0&&BARPOS>=26,BK(TC);// The latest price exceeds the highest value of 20 cycles, the first time to buy long, the quality is TC hands CROSSDOWN(C,LL)&&ISLASTBK=0&&ISLASTSK=0,SK(TC); // The latest price fell below the lowest value of 20 cycles, the first time to sell short, the quality is TC hands C>=BKPRICE+0.5*ATR&&BKVOL<MTC&&ISLASTBK,BK(TC);// The price has increased by 0.5 times ATR on the basis of the last holding position, and when the number of hands does not exceed 4 times of TC, buy long the adding position of TC hands C<=SKPRICE-0.5*ATR&&SKVOL<MTC&&ISLASTSK,SK(TC);// The price fell 0.5 times ATR on the basis of the last holding position, and when the number of hands does not exceed 4 times of TC, sell short the adding position of TC hand. C<=(BKPRICE-2*ATR)&&BKVOL>0,SP(BKVOL);// The latest price is less than the opening price minus 2 times of ATR, stop loss and close position C>=(SKPRICE+2*ATR)&&SKVOL>0,BP(SKVOL); // The latest price is greater than the opening price plus 2 times of ATR, stop loss and close position CROSSUP(H,HV(H,10))&&SKVOL>0,BP(SKVOL);// The highest price up-cross the highest price of 10 cycles, closing the position CROSSDOWN(L,LV(L,10))&&BKVOL>0,SP(BKVOL); // The lowest price down-cross the lowest price of 10 cycles, closing position TRADE_AGAIN(10);