close long position at specific price #228
Replies: 4 comments 4 replies
-
You can use Alternatively, you can set a take-profit price for the order: self.buy(..., tp=40_000) or for the existing trade by assigning to its trade = self.trades[0]
trade.tp = 40_000 |
Beta Was this translation helpful? Give feedback.
-
yes sadly this does not seem to work for me :(
…On Tue, Feb 9, 2021 at 4:55 PM tombohub ***@***.***> wrote:
@kernc <https://github.com/kernc> I am trying to buy on Open and sell on
Close the same candlestick, but it doesn't seem thats possible, is it?
class Overnight(backtesting.Strategy):
def init(self):
self.buy()
def next(self):
self.position.close()
self.buy()
bt = backtesting.Backtest(df, Overnight, trade_on_close=True)stats = bt.run()print(stats['_trades'])
It's now buying on Close and selling on Close next candlestick.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#228 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAD73F4KXDQLFZAGHSCYRLS6HKPNANCNFSM4WJD2RAQ>
.
--
------------------------------------------------------------
Lead Developer - Fiehnlab, UC Davis
gert wohlgemuth
work:
http://fiehnlab.ucdavis.edu/staff/wohlgemuth
linkedin:
https://www.linkedin.com/in/berlinguyinca
|
Beta Was this translation helpful? Give feedback.
-
No I'm using backtesting.py and have a simple wrapper around it to work
with my trading bot.
…On Tue, Feb 9, 2021, 5:11 PM tombohub ***@***.***> wrote:
@berlinguyinca <https://github.com/berlinguyinca> that's too bad.. Are
you using some other backtester where you can open and close on the same
candlestick?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#228 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAD73CXUPNODE3EAW2DUT3S6HMNRANCNFSM4WJD2RAQ>
.
|
Beta Was this translation helpful? Give feedback.
-
You can also try
If the set price is between the high and low of the incoming candle, the order gets the price that you've specified. |
Beta Was this translation helpful? Give feedback.
-
good morning. I would like to close a long position at a specific price. Say sell BTC at 40k. Right now the default price is calculated based on market price:
Which can lead to vastly and highly inflated wrong results, due to using 'Open' of the next candle.
I'm working on a trading bot, which uses internally different algorithms for automatic profit-taking on certain conditions. For example, close the positions when you hit 1%.
so is there some way to provide 'position.close(price)' instead of just 'position.close()"
I have no interrest in the buy/sell, long/short approach.
Beta Was this translation helpful? Give feedback.
All reactions