@ -1,3 +1,7 @@
// The reverse-engineered code is not perfectly accurate, especially as it's not
// 32-bit ARM floating point. So, be tolerant of slightly unexpected inputs
const FUDGE _FACTOR = 5 ;
const PATTERN = {
FLUCTUATING : 0 ,
LARGE _SPIKE : 1 ,
@ -105,7 +109,7 @@ function* generate_pattern_0_with_lengths(given_prices, high_phase_1_len, dec_ph
min _pred = intceil ( 0.9 * buy _price ) ;
max _pred = intceil ( 1.4 * buy _price ) ;
if ( ! isNaN ( given _prices [ i ] ) ) {
if ( given _prices [ i ] < min _pred || given _prices [ i ] > max _pred ) {
if ( given _prices [ i ] < min _pred - FUDGE _FACTOR || given _prices [ i ] > max _pred + FUDGE _FACTOR ) {
// Given price is out of predicted range, so this is the wrong pattern
return ;
}
@ -128,7 +132,7 @@ function* generate_pattern_0_with_lengths(given_prices, high_phase_1_len, dec_ph
if ( ! isNaN ( given _prices [ i ] ) ) {
if ( given _prices [ i ] < min _pred || given _prices [ i ] > max _pred ) {
if ( given _prices [ i ] < min _pred - FUDGE _FACTOR || given _prices [ i ] > max _pred + FUDGE _FACTOR ) {
// Given price is out of predicted range, so this is the wrong pattern
return ;
}
@ -152,7 +156,7 @@ function* generate_pattern_0_with_lengths(given_prices, high_phase_1_len, dec_ph
min _pred = intceil ( 0.9 * buy _price ) ;
max _pred = intceil ( 1.4 * buy _price ) ;
if ( ! isNaN ( given _prices [ i ] ) ) {
if ( given _prices [ i ] < min _pred || given _prices [ i ] > max _pred ) {
if ( given _prices [ i ] < min _pred - FUDGE _FACTOR || given _prices [ i ] > max _pred + FUDGE _FACTOR ) {
// Given price is out of predicted range, so this is the wrong pattern
return ;
}
@ -175,7 +179,7 @@ function* generate_pattern_0_with_lengths(given_prices, high_phase_1_len, dec_ph
if ( ! isNaN ( given _prices [ i ] ) ) {
if ( given _prices [ i ] < min _pred || given _prices [ i ] > max _pred ) {
if ( given _prices [ i ] < min _pred - FUDGE _FACTOR || given _prices [ i ] > max _pred + FUDGE _FACTOR ) {
// Given price is out of predicted range, so this is the wrong pattern
return ;
}
@ -202,7 +206,7 @@ function* generate_pattern_0_with_lengths(given_prices, high_phase_1_len, dec_ph
min _pred = intceil ( 0.9 * buy _price ) ;
max _pred = intceil ( 1.4 * buy _price ) ;
if ( ! isNaN ( given _prices [ i ] ) ) {
if ( given _prices [ i ] < min _pred || given _prices [ i ] > max _pred ) {
if ( given _prices [ i ] < min _pred - FUDGE _FACTOR || given _prices [ i ] > max _pred + FUDGE _FACTOR ) {
// Given price is out of predicted range, so this is the wrong pattern
return ;
}
@ -282,7 +286,7 @@ function* generate_pattern_1_with_peak(given_prices, peak_start) {
if ( ! isNaN ( given _prices [ i ] ) ) {
if ( given _prices [ i ] < min _pred || given _prices [ i ] > max _pred ) {
if ( given _prices [ i ] < min _pred - FUDGE _FACTOR || given _prices [ i ] > max _pred + FUDGE _FACTOR ) {
// Given price is out of predicted range, so this is the wrong pattern
return ;
}
@ -309,7 +313,7 @@ function* generate_pattern_1_with_peak(given_prices, peak_start) {
max _pred = intceil ( max _randoms [ i - peak _start ] * buy _price ) ;
if ( ! isNaN ( given _prices [ i ] ) ) {
if ( given _prices [ i ] < min _pred || given _prices [ i ] > max _pred ) {
if ( given _prices [ i ] < min _pred - FUDGE _FACTOR || given _prices [ i ] > max _pred + FUDGE _FACTOR ) {
// Given price is out of predicted range, so this is the wrong pattern
return ;
}
@ -370,7 +374,7 @@ function* generate_pattern_2(given_prices) {
if ( ! isNaN ( given _prices [ i ] ) ) {
if ( given _prices [ i ] < min _pred || given _prices [ i ] > max _pred ) {
if ( given _prices [ i ] < min _pred - FUDGE _FACTOR || given _prices [ i ] > max _pred + FUDGE _FACTOR ) {
// Given price is out of predicted range, so this is the wrong pattern
return ;
}
@ -448,7 +452,7 @@ function* generate_pattern_3_with_peak(given_prices, peak_start) {
if ( ! isNaN ( given _prices [ i ] ) ) {
if ( given _prices [ i ] < min _pred || given _prices [ i ] > max _pred ) {
if ( given _prices [ i ] < min _pred - FUDGE _FACTOR || given _prices [ i ] > max _pred + FUDGE _FACTOR ) {
// Given price is out of predicted range, so this is the wrong pattern
return ;
}
@ -473,7 +477,7 @@ function* generate_pattern_3_with_peak(given_prices, peak_start) {
min _pred = intceil ( 0.9 * buy _price ) ;
max _pred = intceil ( 1.4 * buy _price ) ;
if ( ! isNaN ( given _prices [ i ] ) ) {
if ( given _prices [ i ] < min _pred || given _prices [ i ] > max _pred ) {
if ( given _prices [ i ] < min _pred - FUDGE _FACTOR || given _prices [ i ] > max _pred + FUDGE _FACTOR ) {
// Given price is out of predicted range, so this is the wrong pattern
return ;
}
@ -491,7 +495,7 @@ function* generate_pattern_3_with_peak(given_prices, peak_start) {
min _pred = intceil ( 1.4 * buy _price ) - 1 ;
max _pred = intceil ( 2.0 * buy _price ) - 1 ;
if ( ! isNaN ( given _prices [ peak _start + 2 ] ) ) {
if ( given _prices [ peak _start + 2 ] < min _pred || given _prices [ peak _start + 2 ] > max _pred ) {
if ( given _prices [ peak _start + 2 ] < min _pred - FUDGE _FACTOR || given _prices [ peak _start + 2 ] > max _pred + FUDGE _FACTOR ) {
// Given price is out of predicted range, so this is the wrong pattern
return ;
}
@ -507,7 +511,7 @@ function* generate_pattern_3_with_peak(given_prices, peak_start) {
min _pred = predicted _prices [ peak _start + 2 ] . min ;
max _pred = intceil ( 2.0 * buy _price ) ;
if ( ! isNaN ( given _prices [ peak _start + 3 ] ) ) {
if ( given _prices [ peak _start + 3 ] < min _pred || given _prices [ peak _start + 3 ] > max _pred ) {
if ( given _prices [ peak _start + 3 ] < min _pred - FUDGE _FACTOR || given _prices [ peak _start + 3 ] > max _pred + FUDGE _FACTOR ) {
// Given price is out of predicted range, so this is the wrong pattern
return ;
}
@ -523,7 +527,7 @@ function* generate_pattern_3_with_peak(given_prices, peak_start) {
min _pred = intceil ( 1.4 * buy _price ) - 1 ;
max _pred = predicted _prices [ peak _start + 3 ] . max - 1 ;
if ( ! isNaN ( given _prices [ peak _start + 4 ] ) ) {
if ( given _prices [ peak _start + 4 ] < min _pred || given _prices [ peak _start + 4 ] > max _pred ) {
if ( given _prices [ peak _start + 4 ] < min _pred - FUDGE _FACTOR || given _prices [ peak _start + 4 ] > max _pred + FUDGE _FACTOR ) {
// Given price is out of predicted range, so this is the wrong pattern
return ;
}
@ -545,7 +549,7 @@ function* generate_pattern_3_with_peak(given_prices, peak_start) {
if ( ! isNaN ( given _prices [ i ] ) ) {
if ( given _prices [ i ] < min _pred || given _prices [ i ] > max _pred ) {
if ( given _prices [ i ] < min _pred - FUDGE _FACTOR || given _prices [ i ] > max _pred + FUDGE _FACTOR ) {
// Given price is out of predicted range, so this is the wrong pattern
return ;
}