Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to migrate JavaScript policies

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to transplant JavaScript strategy". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to transplant JavaScript strategy".

Let's first take a look at the strategy for this transplant:

(* backteststart: 2019-05-01 00:00:00end: 2019-11-12 00:00:00period: 1dexchanges: [{"eid": "Futures_OKCoin", "currency": "BTC_USD"}] args: [["SlideTick", 10pr 126961], ["ContractType", "quarter", 126961]] *) N1V 10 + + N200:00:00period "21ntAPMA = (HIGH+LOW+CLOSE) / 3terESADA EMA (AP,N1); D:=EMA (ABS (AP-ESA), N1) CI:= (AP-ESA) / (0.015mm D); TCI:=EMA (CI,N2); WT1:TCI;WT2:SMA (WT1,4,1); AA:=CROSS (WT1,WT2); BB:=CROSSDOWN (WT1,WT2); REF (AA,1), BPK;REF (BB,1), SPK

The beginning of this wheat language policy (* backtest...*) is the configuration code for the backtest settings. To facilitate comparison, set a unified retest configuration. This strategy is also a random strategy, and it is not too complex (compared to the one in the last article). It is a more representative strategy. To transplant a wheat language strategy, we must first take a look at the strategy content. The wheat language strategy code is relatively concise. Basically, we can have a certain understanding of the overall situation of the strategy. We can see that several indicator functions EMA,SMA are used in this strategy:

Build a wheel first.

EMA

This index function has a ready-made index library function when the strategy is written in JavaScript language on the FMZ platform. Namely: TA.MA

SMA

What we need to do is the SMA metric. We found that the SMA metric function is not supported in FMZ's TA library, and there are differences between SMA metrics in talib library and those in wheat language:

As you can see, the parameter part not only has a periodic parameter, but also has a weight parameter.

The description of the SMA indicator function in the talib library in FMZ API documents is as follows:

It can be seen that talib.SMA is a simple moving average.

In this way, you have to implement a SMA yourself, which is one of the necessary skills as a developer who writes strategies in Java script language. after all, if you don't have ready-made wheels, you still have to drive, just build one.

To tell you the truth, there is not much research on indicators, generally do not understand the search, check the information. For SMA, these are found:

Feel that the process of this algorithm is quite reliable, so let's implement it:

Function SMA (arr, n, m) {var sma = [] var currSMA = null for (var I = 0; I < arr.length Arr +) {if (arr [I] & &! isNaN (arr [I]) {if (! currSMA) {currSMA = arr [I] sma.push (currSMA) continue} / / [MacroC2+ (Nripm) * S1] / N currSMA = (m *) Arr [I] + (n-m) * currSMA) / n sma.push (currSMA)} else {sma.push (NaN)}} return sma}

Write the fill section

The policy framework uses hand-in-hand to teach you to write strategies-transplant the same framework in a mylanguage strategy article, mainly filling in two parts:

First of all, do market data processing, index calculation.

We deal with the function of this part of Mai language one by one:

1. AP:= (HIGH+LOW+CLOSE) / 3

The highest price, the lowest price and the closing price of each BAR in the K-line data are added and divided by 3, the average is calculated, and then saved as an array that corresponds to each BAR one by one.

It can be handled as follows:

Function CalcAP (r) {/ / AP:= (HIGH+LOW+CLOSE) / 3; var arrAP = [] / / declares an empty array for (var I = 0; I < r.length) For traverses the array v = (r [I] .High + r [I] .Low + r [I] .close) / 3 / calculates the average arrAP.push (v) / / adds to the tail of the arrAP array, which is the first when arrAP is empty. } return arrAP / / returns this array of averages, that is, the AP calculated in the Mac language.

You can call this function in the main loop OnTick function, for example:

/ / calculate metrics / / APvar ap = CalcAP (records)

2. After the AP calculation is completed, then calculate the ESA:=EMA (AP,N1);

Here, we want to use the AP data calculated in the previous step to calculate ESA. In fact, this ESA is the "exponential moving average" of AP, that is, the EMA index, so we use AP as the data, N1 as the parameter of the EMA index, and calculate the EMA index.

Function CalcESA (ap, N1) {/ / ESA:=EMA (AP,N1); if (ap.length)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report