用python的eval函数自定义行情指标公式
- 先看效果
- 实现步骤
- 计算结果
先看效果
实现步骤
在前端配置规则和公式,不同的结果可以自定义背景颜色和字体颜色。
def _compute_rule(self, localdict):
"""
:param localdict: dictionary containing the current computation environment
:return: returns a tuple (amount, qty, rate)
:rtype: (float, float, float)
"""
self.ensure_one()
localdict['localdict'] = localdict
try:
safe_eval(self.rule_condition or 0.0, localdict, mode='exec', nocopy=True)
return float(localdict['result']), localdict.get('result_qty', 1.0), localdict.get('result_rate', 100.0)
except Exception as e:
raise self._raise_error(localdict, _("Wrong python code defined for:"), e)