-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Laddered OCO order with multiple entries/take profits #367
Comments
I've thought about this before - a combination of a ladder order and OCO. FYI there's also #152 which I think is pretty important. Yes, you could definitely do it with a script easily if you're happy with a fixed number of "ladder" prices (e.g. buy 1, buy 2, buy 3). However, you don't actually NEED ia new order type to do what you want. You could just use the existing OCO feature to place multiple "soft" buys and sells at different prices. You are allowed to use OCO with only one buy or only one sell (just only fill in the "below" section or the "above" section. It's a little bit weird and it's a bit bit more work when setting up a trade, but it works. It's what I do. |
The big thing you don't get with that approach is "reduce only" behaviour on the stops/take profits, which can definitely get you into trouble if you're not careful! |
Ok, I got your idea of using existing OCO to achieve this. So we place multiple oco here |
Regarding the script implementation, it seems we can only create limit order in js and we can't get the status of the order we create. So the same partial filled problem, the stop loss and take profit order might not executed I think? |
Yes, there's no way (currently) of modifying orders. Any "soft" order (a stop or take-profit using OCO) should automatically reduce in size to match the available balance when it places the limit order on the exchange. So, if you have:
Then if the price dips to 5700, then spikes immediately up to 9500, then down to 5400 and then up to 11000, what will happen is this:
I hope that gives you an example of the sort of thing that might happen. Another example is what could happen if the price just immediately rose to 11000 without hitting your limit orders and you already had some BTC held - it would sell that BTC without having bought any extra, With a proper, integrated ladder/OCO order, we could automatically cancel/adjust the linked orders to make sure they produce a consistent result and don't affect balances outside that "block". OK - one other point: see #344 - there is a bug with the calculation of the trade amounts on some exchanges which can cause the take profit to fail, depending on whether the exchange takes the fees from the purchased asset or in addition to the purchased asset. So, the initial limit order for 1BTC might leave you with 0.999 BTC when 0.1% fees are subtracted on some exchanges, but on other exchanges, it will leave you with 0.1 BTC but take the additional 0,1% from your USD balance. That does need fixing urgently. I know this is definitely not a problem on Binance if you use BNB for fees but I'm not 100% certain about the others, so I suggest testing it before relying on it until I fix that bug! Sorry this is all a bit complicated! I'm working on this in my spare time so things can take a while. |
Thanks for the detail response, I got what you mean now. So still a problem here, if we have three buy oco but only one get filled, if we want to set three target to sell, then we may sell all the filled asset in the first oco sell order. Maybe we could add someway to get the order status in the js so that we can check it in the script? And if I implement this in a script, how can we show the status in the ui, it seems no way to pass out data currently? |
Oh, #144 looks like you already notice the script problem. |
I think another way to do this is on the user side, add a interface including dynamic number of rows to place multiple oco order in one click submit. |
I've been thinking about this regarding the "full" solution. What do we want to happen if only some of the entry orders hit and then we start hitting the laddered take-profits? We can't fill all of the TPs (we didn't buy enough) so: Should we cancel the first TPs we are going to hit, or the last? Or should this be an option? That is: if I have buys at 120, 110 and 100 and sells at 180, 190 and 200, all for 0.1 BTC, and my 120 and 110 buys get filled, should I cancel the sell at 180 or 200? |
In my opinion, we should sell at percentage of each target. Like if we set sell 30%(0.09btc) at 180, 30% (0.09btc)at 190, 40%(0.12btc) at 200, but only 0.2 btc of 0.3 btc filled. So now, we sell 30%(0.06btc) at 180, 30% at 190, 40% at 200. |
I think this would depend on your trading strategy. If you are trading a trend, I think cancelling TP orders should be an option if early limit orders start getting hit, but you werent filled completely. However, there are times where you want to keep the old orders in, for example, if the price is stuck in a range and your buy/sell orders are staggered in an area of outer standard deviations for those ranges. Trailing stops should also always be an option to seal in profit, which should also give the user the option to allow the cancellation of all lower bids (or upper asks) still on the book if the trailing stop gets hit. Now, how do we decide where the TP orders will be? Its always a nuisance to fill in everything manually...this is where ability to calculate simple TA (EMAs and Standard Deviations) would come in super handy. |
Agreed. There are loads of good things we could do with candlestick data and a TA library like ta4j. Some exchanges publish candlestick data, but not all. The first thing would be to try and create a standard API for candlestick data in XChange. That would provide an exchange-independent means of calculating stuff like MAs, and those can then be used in scripts as well as calculating ladders and even driving a fully-integrated TradingView chart (so you can show and adjust trades on the chart and save chart settings...) |
I think lowwer also has a good point. Automatically adjusting TP level QTY by the total % actually filled is a good idea. |
Hello, can we support all in one oco order like 3commas and other platform provide.
https://support.3commas.io/hc/en-us/sections/360000044853-Smart-Trade
For example,
I can set all these things in one order.
A. Buy Order with multiple price and quantity.
first buy at 220 sats with 0.1 btc, second buy at 210 sats with 0.2 btc
B. Stop loss order
Stoploss at 180 sats
C. Multiple sell target
sell 30% at 300 sats, sell 50% at 350 sats, sell 20% at 390 sats
We can add a new type for this or we can use the script function to do this?
The text was updated successfully, but these errors were encountered: