Coding help - page 408

 
airquest:
Well, still... Here are some tests :

- Default settings (no optimization, WriteCSV to True) : Microsoft Excel - BB+CCI-EURUSD-H1-2014.12.18 00h11-SA1.csv

- Optimize set to True, PeriodMin to 20 and PeriodMax to 20 : Microsoft Excel - BB+CCI-EURUSD-H1-2014.12.18 00h13-SA1.csv

The first one gives coherent values (CSV file and screen results match). That's normal, because both comes from the same variables. But in the second one, opti results are multiplied almost by 10 compared to screen results. Though, they should end up in the same results...

Anyway, no hurry, maybe with time I'll find out what's wrong. Thanks for your kind help Mladen.

Hi Airquest,

Thanks for a very interesting alternative to the Strategy Tester...a very creative and talented piece of coding on your part...!

I did play with your indicator a little...

And it looks like you have two different variables for totals...

One for the normal run = TotalTrades...

And one for the Optimization run = totalTrades...

However...your Comments only show your normal run TotalTrades...

Go ahead and add your Optimized...totalTrades...to your Comments and see if that solves the puzzle...

This hopefully may answer your question of why the difference between the screen display...and the spreadsheet totals...

Hope this helps,

Robert

 
cosmiclifeform:
Hi Airquest,

Thanks for a very interesting alternative to the Strategy Tester...a very creative and talented piece of coding on your part...!

I did play with your indicator a little...

And it looks like you have two different variables for totals...

One for the normal run = TotalTrades...

And one for the Optimization run = totalTrades...

However...your Comments only show your normal run TotalTrades...

Go ahead and add your Optimized...totalTrades...to your Comments and see if that solves the puzzle...

This hopefully may answer your question of why the difference between the screen display...and the spreadsheet totals...

Hope this helps,

Robert

Not sure the end up results will be correct. The problem is that by showing the total trades coming from the opti function, you can see if the function is running well or not. Also not sure how to return more than one parameter from the double function (you need to return the balance and win rate also). But the main reason is to see that there is a difference in results and so that something should be wrong in the function...

 

Hi all, I've Just written this custom indicator based on the RSI.

I have an idea to use it in an EA. I need help to write it...

It's a buy only strategy.

Buy on every up signal... Close all on down signal

Ideally the EA would increase the Lot size for each consecutive up signal without a close. (with a maximum of course)

The indicator works by putting an arrow on the chart every time the RSI crosses bellow/above a set level.

arrow_rsi.mq4

Files:
arrow_rsi.mq4  3 kb
 
airquest:
Not sure the end up results will be correct. The problem is that by showing the total trades coming from the opti function, you can see if the function is running well or not. Also not sure how to return more than one parameter from the double function (you need to return the balance and win rate also). But the main reason is to see that there is a difference in results and so that something should be wrong in the function...

airquest

To "return" as much parameters as you need from a function, pass a parameter by reference to a function. Something like this :

double a;

double b;

double c = testFunction(a,b);

double tectFunction(double& _a,double& _b)

{

_a = 1;

_b = 2;

return(_a+_b);

}

after which a and b will be assigned values 1 and 2 by the testFunction (implicitly "returning" 3 values in this example case - I used _a and _b names in the function just to show that they do not have to have same name at all when passed by reference, otherwise no need to do that at all)

 
airquest:
Not sure the end up results will be correct. The problem is that by showing the total trades coming from the opti function, you can see if the function is running well or not. Also not sure how to return more than one parameter from the double function (you need to return the balance and win rate also). But the main reason is to see that there is a difference in results and so that something should be wrong in the function...

Hi Airquest,

From what I see...your indicator seems to be working just fine.

I still think it's a "display values" problem...and not any calculation problem.

Here's what I see happening in the indicator...

Program has 2 options - 1) Normal Run 2) Optimization Run

They are NOT exclusive either/or choices...

When Optimization is NOT selected...the program only does the Normal Run...

When Optimization is selected...the program STILL does the Normal Run...AND...then does the Optimization Run...so it's getting both values...

However...only the values from the Normal Run are displayed in screen Comments...and does not display the Optimization values at all.

Attached is my test showing the screen displayed Optimization values are the same as the spreadsheet values...

This shows me that all your calculations are fine...

Also it looks like it uses the last record in the spreadsheet to get the final Optimization values...

I also recommend running it without other charts/indicators loaded...and use only a few selected values to test at a time.

I have 20+ charts running...and MT4 becomes non-responsive as it does it's calculations for this indicator...

Better to use a clean MT4 setup to run the Optimization tests...

But the good news is...it doesn't lock up my system as I can go do other things while it's crunching numbers and making the report.

In the meantime...as far as I can tell in the screen shots below...your indicator seems to work just fine...

BTW...it's an amazing piece of coding... Thank you so much for sharing it...!

Hope this helps,

Robert

 
cosmiclifeform:
Hi Airquest, From what I see...your indicator seems to be working just fine.

You're welcome, thanks a lot for your words. The idea is indeed to replace the mt4 strategy tester optimization (which I think sucks and is too slow) for backtesting simple strategies. And yes, you need to wait a little for it to load and do the calculation, but from what I've seen it's already faster and more convenient than a regular optimization.

But, I still think there is a problem with the indicator and that it's not working properly. Replacing the screen text by the results coming from the optimization does not show at all if these coming out results are right or wrong. It is like painting a rusted car.

I think the opti function give wrong results. You can see in your screenshot that the results in the CSV give 5'307 trades. That's way off the roof. It depends on how many bars you have in your screen, but it's not possible that the strategy gave 5'307 trades to take. To be sure, you don't need to count the arrows, you can reduce the number of bars to test like I did in this screenshot (I've set it to 100 bars) :

You can see here that, for 100 bars, there are only 10 trades to take, with 4 winners (counting the arrows), while the opti results show 89 trades taken. So, based on a visual backtest, the screen results are right (for the best period that the opti said), while the CSV is wrong. So that shows we should not trust the CSV results, either for counting trades OR for determining which settings are the best.

So I've put the problem in a simpler way. I've made a simple indicator (attached) that shows on screen the results coming out from the Optimization double function and from the Start int function (main calculation). So you don't need to write a CSV to see that both results are different.

Based on this indicator, my (simple) question is : WHY ON EARTH TWO EXACT SAME CALCULATIONS (the one in the Start function and the other in the Optimization double function) GIVE DIFFERENT RESULTS ? If anyone can help me to understand this, that would be awesome, because I really don't get it. As far as I see, the two are exactly the same and should come out with same results. Thanks a lot.

PS : the indicator is still a bit slow and you'll probably have to wait a few seconds for it to show the results. Though, it will play a sound when results come out.

Files:
sa1.png  78 kb
sa3.png  41 kb
 

Hi Airquest,

I tried your "Sample Test" but could not get it to work. I looked at the code and it had over 400 lines deleted...so I left it alone.

I did go back to testing your original code...and I think I'm beginning to see what you are saying about the problem with "too many trades"...

To keep testing simple and quick...I tested using only Bands...and minimized the settings (Bands 10 and Bands 20) to have only two (2) runs to see the results faster.

I also focused on "BarsToCount" since that should seem to relate directly to the number of trades...

While I did not find any answers...I may have some more clues for you...

"BarsToCount"...does not seem to work...

I ran your code with 1 Bar...2 Bars...and 100 Bars Back...

And all had exactly the same results...which should not be...since more bars should equal more trades...and less bars should equal less trades.

I have attached my screen shots of the 3 runs I did...changing only the "BarsToCount"...

Maybe this clue will help you track down the other problems.. Good luck in finding your answers.

Hope this helps,

Robert

 

Finally I managed to make a working version. Now the opti results are correct and correspond to screen results. I just dropped off the double function and put it all into the Start one. So now, you only have one choice between running it in Tester mode (so it will use default settings) or in optimizer mode (which will not plot anything but only write a CSV file). After running an optimization, you can go back to tester mode and check out if the results are correct.

Please let me know if you find any issue, by PM is better, as we don't want to spoil this thread. Guys, thanks a lot for your help. This forum is great, people motivate and help each other (most of the time) and that's the reason why I publish it here. Now let's start backtesting

 
cosmiclifeform:
Hi Airquest,

Robert, thanks for your help. See the version I posted above, it should now work.

PS : To limit the number of bars, you need to turn UseAllBars to False. You probably didn't see it.

Regards.

 

Hi Airquest,

Good job tracking it down and getting it to work...!

I'll look forward to playing with it this week...

Thanks and take care,

Robert