There are probably other things that may likely to be wrong too but since your Tradesim formula links to "External Formulas" and postion sizing that are not given, it is guessing game that can't be won without magical mirror.
Hehe, yes, the magic is 1 percent also in Tradesim. In Tradesim it is "Fraction of capital risked pr trade". In Tradesim you have Profits Pyramid(on or off).
From the usermanual for Tradesim:
Pyramid Profits
When this parameter is not checked then we aim to maintain the total trading capital at an amount specified by the Initial Capital parameter. However in the course of trading we may have a situation where we have many losing trades so that the total capital has fallen below the initial capital in which case the total trading capital will be less than the initial capital. If the trading system produces too many losing trades so that the total capital falls below what can reliably be traded then any simulation in progress will abort and a ‘bankrupt’ condition will be reported.
If there are enough profitable trades so that the total capital exceeds the initial capital then the total trading capital will be ‘clamped’ or held at the initial capital and the rest of the trading profits are put aside to be used later when the total trade capital starts to fall due to losing trades.
When this parameter is checked any profits that are returned by profitable trades are added to the total equity and trade capital. The effect of this on the trading strategy will depend on what position size model is used. However it should be noted that a trading system that is profitable without profit compounding should benefit from using profit compounding. How much of an improvement will depend on other factors of course but the position size model used will have the most profound effect. Position size models which size trades according to a proportion of the total trading capital will benefit the most from profit compounding.
Are you a timetraveller?
You are buying a breakout on a specific level at open price while the breakout happens during the following day - but this is future. Therefore you have to know in advance that today there will be eventually a breakout! Same with the sell of your position. This gives a nice backtest, but...
I would suggest one of this possibilities:
If you want to buy at next Open, then the code should be like this:
No. He is buying the breakout but he is also delaying the entry by one bar thus open prices can work. @herbertioz to really understand what is happening wiht your code run a simplified version of a exploration: