Mastering Capital Management in Backtesting (IG Index - ProRealTime)

Rodin17

Newbie
Messages
3
Likes
0
After successfully coding my first set of backtesting programs with the IG Index–supplied “IT Finance Pro Real Time”, I would really appreciate some help from you all regarding the capital management sections and position size management….

I have poured over the Pro Back Test pdf file on the Capital Management section – but I cannot make head nor tail of the parameter definitions, and how to tailor these to model real trading on the IG Index platform.
http://www.prorealtime.com/en/pdf/probacktest.pdf

My coding is designed to work on the forex, risking a defined % of total equity (e.g. 2% per trade) but I guess that the coding can also work on less liquid markets. ;)

My coding determines the number of pips from the trade entry position for the stop loss using a multiple of the average true range indicator.

The problem I have is that ProBackTest should be able to calculate the correct £/pip in order to risk only the 2% per trade, but I cannot grasp the parameter definitions sufficiently to control this. Please see thumbnails below...

Example to highlight the requirement: stop loss = 150 pips away from trade entry… Initial capital position = £20,000… 2% = £400…. £/pip = 400/150 = £2.67/pip

Your help is greatly appreciated, and I would love to post a concise instruction after our exchange for other users.

Rodin17
 

Attachments

  • Broker Fee.JPG
    Broker Fee.JPG
    9.1 KB · Views: 586
  • Risk Mgt.JPG
    Risk Mgt.JPG
    9.1 KB · Views: 541
Hi Rodin17. On another subject but I wondered if you've noticed about IG's advanced charts that the 200 day SMA applied to the daily chart is way off the Prorealtime chart data etc. It's worth checking out & I'd love to know if someone could tell me why!? It's most noticeable on the 200 day SMA applied to the close on the daily chart. Try the GBPUSD say compared to virtually any other data provider.
 
Hi Rodin17,

I am using IG for the last 2-3 years. I am still in the learning phase and were doing some sporadic codining the ProBackTest platform but dropped it a couple of times due to lack of control/understanding and reverted to manual back test.

Just a couple of days ago I had another go and the backtest actually did what I intentet it to do (not fully but in the right direction). Now I am also at the point trying to simulate dynamic position sizing.

I see this post is over a year old and I just came across it searching on this topic.

1) Did you manage to implement a working solution using the ProRealTime platform?
2) Would you be interested in discussing any coding experience?

Many Thanks
wc
 
Hi wc,

Yes, I have managed to work this out, and I've been running my backtested systems live now for a while.

After my experience with the testing, and research on position sizing, when we are trading this aspect is by far more important than the system we use - given of course that our system has a positive expectation of profit.

Position size can optimize our equity leverage in trading, which impacts on our portfolio return more than the difference between two profitable systems X & Y.

For more information, I strongly recommend the 2 recent books from a guy called Ralph Vince on this topic, they are heavy going, but have helped me a lot.

Why is this relevant for your question? Well, when backtesting, in order to compare systems X & Y for success, we must not use dynamic position sizing! We should use a fixed level of $ position risk per trade, and after we have optimised our parameters and chosen our system, we then use dynamic position sizing in our live portfolio to maximise our profits.

So, to save a lot of work in programming your backtesting (which I did and can share in the future with a bit more time) - don't bother - for each trade placed during backtesting, risk say $1000 per position. So for example, if your stop loss is 200 pips from the entry level after spread & slippage assumption, then your $/pip = 1000/200 = $5. This is then the parameter used in the "BUY" or "SELLSHORT" commands in the ProBacktest code.

I hope this has been helpful,

Rodin

P.S. In answer to my own question posted in 2010 I have included below the parameters used in the Cap. Magt. Section of the ProBacktest code:

//----- Capital Management settings --------
//
// By order (for non-futures eg stock, ETFs): Order fee 0.7% ish minimum fee 0

// By lot for futures: Lot fee 5 (= assumed spread divided by 2 i.e. if your bid/ask spread = 10, enter 5 here)

// Deposit by lot 100 & 1 point worth 1

//Risk mgt 2000, 2000, 0 all % capital ie not controlled here but in code
// Reinvest profit, cumulate orders, 1 stop for all orders (however we do not use the code STOP, but have our own)
// Round to the upper non-decimal limit

P.P.S. Countvonaltibar - this works fine on my IG, check that in the IG charts, the price is set to Mid, and in Advanced Charts, check that you have the simple moving average set to "Close".
 
Hi Rodin17,

Thank you very much for your speedy feedback.

This is reassuring, after I had continued to play around with some simulations I came to a similar conclusions.

