@run-out said in Buying and Selling at a fixed, virtual price:

@solo-kirmish Options are restricted to simulate real world conditions, or results are useless. Could you provide an example of what you are looking to accomplish? We may be able to help. Thanks.

I don't think a full example would help much, but it something like this:

if self.dataclose[0] >= self.dataclose[-1]*1.01: buyDecide += 1 buyPrices.append(self.dataclose[-1]*1.01)

So here it would just look whether a candle closed at or higher than 1% over the last. Since my actual(/non-backtest) code would grab the stock at +1% over last close, even when the current candle hasn't closed yet, the real buying price I'd need to register is obviously [lastClose]*1.01

Later, if buy- or sellDecide > 0 because one of the various conditions has been satisfied, it should select the best price out of the appended price-list and commit the action. E.g.:

if buyDecide > 0: price = min(buyPrices) print('registered buy price %.2f' % price) orderSize = cerebro.broker.get_cash() / price * 0.99 self.order = self.buy(size=orderSize, price=price, exectype=bt.Order.Limit)

Yet, this doesn't always work, especially for sell.
I get that the ability to simulate real market is useful, but sometimes you just want to run a dry simulation, so it rather disappoints me to learn that it can't be rigged for a true virtual simulation. What a bummer.

@ab_trader:
I will try the StopLimit shortly, though it sounds like it would just be a patch. I need this to work on large data without a chance of misfiring, so if I can't really trust the result to the t, it will most likely not suffice.

Well, if this really can't work with Backtrader, I might be better of just learning to process my raw Csv vault and going through the candlesticks in some simple looping. I don't actually need the real market simulation that comes attached here, just some results to my code.