diff --git a/src/strategy_team/future_strategy_long.rs b/src/strategy_team/future_strategy_long.rs index b31c4d6..c29a2fa 100644 --- a/src/strategy_team/future_strategy_long.rs +++ b/src/strategy_team/future_strategy_long.rs @@ -121,6 +121,57 @@ pub async fn list_up_for_buy( } remove_keys(&mut filtered_data, keys_to_remove).await; + let mut keys_to_remove: HashSet = HashSet::new(); + let server_epoch = get_server_epoch().await; + for (symbol, values) in &mut filtered_data { + let mut do_buy = false; + let opclo_sample_length: usize = 60; // 15 candle samsples + let mut target_profit_percent = 0.0; + if let Some(price_1m_vec) = alldata.rt_price_1m_vec.get(symbol) { + let vec_len = price_1m_vec.len(); + if let Some(candles) = + price_1m_vec.get(vec_len - opclo_sample_length - 2..vec_len - 1) + { + let windows = candles.windows(2); + let mut sum_amplitude_candles = 0.0; + let mut sum_ratio_amp_body = 0.0; + let mut average_amplitude = 0.0; + + for window in windows { + sum_amplitude_candles += ((window.last().unwrap().high_price + - window.last().unwrap().low_price) + * 100.0) + / window.first().unwrap().close_price; + } + let average_amplitude = sum_amplitude_candles / opclo_sample_length as f64; // percent unit + let mut amplitude_variance = 0.0; + + let windows = candles.windows(2); + for window in windows { + amplitude_variance += ((((window.last().unwrap().high_price + - window.last().unwrap().low_price) + * 100.0) + / window.first().unwrap().close_price) + - average_amplitude) + .powi(2); + } + amplitude_variance = amplitude_variance / (opclo_sample_length - 1) as f64; + let standard_deviation_amplitude = amplitude_variance.sqrt(); + target_profit_percent = + average_amplitude + (standard_deviation_amplitude * 0.5); + + if target_profit_percent * 2.0 > 0.14 { + do_buy = true; + } + } + } + + if do_buy == false { + keys_to_remove.insert(symbol.clone()); + } + } + remove_keys(&mut filtered_data, keys_to_remove).await; + // StochRSI (RSI_len: 30, StochRSI_len: 30, K: 2, D: 2) K_current < 70, K_prev < 70, K_prev_1 < 70 // let server_epoch = get_server_epoch().await; // let mut keys_to_remove: HashSet = HashSet::new(); diff --git a/src/strategy_team/future_strategy_short.rs b/src/strategy_team/future_strategy_short.rs index 412dda8..b5995c8 100644 --- a/src/strategy_team/future_strategy_short.rs +++ b/src/strategy_team/future_strategy_short.rs @@ -121,6 +121,57 @@ pub async fn list_up_for_buy( } remove_keys(&mut filtered_data, keys_to_remove).await; + let mut keys_to_remove: HashSet = HashSet::new(); + let server_epoch = get_server_epoch().await; + for (symbol, values) in &mut filtered_data { + let mut do_buy = false; + let opclo_sample_length: usize = 60; // 15 candle samsples + let mut target_profit_percent = 0.0; + if let Some(price_1m_vec) = alldata.rt_price_1m_vec.get(symbol) { + let vec_len = price_1m_vec.len(); + if let Some(candles) = + price_1m_vec.get(vec_len - opclo_sample_length - 2..vec_len - 1) + { + let windows = candles.windows(2); + let mut sum_amplitude_candles = 0.0; + let mut sum_ratio_amp_body = 0.0; + let mut average_amplitude = 0.0; + + for window in windows { + sum_amplitude_candles += ((window.last().unwrap().high_price + - window.last().unwrap().low_price) + * 100.0) + / window.first().unwrap().close_price; + } + let average_amplitude = sum_amplitude_candles / opclo_sample_length as f64; // percent unit + let mut amplitude_variance = 0.0; + + let windows = candles.windows(2); + for window in windows { + amplitude_variance += ((((window.last().unwrap().high_price + - window.last().unwrap().low_price) + * 100.0) + / window.first().unwrap().close_price) + - average_amplitude) + .powi(2); + } + amplitude_variance = amplitude_variance / (opclo_sample_length - 1) as f64; + let standard_deviation_amplitude = amplitude_variance.sqrt(); + target_profit_percent = + average_amplitude + (standard_deviation_amplitude * 0.5); + + if target_profit_percent * 2.0 > 0.14 { + do_buy = true; + } + } + } + + if do_buy == false { + keys_to_remove.insert(symbol.clone()); + } + } + remove_keys(&mut filtered_data, keys_to_remove).await; + // StochRSI (RSI_len: 30, StochRSI_len: 30, K: 2, D: 2) K_current < 70, K_prev < 70, K_prev_1 < 70 // let server_epoch = get_server_epoch().await; // let mut keys_to_remove: HashSet = HashSet::new();