Need Help with Coding an EA with Dynamic Zone RSI

 

Hello! I am currently working on an EA that I built simply with the online EA builder and I'm feeling pretty stuck. The EA will not trade and in backtesting will trade a few days then give this error " Invalid index buffer in iCustom function."

What I'm trying to do is create a simple EA based on the Dynamic Zone RSI indicator that will buy when the middle line is at or below the bottom line and close when the middle line crosses the top line (similar to a standard RSI indicator). It could also open a sell order at or above the top line and close at or below the bottom line.

The main focus of my EA is being able to have adjustable (aka. inputs for) RSI period and RSI bands (part of Dynamic Zone RSI). Also, the EA is able to take profit, stop loss, and have a trailing stop.

One thing I want to figure out later is to have the EA open multiple orders so it's not just one order at a time and also be able to close individual orders when the above conditions are met (an option that can be turned on or off maybe with true/false logic).

Here is a copy of my EA the way it is now. It's almost the exact same as created online but with two added variables "RSIPeriod" and "BandPeriod" which I could have incorporated improperly (knowing me).

Any help would be HIGHLY appreciated and maybe I'm taking the wrong route altogether, thanks!

Files:
 

Check Your Buffers

RDKamikaze:
Hello! I am currently working on an EA that I built simply with the online EA builder and I'm feeling pretty stuck. The EA will not trade and in backtesting will trade a few days then give this error " Invalid index buffer in iCustom function."

What I'm trying to do is create a simple EA based on the Dynamic Zone RSI indicator that will buy when the middle line is at or below the bottom line and close when the middle line crosses the top line (similar to a standard RSI indicator). It could also open a sell order at or above the top line and close at or below the bottom line.

The main focus of my EA is being able to have adjustable (aka. inputs for) RSI period and RSI bands (part of Dynamic Zone RSI). Also, the EA is able to take profit, stop loss, and have a trailing stop.

One thing I want to figure out later is to have the EA open multiple orders so it's not just one order at a time and also be able to close individual orders when the above conditions are met (an option that can be turned on or off maybe with true/false logic).

Here is a copy of my EA the way it is now. It's almost the exact same as created online but with two added variables "RSIPeriod" and "BandPeriod" which I could have incorporated improperly (knowing me).

Any help would be HIGHLY appreciated and maybe I'm taking the wrong route altogether, thanks!

Hi RD,

Check your buffers... Missing the last one...??

double Buy1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double Buy1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 2, Current + 0);

double Sell1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double Sell1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 1, Current + 0);

double CloseBuy1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double CloseBuy1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 1, Current + 0);

double CloseSell1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double CloseSell1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, Current + 0);

For multiple trades...search TSD and Google for Hedge EA's and Grid EA's...there are many good examples you can find and use.

Hope this helps,

Robert

 
cosmiclifeform:
Hi RD,

Check your buffers... Missing the last one...??

double Buy1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double Buy1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 2, Current + 0);

double Sell1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double Sell1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 1, Current + 0);

double CloseBuy1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double CloseBuy1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 1, Current + 0);

double CloseSell1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double CloseSell1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, Current + 0);

For multiple trades...search TSD and Google for Hedge EA's and Grid EA's...there are many good examples you can find and use.

Hope this helps,

Robert

Oh man, those numbers are sneaky!! Thanks for catching my mistake, I fixed it

I would want to fix the last one to have a 2 in it if I want to close sell at the bottom line, correct? Like so:

double Buy1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double Buy1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 2, Current + 0);

double Sell1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double Sell1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 1, Current + 0);

double CloseBuy1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double CloseBuy1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 1, Current + 0);

double CloseSell1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double CloseSell1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 2, Current + 0);

When I fixed it and ran the EA, the problem was solved. However, now it only opens a sell order and won't close until it hits the take profit level. I also noticed that it opens the sell order at the bottom line (which should be the top line) and doesn't close it when it hits the top (should be bottom) line. What am I doing wrong now?

EDIT: I found m problem, I was defining variables again! I changed the top and bottom lines to vars to clean everything a little and now it's working well opening and closing when and where it should be

 

Change The Variable Names - Eliminate The Double Calls

