Insufficient Capital in Strategy Backtesting when Buying Futures and Forex Asset
Forums › ProRealTime English forum › ProBuilder support › Insufficient Capital in Strategy Backtesting when Buying Futures and Forex Asset
- This topic has 6 replies, 2 voices, and was last updated 1 month ago by
jogtt.
-
-
02/03/2025 at 6:18 PM #243386
I am backtesting a trading strategy with different asset classes. For the time being, it has worked properly with indices and stocks. Nonetheless, when analysing Futures or Forex , the position is opened at the opening price of a candle and then closed at the close price of the very same candle, although the sell conditions are not met.
I believe the error is related to how shares are bought and the leverage that might be involved, as the message I am getting In the ‘Equity Curve’ chart panel is Insufficient capital, but since I am still a beginner, I do not actually know how to go about this . I am using the following code:
1234567891011121314151617181920// Initial capitalInitialCapital = 100000000CumulativeProfit = StrategyProfit + InitialCapital// Calculate the number of shares (lots) to buyLotsToBuy = FLOOR(CumulativeProfit / Close)// Execute Buy TradeIF Close>Close[1] THENIF NOT OnMarket THENBUY LotsToBuy LOTS AT MARKETENDIFENDIF// Execute Sale TradeIF Close<Close[3] THEN // SellCondition1 AND SellCondition2 OR SellCondition4IF OnMarket THENSELL AT MARKETENDIFENDIFIt would be highly appreciated if you could let me know how to fix the code.
Many thanks in advance for your help!
02/03/2025 at 6:44 PM #243395As to your exiting condition, simply append this line to your code, so you can see when it’s TRUE:
1graph (Close<Close[3]) AND OnMarketAs to the Capital, input the value you want as shown in the highlighed box (see the attached pic).
But you should also reduce your InitialCapital, as the larger it is the higher number of assets/lots will be traded, without solving the problem.
02/03/2025 at 7:53 PM #243403Thanks for your reply, robertogozzi.
I have been modifying the code as you suggested, and the sell condition is not triggered, as you can see in the image attached.
Concerning the initial capital, I have tried different values: 100, 1k, 10k, 100k, 1M. Although 1 future contract was worth 35-40USD at the entry time step, the ‘insufficient capital’ issue is not solved…any ideas?
02/03/2025 at 11:53 PM #243418I set InitialCapital = 10000 and 20K+ as the Capital for the backtest.
I tested it on Apple (AAPL), Daily TF, and it seems to be working as expected.
1 user thanked author for this post.
02/04/2025 at 12:15 AM #24342402/04/2025 at 12:26 AM #243426Use a 10K InitialCapital and 100LK+ as Capital to backtest, then replace line 6 by:
1LotsToBuy = max(1,FLOOR(CumulativeProfit / (Close / PipSize)))1 user thanked author for this post.
02/04/2025 at 12:57 AM #243427 -
AuthorPosts
Find exclusive trading pro-tools on