Alex, I have used Cum() extensively in a similar manner to your example without any problems whatsoever.
I used it for *manually* calculating ProfitFactor outside of the Backtester, so I will discuss it in that context. I calculate PF using the Wins/Losses * Ave%Won/Ave%Loss compared to the AA metrics which uses gross profit/gross loss method (large sample tests show they are near enough the same for my purposes - allowing for IEEEEEEEEEEEEEEEE standard float roundoff stuff :-) For my approach I calculate PF on a bar by bar basis for any chosen symbol/index. It could be used as a benchmark metric (a trading system PF would have to beat the index *bar by bar* PF?) I have posted a very temporary file in the root of the group files section with screenshots: ProfitFactor.doc The first shot uses a small database for ease of counting etc. The second shot shows that cum() holds up over larger datasets (the database contains 614 bars and the example shot shows that cum correctly totalled 330/284 = = 1.16197. I haven't given a screenshot of the last code in use but I am confident it is correct. Cum is a progressive total - it is normal to increase left to right. If you are only interested in the final number for your range then my guess is you could use explore>with a lastvalue() column or select n = = 1 in AA window before runnning an exploration. I don't understand how backtest got into your example except that, making another guess, your buyprice-sellprice must be resetting each push of the backtest button. I would say that you are just not fully understanding what is going on there yet. The topguns would do that type of thing in the custom backtester. I have done it in explorer by coding and cumulating raw descriptions of the buy signal etc (no backtester involved). There are quite a few hours in that *from the ground up* approach. BrianB2. --- In [email protected], "dralexchambers" <[EMAIL PROTECTED]> wrote: > > I am using the Cum() function - in the code below - to calculate the > number of trades that make a profit and a loss in a backtest. > > I am finding that the values outputted for total trades won and lost > are being affected by the position of the chart being displayed that > contains the backtest AFL. > > To get the correct profit and loss values, I have to scroll the price > chart to the end of the data and hit "Backtest". If I move the data > back in time (ie. scroll the chart to the left), the values below > change. > > It appears to be the Cum() function that is affected. I thought that > the "SetBarsRequired" code should eliminate this problem, but it > doesn't. > > Can anyone advise, > Most grateful > > ==================================== > SetBarsRequired(10000,10000); > > rwdaL = IIf(Sell,(SellPrice-ValueWhen(Buy,BuyPrice)),0); > > profitL = IIf(rwdaL>0,rwdaL,0); > LossesL = IIf(rwdaL<0,rwdaL,0); > > fh = fopen("D:\AdvancedTradeOutput.html", "w"); > > f = Cum(ProfitL); > g = Cum(LossesL); > > fputs("Profit / Loss = "+(f/g), fh); > fclose(fh); > ==================================== >