RDKamikaze:
Oh man, those numbers are sneaky!! Thanks for catching my mistake, I fixed it

I would want to fix the last one to have a 2 in it if I want to close sell at the bottom line, correct? Like so:

double Buy1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double Buy1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 2, Current + 0);

double Sell1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double Sell1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 1, Current + 0);

double CloseBuy1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double CloseBuy1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 1, Current + 0);

double CloseSell1_1 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 0, Current + 0);

double CloseSell1_2 = iCustom(NULL, 0, "Dynamic Zone RSI", RSIPeriod, BandPeriod, 2, Current + 0);

When I fixed it and ran the EA, the problem was solved. However, now it only opens a sell order and won't close until it hits the take profit level. I also noticed that it opens the sell order at the bottom line (which should be the top line) and doesn't close it when it hits the top (should be bottom) line. What am I doing wrong now?

EDIT: I found m problem, I was defining variables again! I changed the top and bottom lines to vars to clean everything a little and now it's working well opening and closing when and where it should be

Hi RD,

Glad I could contribute to your AHA experience...! Learning coding is fun.

Now you just created new brain cells and neural connections for the New Year... Good job.

Suggestion on the basic EA template...

If you look at the variables...Buy | Sell | CloseBuy | CloseSell...they actually are duplicates...which means double calls to the indicator...

Buy == CloseSell and Sell==CloseBuy

I find it easier if I actually use the names of the indicator as the variable names. Simplifies knowing how it's trading.. Example:

Instead of Buy1_1 and Buy1_2

DZR1_0 - tells me it's the DZ Rsi Current bar 0...

DZR1_1 - tells me it's now the DZ Rsi Past bar 1

Then the Buy/Sell formula becomes:

Buy = DZR1_0 > DZR1_1

Sell = DZR1_0 < DZR1_1

And reverse for Exits...

Match up the code and make sure you have all your buffers accounted for.

I like the basic EA Builder Template, but it helps me to change the variable names to give me better control in writing my Buy/Sell formulas, to make it easier track how the code is trading, and you also eliminate the double calls to the same iCustom indicator at the same time.

Hope this helps...and keep feeding those brain cells...!

Robert

 

That makes sense, thanks for the heads up to simplify it I already know three languages, it's always fun adding C# to my belt!!

In more recent news, a backtest from Jan 1st to Jan 5th with my optimized settings results in 3.5% DD with a profit of 10% when trading NZDUSD M15

I'm going to forward test these results and if it works well and I keep tuning it over time, I'm for sure sharing it for free!! :D

It still has a couple losses that prevent my gains from being a lot more than they are, do you have any advice on what other indicators/things I could tie it with to predict the market better?

Thanks again for helping feed my brain, it loves the extra knowledge!

EDIT: Random side note, is it possible to optimize more than one run at a time? Ex. optimizing NZDUSD M15 and NZDUSD M30 on the same EA at the same time. I know I can make two installs of MT4 and do it that way (don't forget .srv files, I know) but can I do it on the same MT4 program? That would make optimizing every tick MUCH faster and easier!! Or even different currencies (ex. NZDUSD M15 and EURUSD M15 using same EA) would help too!!

EDIT #2: How do I incorporate a hidden SL and TP? Some people will probably want that in my EA so I might as well include that now so I don't have to worry about it later. Thanks again!! JUST KIDDING, I FOUND HOW ON GOOGLE!!

 

After some playing around with my EA, I gave it the option to go above or below the top/bottom line on a sell or buy, similar to a traditional RSI but now it moves with the dynamic RSI!! Optimization and backtesting provided MUCH more profitable at a LOT less risk, which is very nice

Anyway, that's not why I'm posting. I want to know how to add money management (MM) or max equity at risk or auto-lot sizing or whatever it's called (are those all the same term?). I have read this thread but there are variations on how people do it and the code is driving me insane trying to understand where to put it into my current code!!

Could someone help me with this please? My goal is once this is added to have a parabolic profit (assuming 100% gains which we know is impossible) from the added lots as I make more and more profit. I am trading on various pairs if that affects anything (sometimes the same EA on multiple pairs).

Reason: