Help - Search - Members - Calendar
Full Version: Backtesting AddOn and P/L Indicator
Visual Trading Systems User Forums > VTTRADER TRADING SYSTEMS > NEW TRADING SYSTEMS POSTINGS
KoGe
.
Visual P/L and backtesting too

A visual chart of P/L would be great and backtesting possibilities too.

Other forum topics already asked for backtesting.

I think its quite easy to create, see screenshot below where 'profit' is shown in additional frame 2.

The following additional code was needed:

{BackTest}
LongKill:= ShortSignal and cum (LongSignal);
{close Long Position if existing}
SumLong:=cum( LongSignal - LongKill);
{resulting Long Positions}

ShortKill:= LongSignal and cum (ShortSignal);
{close Short Position if existing}
SumShort:=cum( ShortSignal-ShortKill);
{resulting Short Positions}

Cashflow:=(ShortSignal+LongKill)*Close-(LongSignal+ShortKill)*(Close+0.0003);
Cash:= cum(Cashflow);
{resulting cash}

Value:=SumLong*Close - SumShort*(Close+0.0003) ;

profit:=(Cash+Value)*100000;

{End of script…}


But perhaps Im wrong cause some answers said 'until now no way for a backtesting indicator'. So if you think there are errors in my code, please let me know.

In a similar way you could create a realtime indicator, which shows the result of a running Trading System starting not in history but with the start of the system itwelf as cms-5857 mentinoned, see following link:

http://forum.vtsystems.com/index.php?s=&sh...=findpost&p=248

If you think its worthwhile, Ill try to post running examples of such trading systems.

Regards,
Konny
davidphily
Hi Konny,

It seems you are the first person in this forum that discovered this function Congratulation! biggrin.gif

Do you mind to post this indicator on this forum? it would be very helpful for me and the rest of us.

Thank you
Dave
KoGe
Thanks Dave,

attached find a working example for the SchaffTrendSystem.

Its just a trial version, as Im still working on final versions.

I should mention: the output works like an indicator, but it needs the signals of a running trading system, so working examples can only be distributed as trading systems.

I think, with this example it should be easy to transfer the idea to other trading systems.

Konny
davidphily
Thanks Konny,

You're the best smile.gif
cskidmore
Hello,

This does look promising. Please continue to post your examples here if you would like. Typically, calculating historical trade profit/loss results is easy IF the system is a stop-reverse, always-in-the-market type of system. However, the difficulty arises when the system is not as simple as that because in VTtrader there is currently not an easy way to ensure that you always end up with signals in the correct order to ensure accuracy of results (ie: always Openbuy>Closebuy>Opensell>Closesell).

This is something that I have discussed at length with the VTtrader project manager and one of the trading system experts. A graceful solution is trying to be found.

Regards,
Chris
PeterFX
Hi Chris

Can you direct me to the KAMA/TEMA/MACD File(s?) for download to VT?

I've got the TEMA, but don't know if the KAMA is added separeately and what is needed to auto trade this system.

PeterFX
cskidmore
Hello,

PeterFX: This topic was created by the forum user KoGe to provide an example of how to create a type or indicator-based backtest example. The system used as an example in this topic is using the Schaff Trend Cycle indicator.

I believe the idea behind this topic is to create code that is "portable" into any trading system to help determine potential profitability (or up-to-date profit/loss results) for a trading system.

Regards,
Chris
KoGe
Thanks Chris,

thats what I have in mind, always automatically seeing a visible chart how the trading system makes my bucks exploding

To mention: exploding if I had traded in past, what a pity I didnt. (So be aware, backtesting is no garantee your money isnt imploding in future.)

Maybe I wasnt clear enough. In fact its not just another trading system but 'portable code' enabeling any trading system to show visually what profit it had produced in past (beginning with the start of the chart).

'Portable code' doesnt mean that its useful for cracks only. When a final version of the code is found, ready versions of the 6 trading systems coming with VT can be written and offered for download.

Only the 'VT_trailing_stop_system' cant produce a profit chart, cause this system doesnt create Trade-Signals. At least in the current version.

Until now the code is working for the whole past (beginning of the chart till latest bar). See example above and in
http://forum.vtsystems.com/index.php?showtopic=704

It would be nice to have the additional possibility not to start with the beginning of the chart but with the beginning of "recommodation mode" to see live how the money piles up/ disappears.

(Live its already now, but it doesnt start with zero cause history is calculated too and to start with beginning of 'recommodaton mode' you probably have to use different signals.)

It would be very kind if somebody had suggestions for improvement.

Regards
Konny
KoGe
outperforming the market?

You know Im joking, dont you?

But perhaps its a good example to see what random can do not to be too proud with ones own fitted backtesting results.

Download and try the attached trading system and with each try random will produce different results.

The purpose of this 'Random'-system is that I promised in
http://forum.vtsystems.com/index.php?showtopic=704
to demonstrate how to display a profit-chart if the trading system is not always in the market.

Have a look into the code and you will see that the attached Random-System contains a working solution you can use with any other trading system.

Enjoy
Konny
Batcheler
QUOTE(cskidmore)
Hello,

PeterFX: This topic was created by the forum user KoGe to provide an example of how to create a type or indicator-based backtest example. The system used as an example in this topic is using the Schaff Trend Cycle indicator.

I believe the idea behind this topic is to create code that is \"portable\" into any trading system to help determine potential profitability (or up-to-date profit/loss results) for a trading system.

Regards,
Chris


where is the latest of this "portable" and how do I install in scripts available? just paste it into bottom part of a script?

please put-up here latest on it and let me know. Latest strategy "complex trading system" looks like good candidate to use this p/l meter.

jerry
cskidmore
Hello,

You can find the archive koge posted containing the 6 trading systems that this the code was added to here:

