Backtest on Contract orders works, but not with full equity
Forums › ProRealTime English forum › ProOrder support › Backtest on Contract orders works, but not with full equity
- This topic has 9 replies, 3 voices, and was last updated 5 years ago by
swedshare.
-
-
04/28/2020 at 12:43 PM #128610
This might seem a simple question, though it has been bothering me for a while now.
Sometimes, I cannot backtest a strategy for which I’m using full equity instead of a fixed amount of contracts.
First of all, I define the equity and the capital like this:
12capital = 10equity = capital + StrategyProfitAnd to enter/exit positions I write the following:
1234567891011121314151617181920//Entries// Conditions to enter long positionsIF NOT LongOnMarket AND long THENBUY equity CASH AT MARKETENDIF// Conditions to exit long positionsIf LongOnMarket AND closelong THENSELL AT MARKETENDIF// Conditions to enter short positionsIF NOT ShortOnMarket AND short THENSELLSHORT equity CASH AT MARKETENDIF// Conditions to exit short positionsIF ShortOnMarket AND closeshort THENEXITSHORT AT MARKETENDIFBacktesting with equity doesn’t seem to work when I write this, even though it has worked for me in the past.
Since there is no error in the code of the strategy itself (because when I translate it into contracts it directly works), I figured the mistake must be either in the entries/exits snippet or perhaps a setting in the platform which is causing this.
I’m pretty new to ProRealTime and really enjoy the software, I’d much appreciate your help.
04/28/2020 at 5:59 PM #128710alex12 – Welcome to the forums.
There are some simple rules that everyone using the forums is expected to follow. Your post has broken one or more of these rules.
The forum rules are as follows. I have highlighted in bold the rule/rules that you have not followed:
Post your topic in the correct forum.
ProRealTime Platform Support only platform related issues.
ProOrder only strategy topics.
ProBuilder only indicator topics.
ProScreener only screener topics
General Discussion any other topics.
Welcome New Members for new forum members to introduce themselves.Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.
Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.
Do not double post. Ask your question only once and only in one forum. All double posts will be deleted anyway so posting the same question multiple times will just be wasting your own time and will not get you an answer any quicker. Double posting just creates confusion in the forums.
Be careful when quoting others in your posts. Only use the quote option when you need to highlight a particular bit of text that you are referring to or to highlight that you are replying to a particular member if there are several involved in a conversation. Do not include large amounts of code in your quotes. Just highlight the text you want to quote and then click on ‘Quote’.
Give your topic a meaningful title. Describe your question or your subject in your title. Do not use meaningless titles such as ‘Coding Help Needed’.
Do not include personal information such as email addresses or telephone numbers in your posts. If you would like to contact another forum member directly outside of the forums then contact the forums administrator via ‘Contact Us’ and they will pass your details on to the member that you wish to contact.
Always be polite and courteous to others.
Have fun.I have edited your post where required. Please ensure that your future posts meet these few simple forum rules. 🙂
04/28/2020 at 6:19 PM #128713Hi alex12,
Might I suggest you replace your code with the below and change your buy/sell conditions to say “position” instead of “equity”
12345Capital = 1000 // initial capital of your choiceEquity = Capital + StrategyProfitPosition = Max(1, Equity * (1/Capital))Position = Round(Position*100)Position = Position/100 // lower the number to take larger starting position04/28/2020 at 7:27 PM #128721Thank you for your reply.
I tried substituting my snippet with your code and used then included “position” into the entry conditions instead of equity.
However, I am still getting a flat equity curve and no completed trades (same results I got when using the “equity” definition).
So now my capital section is looking like this:
123456//CapitalCapital = 100 // initial capital of your choiceEquity = Capital + StrategyProfitPosition = Max(1, Equity * (1/Capital))Position = Round(Position*100)Position = Position/100 // lower the number to take larger startingAnd the conditions for entries and exits look like this:
1234567891011121314151617181920//Entries// Conditions to enter long positionsIF NOT LongOnMarket AND long THENBUY Position CASH AT MARKETENDIF// Conditions to exit long positionsIf LongOnMarket AND closelong THENSELL AT MARKETENDIF// Conditions to enter short positionsIF NOT ShortOnMarket AND short THENSELLSHORT Position CASH AT MARKETENDIF// Conditions to exit short positionsIF ShortOnMarket AND closeshort THENEXITSHORT AT MARKETENDIFIs there still something that can be done?
04/28/2020 at 10:26 PM #128739In that case there is something else wrong with your code. If you share the complete code and settings (timeframe and product being traded) we might solve it.
I’m not used to seeing “cash at market”, more common with “contract at market” but maybe it doesn’t matter.
04/30/2020 at 10:10 AM #128961Here is the code of the strategy:
123456789101112131415161718192021//CapitalCapital = 100 // initial capital of your choiceEquity = Capital + StrategyProfitPosition = Max(1, Equity * (1/Capital))Position = Round(Position*100)Position = Position/100 // lower the number to take larger starting//Valuesma = average[20](close)long = close > mashort = close < ma// Conditions to enter long positionsIF NOT LongOnMarket AND long THENBUY Position CASH AT MARKETENDIF// Conditions to enter short positionsIF NOT ShortOnMarket AND short THENSELLSHORT position CASH AT MARKETENDIF(This is the strategy with the “Conditions to close positions” removed since they are not necessary)
By using your snippet or the one I used previously I get the same error. I’m doing this because my goal is to backtest with full equity which grows as profits grow, that is why I don’t want to use the “CONTRACTS” function.
I’m backtesting it on the market BTCUSD, on the 1H chart, for a backtesting period of about one year.
The equity curve I receive when trying this is flat, and no trades are completed. Maybe there is another way to perform a backtest for growing equity?
04/30/2020 at 11:29 AM #12897804/30/2020 at 3:45 PM #129064Great! It seems to work now.
However, is there a way to enter the position, not by the compounded number of contracts but with the cash equity which keeps adding its profits?
Because using the number of contracts that keep adding might not be as precise as the direct equity plus the profits as cash.
Perhaps it’s just because I don’t fully understand the logic behind the code snippet you gave me 🙂
04/30/2020 at 4:09 PM #12907004/30/2020 at 8:20 PM #129127You cannot use 100% of your capital since the broker requires a margin. The code will automatically take a larger position as long as your equity increases (previous trade is a winner). You can also adjust how big the starting position will be, for example using 50% of initial capital. See the attached image how the code takes a larger position.
I would not recommend trading Bitcoin because of the extremly high spread. The only one who will win on that product is the broker.
-
AuthorPosts
Find exclusive trading pro-tools on