For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Question: How to decide buy and sell order for once?
-
Dear all
I make the strategy to use RSI. I make easy example code to make sure the behavior follows.if self.RSI[0] < -80, I buy. if self.dataclose[0] > -20, I sell. And I check the command prompt, there are many sell order. 2014-02-24, SELL CREATE, 14837.68 2014-02-25, SELL EXECUTED, Price: 15002.51, Cost: 14803.64, Comm 0.00 2014-03-06, SELL CREATE, 15134.75 2014-03-07, SELL EXECUTED, Price: 15280.76, Cost: 14933.76, Comm 0.00 ....
I want to do buy and next time should be sell. How to do these?
-
def next(self): if not self.position: # check if open position exists if self.RSI[0] < -80, I buy # open position if self.position: if self.dataclose[0] > -20, I sell # close position
-
Most assets have prices well above
0
and henceif self.data.close > -20
will probably always evaluate to
True
(the asset in use here could have prices below0
of course) and therefore it willsell
Additionally, the
RSI
oscillates between0
and100
, so thisif self.rsi < -80
is for sure never going to evaluate to
True
, i.e.: it will neverbuy
If there is also no control of whether one is in the market,
sell
orders will be continuously issued.The code by
ab_trader
respects the original but controls the position but controls the position. The final outcome will probably be:- One
sell
- No
buy
ever
- One