As mentioned by @ab_trader orders are executed on the same bar if you set coc=True in the broker. If not the bar is considered closed and order execution is deferred until the next bar. Two orders issued on the same bar with Market execution policy should be executed also on the same bar (be it the next or the current bar)
The system does a check of submitted orders before accepting them. To avoid for example having 2 consecutive orders which would go over the actual cash reserves on the same bar. If tries to take into account that if a long position is closed cash will be re-injected into the system to let you operate with another buy.
Deactivation of the check can be achieved in the broker with checksubmit=False
Sizers are called internally by buy and sell (close uses the actual existing position) but a Sizer can be subclassed to provide complex functionality.
In that documentation page there are examples of how the modification of _getsizing achieves policies, like for example reversing a position or keeping it long only.
It's not fool proof. Use safediv offers you an option to still use the Stochastic on data which is not probable meant for.
The safediv parameter plays together with safezero which has a default value of 0.0. This is a choice and can be changed by you. Because once you enter in the territory of indetermination, assigning a value to an operation which hasn't got a value means making a compromise.
There isn't documentation as such, given the differences found in different platforms.
Oanda (https://www.oanda.com) was the last integration and was at the same time an effort to try to streamline the interfaces and make it as generic as possible. I would have a look at it.
But being your provider Windows based and with OCX in play I guess you'll have to play with comtypes. Although there are, at least, 2 major COM Windows implementations, you are basically on your own. Visual Chart (https://www.visualchart.com) is also Windows based and uses COM and the following still holds:
win32com (pywin32) launched OutOfMemoryError exceptions because it wouldn't fully understand a type.
Although the type was properly decoded, it was clearly going to be a headache and meant fiddling directly with C++ for any needed modification (the major problem being other people compiling pywin32 from scratch or installing a DLL from a non-trusted source, not to mention the lack of proper support for GCC based compilers under Windows that Python exhibits)
comtypes being pure Python was more up to the task of being a target. It still failed to properly decode complex arrays, so a fork of comptypes was needed for full support.
See the fork: https://github.com/mementum/comtypes
See the pull request (from Apr 9) quietly waiting for integration in the master: https://github.com/enthought/comtypes/pull/104
Hopefully your provider is using simpler types and nothing breaks with the standard distributions.
For implementation, the following pattern was chosen:
Store: is an entity which should be the only one talking to the data/broker provider, be it interfacing with sockets or COM
Both the data feed and the broker rely on calling the store and receiving events from it (yes it has to run in a separate thread) to make the information available to the platform.
The suggestion would be to look at the patterns in the Oanda store and associated broker and feeds.
They are plotted. The problem arises because matplotlib makes assumptions about situations where the difference between the top and bottom of a plot is too small and could lead to problems.
The plot below plots the BuySell observer on a different axis to make it clear: I am here. But cannot be seen with the data. The right axis ticks (Y) show values like 3.5 and the top of the axis (already inside the observer) indicates that everything has to be multiplied by 1000 (3.065e3)
The scale is wrong obviously because it goes from 0 to 3.065
Probably your case too.
An alternate, very simple, approach is to handle the window outside of backtrader. Personally I wrote a (tiny) script (in keyboard maestro, mac only) to just resize the window with a F2 keypress, exactly to the dimensions I prefer. This keeps your code clean and works simple and effective. Just run, and press a key if you want to see a bigger window with the graphical results.
As explained above order importing is not a feature of the the platform.
If you have the data in that format:
there are several approaches:
Make a custom data feed with it containing only 2 fields
trigger (or any other name you wish)
In this case you would add the data feed to the system and could at each moment in time and synchronized with the data read if an order has to be executed or not
Read that input with something like a pandas.read_csv module and during each call to next in the strategy, look for the corresponding datetime index in the dataframe to see if an order has to be executed or not.