Hi,
I just installed Zorro, read the manual, and trying to set up a first bot, for short-term scalping, frequent trades.
I am trading on Binance, spot, and there are a few pairs there that presently have zero trading fees for the market makers, but the usual fees for market takers. So I am trying to write the bot in such a way that I can be sure it's using solely (or as much as possible) limit orders on broker side, because those are free, and with bigger sums and more frequent trades with small price differences, they would be my primary loss source.
Binance plugin reports support for limit orders ( here:
https://zorro-project.com/manual/en/binance.htm ):
The API supports market orders and limit orders.
and
SET_ORDERTYPE (types 0,1,2; limit orders only)
so I presumably can use limit orders on broker side.
Online manual says ( here:
https://zorro-project.com/manual/en/stop.htm ):
Use a limit order at the given limit price, instead of a market order, for subsequent trades in live trading. Has only an effect if supported by the broker API; has no effect in training or backtests. OrderLimit is different to an Entry limit because it is handled on the broker's side (see remarks) and is - if supported by the API - also valid for exits. If not sent in GTC mode, the order is automatically cancelled if not filled within the wait time set for the broker API.
The price limit is directly used for the order and thus must be an ask price for enterLong and a bid price (ask minus Spread) for enterShort. For a combo order it must be the sum of the ask and bid limits of all legs. The script must round the limit to an integer number of pips if required by the broker API. Unlike normal orders, not filling a limit order does not produce a "Can't open trade" error message in the log. For avoiding that it affects subsequent entries and exits, set OrderLimit back to 0 after entering. A tick or tmf function can be used to resend orders with different OrderLimit values for catching the best price within a certain time period.
Great, so it should be enough to set this limit before entryLong() and exitLong() and clear it immediately thereafter.
So, this would resolve entering trades... if a trade is missed because it starts with a missed limit order, so be it.
But the trade exits on its own, when exit, TakeProfit or Stop conditions are met, and I am not there to make sure OrderLimit is set before call and reset after it.
So I have to make sure I conrol it more precisely.
I hope it could work something like this: I can use a TMF for every trade, still make use of Stop and TakeProfit price calculations, and when I get informed, through Trade variables that an Exit, a Stop or TakeProfit is about to happen, I can instead set OrderLimit, exitLong(), reset OrderLimit, and return 4 from TMF to prevent Zorro from exiting trade by itself. This way I can use exitLong() directly, and so I can put OrderLimit around it.
So here we get to my conundrum: how do exit* functions work, precisely?
In here (
https://zorro-project.com/manual/en/selllong.htm ), it says that exits:
Exits all long or all short trades that match the given filter condition (see below), at market or at a given price limit, until the given number of lots is closed.
and (in case of exitTrade)
Exits a particular trade completely or partially at market or at a given price limit. Returns 0 when the order failed, otherwise nonzero.
and furthermore, that:
Long trades exit at the best bid price, short trades at the best ask price from the order book or the historical data. The real exit price in live trading can differ from the current ask or bid price due to slippage.
So, how does the Price function argument works in exit* functions? It seems that it should allow exiting at market price or at given price limit - but what should I set in it for it to do one of the other?
First, let's see what I can understand of it in the base case, when I don't use OrderLimit with it.
Apparently exitTrade() "Returns 0 when the order failed, otherwise nonzero.", so that would imply that Zorro uses market orders on broker side and calculates everything internally, because with limit orders on broker side, it's not yet known whether the trade failed or not when function returns. Unless the function stalls until the limit order gets filled, or cancelled - but that's quite unlikely in time-critical code. Or maybe it only return 0 if the trade failed immeditaely, and now when it's just pending.
But if it allows exiting at some other price, which I can give it through the Price argument, then it either uses limit order on the broker side, or just marks the trade as pending exit and will exit it through market order when the price reaches it... but then, that might not be immediate either! Or maybe it posts a limit order on the broker side, with post-only flag set? If the broker allows it? I think Binance doesn't.
So I already can't figure out what it's doing without OrderLimit around it. And with OrderLimit around it, what will happen? It does seem that it's using limit order on broker side then, because of this bit (here:
https://zorro-project.com/manual/en/trade.htm ) :
TradeIsMissed
Is true when the enter or exit order was unsuccessful due to an OrderLimit.
So if the price passes the broker's limit order already, I could learn of that at the next TMF call.
But how quickly is it called again? Or maybe I should stay inside the TMF, and continually poll that state of this variable?
Then I could cancel it (but it's not a trade, how do I cancel a trade exiting limit order?) and issue another limit order at an updated price level, hoping to catch it again.
But this entire reasoning relies greatly on all the quoted texts, from various places in the online manual, some of them likely years old. If any of these is wrong, or simply outdated and no longer true, I am wrong as well.
Of course I can't test it on backtesting, and Binance doesn't have a demo for spot trading. So I could put in some money, set up a bot, go on Binance and proceed to lose money, reading Binance's log to see whether each trade was a Maker or a Taker to them. I would then form some ides of how it works internally - but I could never be 100% sure.
Is it possible to make this aspect of Zorro more clear in the manual? Or in this thread? At least what kind of order Zorro would send on exit* (with and without OrderLimit), on TakeProfit and Stop? (does it just call exit there, is it even possible to enforce these to be limit orders without working around them completely) What happens when it exited through limit order in TMF and that limit order was missed, how to make sure it exits again at the next price level, and when will TMF be called next? (probably on next tick, so I guess I could monitor if the order got filled or not) And how to cancel a missed exit limit order (as it has no TradeID available)?
Thank you.