With the continuous improvement of quantitative trading strategies, users have increasingly higher requirements for real-time push of position changes. For example: Web online logs, mobile apps and WeChat, etc. all need the changes in account positions in real time, which requires automatic push of the changes sent to browsers and mobile phones, etc. For the reason, this article aims at FMZ Quant (FMZ.COM) Mylanguage strategy to achieve real-time push of positions to mobile App and WeChat.
To see the complete source code in the article, please click the link: https://www.fmz.com/strategy/305785 , and I suggest you write the code to practice, for only learning from reading the code is not enough.
To conveniently demonstrate, this article will refer to the previous Williams %R trading strategy. The link address of the strategy is: https://www.fmz.com/strategy/283024. The strategy logic is composed of the Williams value and the moving average. For the complete strategy and the backtest configuration, you can click this link to get it. The code of this strategy is shown as follows:
HC := HHV(HIGH, 14) - CLOSE;
HL := HHV(HIGH, 14) - LLV(LOW, 14);
WR := -100 * HC / HL;
MA20 : EMA2(C, 14);
C1 := WR < -60 && C > MA20;
C2 := WR > -15 && C < MA20;
C1, BPK;
C2, SPK;
The Mylanguage on FMZ Quant (FMZ.COM) is a further encapsulation of the JavaScript language, which aims to help the beginners of quantification get started better. Mylanguage has a simple syntax, which can deal with the logic of some simple strategies; when dealing with some complicated strategies, the language will show some problems. Therefore, FMZ Quant has promoted the language enhancement function based on Mylanguage. Such as the following code example:
%%
// here we can call any API of FMZ Quant
scope.TEST = function(obj) {
return obj.val * 100;
}
%%
close price:C;
Zoom 100 times of close price:TEST(C);
Zoom 100 times of last close price:TEST(REF(C, 1)); // move the mouse to the backtested K-line, and the variable value will prompt
As shown in the above code, the language enhancement function allows the programming of Mylanguage and JavaScript to be mixed. For specific explanations, please refer to the documentation: https://www.fmz.com/doc/2569#语� %A8%80%E5%A2%9E%E5%BC%BA
Including:
1.scope object scope object; can add properties in it, and assign anonymous functions to properties. The anonymous function referenced by this property can be called in the code part of Mylanguage.
2.scope.get_locals(‘name’) The function can obtain the variables of Mylanguage, so as to realize the interaction between Mylanguage and JavaScript.
In a Mylanguage strategy, the BKVOL function can obtain the buy signal Lot, that is, the current long position. The SKVOL function can obtain the sell signal Lot, that is, the current short position. Then, we can calculate the current position change status by subtracting SKVOL from BKVOL. As shown in the code below:
HC := HHV(HIGH, 14) - CLOSE;
HL := HHV(HIGH, 14) - LLV(LOW, 14);
WR := -100 * HC / HL;
MA20 : EMA2(C, 14);
C1 := WR < -60 && C > MA20;
C2 := WR > -15 && C < MA20;
C1, BPK;
C2, SPK;
%%
// adding the following code in any Mylanguage strategy can realize the push of position changes to mobile phone App and WeChat
if (typeof(scope._tmp) !== 'number') {
scope._tmp = 0;
}
var pos = scope.get_locals('BKVOL') - scope.get_locals('SKVOL');
if (pos != scope._tmp) {
scope._tmp = pos;
Log('Push position changes:', scope.symbol, pos, '@');
}
%%
In the above code, we put William W%R’s trading strategy and the function of pushing position changes together, so as to realize the real-time synchronization of trading strategy orders and position changes, and push them to the mobile App and WeChat.
Next, we run a bot to verify this function; create a bot, select OKEX spot, and set the currency pair to LTC_USDT (commodity futures and cryptocurrency futures can also use this function, and the operation is the same).
1.signal triggered, push to web logs 2.signal triggered, push to mobile phone App 3.signal triggered, push to WeChat message push
Above, we use a simple Mylanguage William W%R trading strategy and the message push module developed by the language enhancement module in Mylanguage, so as to realize the strategy to push position changes to mobile Apps and WeChat in real time. The module code can be attached to any Mylanguage strategy to push position changes to mobile Apps and WeChat, and launch various push types for different scenarios to meet your personalized push demands.