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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Initial capital
InitialCapital=100000000
CumulativeProfit=StrategyProfit+InitialCapital
// Calculate the number of shares (lots) to buy
LotsToBuy=FLOOR(CumulativeProfit/Close)
// Execute Buy Trade
IFClose>Close[1]THEN
IFNOTOnMarketTHEN
BUYLotsToBuyLOTSATMARKET
ENDIF
ENDIF
// Execute Sale Trade
IFClose<Close[3]THEN// SellCondition1 AND SellCondition2 OR SellCondition4
IFOnMarketTHEN
SELLATMARKET
ENDIF
ENDIF
It would be highly appreciated if you could let me know how to fix the code.
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?
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue