The resource loading... loading...

Built-in function_Cross analysis and instructions

Author: Inventors quantify - small dreams, Created: 2017-10-11 19:50:44, Updated: 2021-11-05 16:15:56

Built-in function_Cross analysis and instructions

The _Cross function in the global function array in the API documentation is used to calculate the cross state of two pointer lines

  • The ### function implements code similar to the following:

It's important to note thatarr1It is defined as a fast-track indicator array.arr2When defined as a slow-line indicator array,

  可知,此时```arr1```上穿```arr2```已经n个周期,此时就是快线上穿慢线代表金叉。
  同样```_Cross```函数如果返回负数,即为死叉。
  
  如果定义```arr1```为慢线指标数组,```arr2```为快线指标数组,则相反。
  ```_Cross```函数返回的值为正数代表死叉。
  ```_Cross```函数返回的值为负数代表金叉。

// Returns the number of cycles of upward wear, the positive number is the number of weeks of upward wear, the negative number is the number of weeks of downward wear, 0 is the same as the current price $.Cross = function ((arr1, arr2) { // The number of arguments is 2, as can be seen from the name of the arguments, these two arguments should be of the type of array, the array should be // as if the line segment in the coordinate system where the X axis is the index value of the array and the Y axis is the indicator value, the function is to determine the intersection of the two lines if (arr1.length!== arr2.length) { // First, we need to determine whether the two arrays are equal in length. throw array length not equal; // If unequal is thrown, the error cannot be judged for unequal pointers I'm not sure. var n = 0; // Declared variable n used to record the cross-state, initial 0, not overlapping for (var i = arr1.length-1; i >= 0; i) { // traverses the array arr1, traversing the sequence as traversed from the last element onwards if (typeof ((arr1[i])!== number typeof ((arr2[i])!== number) { // jumps out of the loop when any of the arrays of arr1 or arr2 is of non-numeric type (i.e. invalid indicator) break; // jump out of the loop I'm not sure. if (arr1[i] < arr2[i]) { // If arr1 is smaller than arr2 then n is odd, then the relative states of arr1 and arr2 are recorded at the beginning, whereas at the beginning, n is self-adjusted according to the relative sizes of arr1[i] and arr2[i], and when another relation of the opposite sizes of arr1[i] and arr2[i] occurs, the two lines intersect. If (n > 0) { I'm going to break. I'm not sure. I'm not sure. } else if (arr1[i] > arr2[i]) { // n++ if arr1 is greater than arr2 If (n < 0) { I'm going to break. I'm not sure. n++; } else { // arr1[i] == arr2[i], then jump out immediately I'm going to break. I'm not sure. I'm not sure. return n; // Returns the n-value, which represents how many cycles have been crossed, 0 is equal to the indicator value I'm not sure.


- #### 我们模拟一组数据传入该参数看看结果如何

var arr1 = [1, 2, 3, 4, 5, 6, 8, 8,9] // the fast-line indicator var arr2 = [2, 3, 4, 5, 6, 7, 7, 7] // the indicator of the slow line function main (()) { Log ((_Cross ((arr1, arr2)): the log, _Cross ((arr1, arr2)) Log ((_Cross ((arr2, arr1)): the log, _Cross ((arr2, arr1)) I'm not sure. What's up?

内置函数_Cross分析及使用说明

You can see that the result is 3, 3, 3.

内置函数_Cross分析及使用说明

As can be seen in the diagram, the position of the intersection occurs before the three K-line columns.


More

alphaStrategy00XSo if you don't have a cross, you should return 0.

And the cabbage.What if we cross back and forth?

Inventors quantify - small dreamsWell, let's think about that.

alphaStrategy00XThank you for your reply! I mean, returning 0 is more reasonable, right?

Inventors quantify - small dreamsWhat's up? var arr1 = [1, 2, 3, 4, 5, 6, 8, 8,9] // the fast-line indicator var arr2 = [2, 3, 4, 5, 6, 7, 7, 7] // the indicator of the slow line function main (()) { Log (("_Cross ((arr1, arr2) ": ", _Cross ((arr1, arr2)) Log (("_Cross ((arr2, arr1) ": ", _Cross ((arr2, arr1)) I'm not sure. What's up? You can use this to run a set of non-crossing arrays. I'm not going to return 0.

Inventors quantify - small dreamsOnly the most recent cross-section is detected, and source code analysis can tell.