http://forum.vtsystems.com/index.php?s=&sh...findpost&p=2324

I have not studied the code, but according to the author is is usable in any trading system. You will need to copy and paste the code into the bottom of the trading system and create the appropriate variable outputs for display.

Regards,
Chris
Batcheler
Hi, but I'm afraid, not being experienced at VTTrader code to find such "outputs" and do right thing with code, let alone how at bottom of strategy code to put it......afraid I'll have foul-up followed by much back 'n forth followed by foul-up....etc., etc.!! So Admin sir, sure appreciate a small favor if you could stick said Add-on in "complex trading system" and do the appropriate thing to it to make it go right, know that this can take you no more than couple minutes being as familiar as you are with the coding, then post please the whole new thing with title "Complex Trading System with BackTestPL Add-on". Sure appreciate if you could do that favor, otherwise I'm going to get hopelessly lost. Others will appreciate this overall availed as this looks like VERY good system with great real possibilities! (looking at 10Min EurUsd and MAs=20,40, RSI=50, MACD at defailt) Sorry I impose on you a bit sir, just looking for most expeditious solution being unfamiliar with "outputs" needed and coding juxtapositioning. Thanks again! :-)

Truly,
Jerry B.
dberg
Hello,

Here's the Complex Trading system with the Profit/Loss Indicator built into the script just as you wished. Please download the attached file to your computer and import the trading system into VTtrader. Good luck!

Best Regards,

David Berg

VTtrader features specialist
Batcheler
Thank you quite much...........but it's doing same as KeGo's 6-VT-systems-w/-BackTestP/L display, no such window showing. Am I suppose to do sometrhing special to have it display?

I've become highly interested in Level-Stop-n-Reverse system, but it's doing a sell when it's suppose to buy and vice versa, please elude to me the fix. You might want to note this error to programmers when they need to do updates, in meantime please inform me of the quick fix (sorry I'm not starting on any VT coding education yet, I should) I already have the special BackTest code in one of those "6 VT-system with...." from KeGo, but same occurence here, no such P/L window appearing.

THx.

Jerry
Batcheler
re: Level Stop Reverse system

By the way, I have settings .002 and Manual for Delta, this is VERY (!!) nice per where blue/red arrows are on 5Min, but letting it run over-nite it did a Buy instead of a Sell (would've yielded +93 pips, but instead MINUS 93 pips were "gotten"....ooooo), so things backwards in code. I took brief look at code and it seems OPenthis and OpenThat are on correct ups or downs, so my unfamiliarity with code isn't going to be able to debug, sure appreciate a fix kind Admin sir, THx. :-)

jerry
Bemac
Hey all,

Remember to test all Trading systems posted here on a demo account BEFORE you apply it to a Real Money Account.

Happy Trades to You

Bemac[B]
cskidmore
Hello,

To see the Inspect Window you should click the button in the chart window toolbar directly to the right of the tool selector icon. It looks like a blue zigzag with a red arrow under it - this is the Inspect Window.

Regarding the Stop/reverse system, it is likely that the trading system, while left unattended, perhaps missed a trade execution due to disconnection, requote, or other. The logic in the system is correct for the appropriate buy/sell operations. However, you should become familiar with how the trading systems operate in auto-trade mode in a DEMO account. There's lots a great information in these forums as well for you to read through to understand how they work and what limitations you may face while runninng them.

Regards,
Chris
rsflavell
QUOTE(cskidmore @ Nov 16 2004, 11:52 AM) *

Hello,
This does look promising. Please continue to post your examples here if you would like. Typically, calculating historical trade profit/loss results is easy IF the system is a stop-reverse, always-in-the-market type of system. However, the difficulty arises when the system is not as simple as that because in VTtrader there is currently not an easy way to ensure that you always end up with signals in the correct order to ensure accuracy of results (ie: always Openbuy>Closebuy>Opensell>Closesell).
This is something that I have discussed at length with the VTtrader project manager and one of the trading system experts. A graceful solution is trying to be found.
Regards,
Chris


Here's another approach. The first code example is for an always-in strategy, the second for an in-and-out strategy under limited circumstances. Both require an Input variable set to the spread (e.g., 0.0004) and an Output variable (gain) displayed in its own frame. It's a visual preference of mine to also create an output variable set to 0.0 and display it in the same frame as the gain.
________

pips:=Spread;

t1:=if(short,
(close-ref(close,-(barssince(long))))-pips,
0);
t2:=if(long,
(ref(close,-(barssince(short)))-close)-pips,
0);

{ignore first signal}
t1:=if(barssince(long)>0,t1,0);
t2:=if(barssince(short)>0,t2,0);

gain:=int(cum(t1+t2));
________

This next one will work for an in-and-out trading strategy, but only if it doesn't generate spurious exit signals (*see below).
________

pips:=Spread;

t1:=if(exitlong,
(close-ref(close,-barssince(long)))-pips,
0);
t2:=if(exitshort,
(ref(close,-barssince(short))-close)-pips,
0);

{ignore first exit signal if no previous long or short}
t1:=if(barssince(long)>0,t1,0);
t2:=if(barssince(short)>0,t2,0);

gain:=cum(t1+t2);
________

Note that these code examples display your cumulative P/L position after each trade. The resulting display consists of discreet stairsteps (up or down). The in-between equity gain and/or drawdown on open positions is neither calculated nor displayed.
________

*Having an in-and-out strategy that doesn't generate spurious exit signals requires something like this:

long:=cross(variable1,close);
exitlong:=cross(close,variable1);

short:=cross(close,variable2);
exitshort:=cross(variable2,close);

In the above code examples, an exit signal can't be generated except under conditions that would require a previous long or short signal to have been generated.





This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.