Reputation: 55
A newbie here. I am working on a strategy long/short. When i run my strategy the Long positions are closed as expected but the Short positions i believe are not. Because i have the fees setup to USD per order i want to make sure that every market order is opened/closed so i can back test my strategy. My code as follows.
hist = macd - signal
if (hist > 0.15)
strategy.entry("Long", strategy.long, comment="Long")
if (hist < -0.15)
strategy.close("Long")
if (hist < -0.15)
strategy.entry("Short", strategy.short, comment="Short")
if (hist > 0.15)
strategy.close("Short")
Thanks!
Upvotes: 1
Views: 1949
Reputation: 1961
This is correct behaivour as your conditions in fact defined as
hist = macd - signal
if (hist > 0.15)
strategy.entry("Long", strategy.long, comment="Long")
strategy.close("Short")
if (hist < -0.15)
strategy.close("Long")
strategy.entry("Short", strategy.short, comment="Short")
So when you enter Short position in (hist < -0.15)
condition,
at the next bars, when if (hist > 0.15)
is true you will revert your Short
position by strategy.entry("Long", strategy.long, comment="Long")
.
Upvotes: 1