How to build on last order to further execute orders?
-
basically I want to check the last buy order, if current close is larger than last execution, we buy another 50% in from the rest of cash. but no more than 3 times.
The command wont execute, I know it could to be something likeorder.executed.price[0]
but I couldn't find a right expression for it:
def next(self): self.count = 0 if not self.position: if self.datahigh[0]>self.upper: dif =self.short - self.long if dif > 0: self.order = self.order_target_percent(target=0.5) else: if self.datalow[0] < self.lower: dif = self.short - self.long if dif < 0: self.order = self.close() elif self.data.close[0] < self.short*0.90: self.order = self.close() elif self.close[0] > order.executed.price[0]*1.5: if self.count < 4: self.order = self.order_target_percent(target=0.5) self.count += 1 self.order = self.order_target_percent(target=0.5)
please help
-
got a redundant line in the end. please ignore
-
Re: How to build on last order to further execute orders?
tried
elif self.close[0] > self.buyprice[0] * 1.5: or elif self.close[0] > self.buyprice * 1.5:
doesn't really work
and
I can't modify my post? can't even delete it? -
Is your closing price really going to increase by 1.5 times? That's a pretty big move.
-
just trying to figure out a way to execute this kind of request.
-
@Zoutain-Ye The point i'm making is your if/elif statment might not trigger if your price isn't increasing by 50% over the buyprice. That might be stopping execution.
-
First, set variable to count entries.
Then, from
notify_order
get execution price when counter is zero and set it to separate variable.In the
next()
check if current close higher than execution price, then if counter is less than 4 issue the order and increase the counter (ideally this increase should be done innotify_order
after the order is confirmed as completed, but in case of market orders and enough cash should be good here)On my opinion it will be easier to use target value order with the value equal to half of the cash available + value of the position open.
Don't forget to set counter to zero when position is closing.