|
|
@@ -176,10 +176,10 @@ impl Predictor {
|
|
|
fair_price: Default::default(),
|
|
|
fair_price_ema_short: Default::default(),
|
|
|
fair_price_ema_long: Default::default(),
|
|
|
- mid_rate_signal_open: Default::default(),
|
|
|
- mid_price_focus_cancel: Default::default(),
|
|
|
- mid_price_focus_stop_loss: Default::default(),
|
|
|
- mid_rate_signal_close: Default::default(),
|
|
|
+ mid_rate_signal_open: Self::DONT_VIEW,
|
|
|
+ mid_price_focus_cancel: Self::DONT_VIEW,
|
|
|
+ mid_price_focus_stop_loss: Self::DONT_VIEW,
|
|
|
+ mid_rate_signal_close: Self::DONT_VIEW,
|
|
|
|
|
|
price_times_avg: Default::default(),
|
|
|
|
|
|
@@ -402,36 +402,36 @@ impl Predictor {
|
|
|
mid_trend_rate.rescale(8);
|
|
|
|
|
|
// 重置开仓焦点,条件1
|
|
|
- if !self.mid_rate_signal_open.is_zero() && !self.inventory.is_zero() {
|
|
|
- self.mid_rate_signal_open = Decimal::ZERO;
|
|
|
- self.mid_price_focus_cancel = Decimal::ZERO;
|
|
|
- self.mid_price_focus_stop_loss = Decimal::ZERO;
|
|
|
+ if self.mid_rate_signal_open != Self::DONT_VIEW && !self.inventory.is_zero() {
|
|
|
+ self.mid_rate_signal_open = Self::DONT_VIEW;
|
|
|
+ self.mid_price_focus_cancel = Self::DONT_VIEW;
|
|
|
}
|
|
|
// 重置开仓焦点,条件2
|
|
|
- if !self.mid_price_focus_cancel.is_zero() {
|
|
|
+ if self.mid_price_focus_cancel != Self::DONT_VIEW {
|
|
|
if self.mid_rate_signal_open > Decimal::ZERO && self.mid_price > self.mid_price_focus_cancel {
|
|
|
- self.mid_rate_signal_open = Decimal::ZERO;
|
|
|
- self.mid_price_focus_cancel = Decimal::ZERO;
|
|
|
- self.mid_price_focus_stop_loss = Decimal::ZERO;
|
|
|
+ self.mid_rate_signal_open = Self::DONT_VIEW;
|
|
|
+ self.mid_price_focus_cancel = Self::DONT_VIEW;
|
|
|
+ self.mid_price_focus_stop_loss = Self::DONT_VIEW;
|
|
|
}
|
|
|
if self.mid_rate_signal_open < Decimal::ZERO && self.mid_price < self.mid_price_focus_cancel {
|
|
|
- self.mid_rate_signal_open = Decimal::ZERO;
|
|
|
- self.mid_price_focus_cancel = Decimal::ZERO;
|
|
|
- self.mid_price_focus_stop_loss = Decimal::ZERO;
|
|
|
+ self.mid_rate_signal_open = Self::DONT_VIEW;
|
|
|
+ self.mid_price_focus_cancel = Self::DONT_VIEW;
|
|
|
+ self.mid_price_focus_stop_loss = Self::DONT_VIEW;
|
|
|
}
|
|
|
}
|
|
|
// 更新程序关注的开仓焦点
|
|
|
- if self.mid_rate_signal_open.is_zero() && self.inventory.is_zero() {
|
|
|
+ if self.mid_rate_signal_open == Self::DONT_VIEW && self.inventory.is_zero() {
|
|
|
+ self.mid_price_focus_stop_loss = Self::DONT_VIEW;
|
|
|
// 是同起点
|
|
|
// let mut is_cross = fair_rate.abs() > self.params.open_activate;
|
|
|
// is_cross = is_cross && mid_rate.abs() > self.params.open_activate;
|
|
|
// is_cross = is_cross && ((mid_start - fair_start) / mid_start).abs() < dec!(0.0005);
|
|
|
|
|
|
// 最近80%的波动都发生在最近短周期的时间里
|
|
|
- let is_high_speed = mid_rate.abs() > mid_long_rate.abs() * dec!(0.8) && mid_rate * mid_long_rate > Decimal::ZERO;
|
|
|
+ // let is_high_speed = mid_rate.abs() > mid_long_rate.abs() * dec!(0.8) && mid_rate * mid_long_rate > Decimal::ZERO;
|
|
|
|
|
|
// mid_trend_rate防止追高
|
|
|
- if is_high_speed && mid_rate.abs() > self.params.open_activate {
|
|
|
+ if mid_rate.abs() > self.params.open_activate {
|
|
|
// 向上涨,带量的,视为观测阶段开始
|
|
|
if mid_rate > Decimal::ZERO && mid_long_rate > Decimal::ZERO && mid_trend_rate < Decimal::ZERO {
|
|
|
self.mid_rate_signal_open = dec!(0.01);
|
|
|
@@ -453,8 +453,8 @@ impl Predictor {
|
|
|
// 大于0:当前价格在均线之上
|
|
|
// 小于0:当前价格在均线之下
|
|
|
// 重置平仓焦点,条件1
|
|
|
- if !self.mid_rate_signal_close.is_zero() && self.inventory.is_zero() {
|
|
|
- self.mid_rate_signal_close = Decimal::ZERO;
|
|
|
+ if self.mid_rate_signal_close != Self::DONT_VIEW && self.inventory.is_zero() {
|
|
|
+ self.mid_rate_signal_close = Self::DONT_VIEW;
|
|
|
}
|
|
|
// // 重置平仓焦点,条件2
|
|
|
// if !self.fair_rate_focus_close.is_zero() && self.fair_rate_focus_close > dec!(-0.1) {
|
|
|
@@ -470,7 +470,7 @@ impl Predictor {
|
|
|
// }
|
|
|
// 更新程序关注的平仓焦点
|
|
|
let close_activate = self.params.open_activate;
|
|
|
- if self.mid_rate_signal_close.is_zero() && !self.inventory.is_zero() && mid_rate.abs() > close_activate {
|
|
|
+ if self.mid_rate_signal_close == Self::DONT_VIEW && !self.inventory.is_zero() && mid_rate.abs() > close_activate {
|
|
|
// 多单平仓逻辑
|
|
|
if self.inventory > Decimal::ZERO && mid_rate > Decimal::ZERO {
|
|
|
if self.profit_point > Decimal::ZERO {
|
|
|
@@ -516,7 +516,7 @@ impl Predictor {
|
|
|
// info!("----------------------------------------");
|
|
|
// }
|
|
|
// ============================ 平仓特殊逻辑处理2 =======================
|
|
|
- if self.mid_rate_signal_close.is_zero() && !self.inventory.is_zero() && self.profit_point_vec.len() > 1 {
|
|
|
+ if self.mid_rate_signal_close == Self::DONT_VIEW && !self.inventory.is_zero() && self.profit_point_vec.len() > 1 {
|
|
|
let prev_profit_point = self.profit_point_vec[self.profit_point_vec.len() - 2];
|
|
|
let profit_point = self.profit_point_vec[self.profit_point_vec.len() - 1];
|
|
|
|
|
|
@@ -529,23 +529,23 @@ impl Predictor {
|
|
|
}
|
|
|
}
|
|
|
// ============================ 平仓特殊逻辑处理3 =======================
|
|
|
- // if self.mid_rate_signal_close.is_zero() && !self.inventory.is_zero() {
|
|
|
- // if self.inventory > Decimal::ZERO && self.mid_price < self.mid_price_focus_stop_loss {
|
|
|
- // self.mid_rate_signal_close = dec!(-0.13);
|
|
|
- //
|
|
|
- // info!("----------------------------------------");
|
|
|
- // // info!("止损,参数调整:{} -> {}", prev_open_activate, self.params.open_activate);
|
|
|
- // info!("趋势失效止损, 在价格{}处,成本价{},价值={}, p={}。", self.mid_price, self.pos_avg_price, self.pos_avg_price*self.pos_amount, self.profit_point);
|
|
|
- // info!("----------------------------------------");
|
|
|
- // } else if self.inventory < Decimal::ZERO && self.mid_price > self.mid_price_focus_stop_loss {
|
|
|
- // self.mid_rate_signal_close = dec!(-0.13);
|
|
|
- //
|
|
|
- // info!("----------------------------------------");
|
|
|
- // // info!("止损,参数调整:{} -> {}", prev_open_activate, self.params.open_activate);
|
|
|
- // info!("趋势失效止损, 在价格{}处,成本价{},价值={}, p={}。", self.mid_price, self.pos_avg_price, self.pos_avg_price*self.pos_amount, self.profit_point);
|
|
|
- // info!("----------------------------------------");
|
|
|
- // }
|
|
|
- // }
|
|
|
+ if self.mid_rate_signal_close == Self::DONT_VIEW && !self.inventory.is_zero() {
|
|
|
+ if self.inventory > Decimal::ZERO && self.mid_price < self.mid_price_focus_stop_loss * dec!(0.9995) {
|
|
|
+ self.mid_rate_signal_close = dec!(-0.13);
|
|
|
+
|
|
|
+ info!("----------------------------------------");
|
|
|
+ // info!("止损,参数调整:{} -> {}", prev_open_activate, self.params.open_activate);
|
|
|
+ info!("趋势失效止损, 在价格{}处,成本价{},价值={}, p={}。", self.mid_price, self.pos_avg_price, self.pos_avg_price*self.pos_amount, self.profit_point);
|
|
|
+ info!("----------------------------------------");
|
|
|
+ } else if self.inventory < Decimal::ZERO && self.mid_price > self.mid_price_focus_stop_loss * dec!(1.0005) {
|
|
|
+ self.mid_rate_signal_close = dec!(-0.13);
|
|
|
+
|
|
|
+ info!("----------------------------------------");
|
|
|
+ // info!("止损,参数调整:{} -> {}", prev_open_activate, self.params.open_activate);
|
|
|
+ info!("趋势失效止损, 在价格{}处,成本价{},价值={}, p={}。", self.mid_price, self.pos_avg_price, self.pos_avg_price*self.pos_amount, self.profit_point);
|
|
|
+ info!("----------------------------------------");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// // 判断价格是否回归
|