Giter VIP home page Giter VIP logo

Comments (5)

tony-ho avatar tony-ho commented on September 24, 2024

@crlsnr You are correct that the OCO behaviour for scale out positions has changed. In v2.0.0, two orders are placed after the buy order is filled:

  • limit order for scale out amount
  • stop order for remaining amount

The stop order is left to protect the remaining amount, and the limit order is watched and treated as an OCO position for the target sell amount. If the stop price is reached, the limit order is cancelled and a second stop order is placed for the scale out amount. Between the two stop orders, the full position is protected.

This was changed to simplify managing the OCO position and to ensure there is always a stop in place for the remaining amount.

That said, if for some reason the app exits after the buy order is filled but before the target is hit then the full position wouldn't be protected. So I may consider adjusting the behaviour after the buy order is filled to place two stop orders (scale out and remaining amount), then cancel the order for the scale out amount if the target is hit.

from binance-oco.

crlsnr avatar crlsnr commented on September 24, 2024

Thank you for clarifying. This seems like a much more risky approach. If a coin's price drops quickly past the stop loss only the pre-set, non-scale out quantity order has a solid chance to get filled. If a stop sell order is only created after the stop loss is hit for the scale-out amount the likelihood of that order getting filled is very low if the price is already below that amount.

binance-oco -p BNBBTC -a 3 -b 0.005 -s 0.003 -t 0.008 -S 2

In this example:

  • Assume buy order is filled (QTY 3)
  • Target sell order is created for QTY 2 @ 0.008 and Stop sell order is created for QTY 1 @ 0.003
  • Assume price drops past 0.003 to 0.002 in a quick candle
  • Stop-limit order of QTY 1 @ 0.003 fills because it was already in the order book
  • Also at 0.003 the script canceled the target sell order (QTY 2) and a new stop limit order was set at 0.003 for QTY 2
  • Since the price was already below that at 0.002 with the new stop was created the price would have to actually come up for that order to be filled so the scale-out amount (QTY 2) is in reality unprotected primarily due to timing in the order book.

What do you think about this approach?

binance-oco -p BNBBTC -a 3 -b 0.005 -s 0.003 -t 0.008 -S 2

  • Buy order is filled
  • A stop-limit order is created at 0.003 for QTY 3 (full position)
  • If:
    • Price drops to 0.003 the stop order is filled and trade is exited
  • Else:
    • Price hits target at 0.008
    • Initial stop-limit order at 0.003 is cancelled
    • Sell limit order is set at 0.008 for QTY 2 (scale-out amount)
    • Stop limit order is created at original stop-loss for QTY 1

Sorry if I'm misunderstanding.

from binance-oco.

tony-ho avatar tony-ho commented on September 24, 2024

Your suggested approach is how it behaved previously.

The intention is to simplify the previous logic to remove having to:

  • manage sell orders for different amounts (scale out amount at target price and full or remainder amount at stop price). Instead, a stop is left in place for the non scaled out amount and only the scale out amount is managed.
  • cancel a stop order for the full amount and place a new one for the non scaled out amount. Instead, both the stop and target orders (ie. the OCO position) use the same scale out amount.

Using your example it would look like this:

binance-oco -p BNBBTC -a 3 -b 0.005 -s 0.003 -t 0.008 -S 2

  • Buy order is filled
  • Stop order is placed at 0.003 for 2 BNB (scale out amount)
  • Stop order is placed at 0.003 for 1 BNB (remaining amount)
  • If price drops to 0.003, both stop orders are filled and trade is exited
  • If price reaches 0.008:
    • First stop order at 0.003 for 2 BNB (scale out amount) is cancelled
    • Target sell order is placed at 0.008 for 2 BNB
    • Second stop order for 1 BNB remains in place

This approach would remove the risk of stop orders not being filled as the two stop orders would cover the whole position, yet retain the simplified order management.

Does this make sense?

from binance-oco.

crlsnr avatar crlsnr commented on September 24, 2024

Yes this approach makes a lot of sense. Changing the timing of the scale out stop loss order protects the whole trade.

On another topic, I have noticed that my trades almost always fail if my target is hit with a wick because of the same order book problem we discussed with the stop-loss. The order just never gets filled.

For example, I had a trade the other day on LSKBTC with a target of .0004247. The price hit 0.004249 in a wick so the script appropriately set the sell order at 0.0004247, but it never got filled since the price dropped back quickly. I'm not sure how to fix this other than setting lower targets for a better chance of them being filled. Thoughts?

Thanks again for creating this and for being willing to collaborate on it.

from binance-oco.

tony-ho avatar tony-ho commented on September 24, 2024

@crlsnr The scale out logic has been updated as discussed in v2.1.0.

Regarding fills on the target order, lowering the target limit seems to be the best option to increase the chance of being filled in that situation.

from binance-oco.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.