I have attached my capital management details as used at the moment and appears to fulfill my requirement and expected outcome during simulation. The plan to handle dynamic position sizing with the code algorithm when I get to the point. However at the moment I have noticed there is another fundamental problem I need to solve first.

So In relation to that fundamental problem I have another question, not directly related to the capital management setting, but rather relating to PRT syntax and how PRT is parsing the historical prices for backtest simulations to control buy/sellshort orders and their respective stop loss levels.

I will continue the questions here for convenience at this point.
I understand you are quite experienced with PRT and hopefully you have a answer.
We can also break out this discussion on a private thread if you prefer.

For this question I am using the capital management settings as in the attached screenshot, the daily chart on EUR/USD (the currency pair shouldn't matter).

The question is basically, is it possible to have a entry and exit order on the same candle. To this point I have not managed to to this in a simulation. For certain this is possible in the real world, but how to do this in the simulation using PRT?

I have attached a screenshot of the simulation result I am observing which shows that SL orders (10 pip from entry) are sometimes executed at the correct price and sometimes they are not. My next observations were that all exit orders are executed on the next candle instead of the same candle.

Here the code used:
>>>
//PPT system based on IB and 50 EMEA
//Version 002 Including Stop logic
//Version 003 Including Re-entry Logic
distanceToMA=5
MA=50
Stake=1
TrailingSL=10
ProfitTarget=100

// Boolean definition => Right=1 Wrong=0

// IB
Condition1 = Dhigh(2) >= Dhigh(1)
Condition2 = Dlow(2) <= Dlow(1)

// EMA
Condition3 = ExponentialAverage[MA](Dclose(1))+distanceToMA < ExponentialAverage[MA](Dclose(0))

Condition7 = Dlow(1) > ExponentialAverage[MA](Dclose(0))+distanceToMA
SLPrice=Dhigh(1)-TrailingSL

IF NOT LONGONMARKET THEN
IF Condition1 AND Condition2 AND Condition3 AND Condition7 THEN
IF CLOSE=> Dhigh(1) THEN
// Kauf wenn Preis IB (inside bar) vom vortag richtung trend durchbricht
BUY Stake CASH AT Dhigh(1) LIMIT
// Set stop loss 10 pips über / unter Kaufpreis
SET STOP (SLPrice)

ELSIF CLOSE < Dhigh(1) THEN
// Kauf wenn Preis IB (inside bar) vom vortag richtung trend durchbricht
BUY Stake CASH AT Dhigh(1) STOP
// Set stop loss 10 pips über / unter Kaufpreis
SET STOP (SLPrice)
ENDIF
ENDIF
ENDIF

// PROFIT EXIT
IF LONGONMARKET THEN
SELL Stake CASH AT EntryQuote + ProfitTarget LIMIT
ENDIF
<<<<<<

I also had done some small modifications i.e.
I had changed the following coding line
FROM: SLPrice=Dhigh(1)-TrailingSL

TO:
...
//SLPrice=Dhigh(1)-TrailingSL
SLPrice=ENTRYQUOTE-TrailingSL


RESULT: Stop loss is not executed at all

Daselbe passiert wenn ich SLPrice ganz herausnehmen und die ENTRYQUOTE variable innerhalb der IF abfrage nutze. So Änderung\
The same happens when I take out the SLPrice variable altogether and replace the following code
FROM:
...
SET STOP (SLPrice)
...

TO:
...
SET STOP (ENTRYQUOTE-TrailingSL)


At the moment I am spending quite a lot of time to try all combinations, even use plain sell orders to exit a long, but none with the desired results where entry price and stop price are executed as expected.

If it helps we can also collaborate via voip (Skype etc.) to discuss and share experience.

Many Thanks,
wc
 

Attachments

  • Screen Shot 2012-01-13 at 17.25.12.png
    Screen Shot 2012-01-13 at 17.25.12.png
    37 KB · Views: 785
  • Screen Shot 2012-01-13 at 09.39.09.png
    Screen Shot 2012-01-13 at 09.39.09.png
    31.9 KB · Views: 2,725
Hi folks,

I see you are using the DHigh and DLow in your code so following that just a quick question, on the functions list there is also a "DClose" which is Daily Close, do you know if this applies to 16.30 on the FTSE for example and 21.00 on the S&P or is it the close of play on the chart, I imagine the latter. So my next question would be, can a close of trading price be included in a code ie for a probacktest.

IF close < "close @ 16.30" THEN BUY
 
Hi w_c,

Sorry for the late reply - by know I assume you have discovered for yourself that PRT can only work with the historical candlestick (and not the movement of the prices in between for that particular time scale).

For example if you buy on the open price, and then the low of the candle {for a long trade} hits your stop loss, then you can indeed buy and sell on the same candlestick in PRT. But, if you want to buy when the price rises to a certain level, this could have happened at any point during that candlestick. So in this example, you would not know if in reality the low of the candle occured before, or after your trade was filled.

The joys of backtesting.... we can never replicate live trading unless you use [x] minute data - but then we can't back test to 1970. :confused:

My advice to you would be if using daily data, that you open the position on the day your system triggers; if the low of the day hits your stop loss, then take the cautious assumption that you have been whipsawed, and you are out of the trade on day one.

If your system is shorter term, let's say average winning position of a few days rather than months or years, then try using a 30 minute or 2 hour candle rather than daily.

Hope that you have progressed since the last question, and we would love to hear how you are getting on.

Best regards,

Steve




Hi Rodin17,

Thank you very much for your speedy feedback.

This is reassuring, after I had continued to play around with some simulations I came to a similar conclusions.

I have attached my capital management details as used at the moment and appears to fulfill my requirement and expected outcome during simulation. The plan to handle dynamic position sizing with the code algorithm when I get to the point. However at the moment I have noticed there is another fundamental problem I need to solve first.

So In relation to that fundamental problem I have another question, not directly related to the capital management setting, but rather relating to PRT syntax and how PRT is parsing the historical prices for backtest simulations to control buy/sellshort orders and their respective stop loss levels.

I will continue the questions here for convenience at this point.
I understand you are quite experienced with PRT and hopefully you have a answer.
We can also break out this discussion on a private thread if you prefer.

For this question I am using the capital management settings as in the attached screenshot, the daily chart on EUR/USD (the currency pair shouldn't matter).

The question is basically, is it possible to have a entry and exit order on the same candle. To this point I have not managed to to this in a simulation. For certain this is possible in the real world, but how to do this in the simulation using PRT?

I have attached a screenshot of the simulation result I am observing which shows that SL orders (10 pip from entry) are sometimes executed at the correct price and sometimes they are not. My next observations were that all exit orders are executed on the next candle instead of the same candle.

Here the code used:
>>>
//PPT system based on IB and 50 EMEA
//Version 002 Including Stop logic
//Version 003 Including Re-entry Logic
distanceToMA=5
MA=50
Stake=1
TrailingSL=10
ProfitTarget=100

// Boolean definition => Right=1 Wrong=0

// IB
Condition1 = Dhigh(2) >= Dhigh(1)
Condition2 = Dlow(2) <= Dlow(1)

// EMA
Condition3 = ExponentialAverage[MA](Dclose(1))+distanceToMA < ExponentialAverage[MA](Dclose(0))

Condition7 = Dlow(1) > ExponentialAverage[MA](Dclose(0))+distanceToMA
SLPrice=Dhigh(1)-TrailingSL

IF NOT LONGONMARKET THEN
IF Condition1 AND Condition2 AND Condition3 AND Condition7 THEN
IF CLOSE=> Dhigh(1) THEN
// Kauf wenn Preis IB (inside bar) vom vortag richtung trend durchbricht
BUY Stake CASH AT Dhigh(1) LIMIT
// Set stop loss 10 pips über / unter Kaufpreis
SET STOP (SLPrice)

ELSIF CLOSE < Dhigh(1) THEN
// Kauf wenn Preis IB (inside bar) vom vortag richtung trend durchbricht
BUY Stake CASH AT Dhigh(1) STOP
// Set stop loss 10 pips über / unter Kaufpreis
SET STOP (SLPrice)
ENDIF
ENDIF
ENDIF

// PROFIT EXIT
IF LONGONMARKET THEN
SELL Stake CASH AT EntryQuote + ProfitTarget LIMIT
ENDIF
<<<<<<

I also had done some small modifications i.e.
I had changed the following coding line
FROM: SLPrice=Dhigh(1)-TrailingSL

TO:
...
//SLPrice=Dhigh(1)-TrailingSL
SLPrice=ENTRYQUOTE-TrailingSL


RESULT: Stop loss is not executed at all

Daselbe passiert wenn ich SLPrice ganz herausnehmen und die ENTRYQUOTE variable innerhalb der IF abfrage nutze. So Änderung\
The same happens when I take out the SLPrice variable altogether and replace the following code
FROM:
...
SET STOP (SLPrice)
...

TO:
...
SET STOP (ENTRYQUOTE-TrailingSL)


At the moment I am spending quite a lot of time to try all combinations, even use plain sell orders to exit a long, but none with the desired results where entry price and stop price are executed as expected.

If it helps we can also collaborate via voip (Skype etc.) to discuss and share experience.

Many Thanks,
wc
 
Top