I created a NT8 Strategy. I have added code to calculate the position size based upon not risking more than a percent of the account balance. This code is focused on the Forex market.
For example, let us says that I only want to risk 1% on a trade. It finds the amount of pips risked between the trade open and the stoploss. Then, with the value per pip, calculates what the position size needs to be to make sure that the stoploss being hit will only be 1% of the account balance.
In Forex, the problem comes when USD is not included as either the base nor the quote in the pair. So the code works just fine with EURUSD or USDCAD. But it has problems when the backtest is done on GBPCAD, for example. It has some trades that are in the 10's or 100's of thousands dollars profit.
In the attached, you can see two code excerpts showing how it calls upon the USD quote pair. Also, the other screenshots show the crazy amounts of money that profited on within 1 bar by hitting the stop loss. Obviously, there is something wrong. I would like to hire you to figure out what is wrong and fix it. I understand there is a more efficient way to write the code, but please, I ask that you work with what is in place. I am going to streamline the code, once I have it working and backtested properly. Let me know if any questions.