Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何设置条件规则_Python_Algorithmic Trading - Fatal编程技术网

Python 如何设置条件规则

Python 如何设置条件规则,python,algorithmic-trading,Python,Algorithmic Trading,我在Pine Editor/TradingView中编写了此购买/出售策略: buy_condition= a<b sell_condition= a>b strategy.entry("Long", strategy.long, when=buy_condition) strategy.exit("L_Out", "Long", profit=1000, loss=500) strategy.entry("Sh

我在Pine Editor/TradingView中编写了此购买/出售策略:

buy_condition= a<b
sell_condition= a>b

strategy.entry("Long", strategy.long, when=buy_condition)
strategy.exit("L_Out", "Long", profit=1000, loss=500)
strategy.entry("Short", strategy.short, when=sell_condition)
strategy.exit("S_Out", "Short", profit=1000, loss=500)
购买条件=ab
strategy.entry(“Long”,strategy.Long,when=buy\u条件)
策略.退出(“L_Out”,“Long”,利润=1000,亏损=500)
strategy.entry(“Short”,strategy.Short,when=sell\u条件)
策略.退出(“S_Out”,“Short”,利润=1000,亏损=500)

在多头或空头仓位中,当相反的情况变为现实时,它会改变仓位,但我希望它保持在仓位上,直到达到盈利或止损。然后它可以进入任何适合的位置。如何编写此规则?

也许您想替换您的:

buy_condition= a<b
sell_condition= a>b
购买条件=ab
作者:

def购买条件(a、b):
返回ab
当您创建购买条件时,它会在此时计算结果,而不是稍后。
所以如果
aHi Onur Kiris,欢迎使用堆栈溢出。请提供一个帮助我们复制您的问题。当我在Pine Editor中键入“def”时,它没有识别出来。下面的链接是关于“Pine脚本语言参考手册”。你能帮我查一下吗?我刚刚在条件中添加了'strategy.position_size==0',它成功了