Help adding indicator as filter and to modify EAs

 

I have two EA's I want to add a filter too and modify.

I can do my best to explain the rules ...

CHART

first lets set up the chart...

5 minute bar chart candlestick

add one exponential moving average period 5 (on close)

add one exponential moving average period 1 (close)

RAW SIGNAL-this is what the 'whatever' EA and 'EMACROSS' EA is/are currently doing. I want to keep this on the TF of chart it's attached to.

if ema1>ema5 buy when CLOSE1 crosses above EAM5

if ema1<ema5 sell when CLOSE1 crosses below EMA5

This is the raw unfiltered signal. Now we will filter the signal to allow or disallow long or short trades.

FILTER-this is the function that needs to be added to the EA's

(The filter rule is not known what works best yet, the test will reveal what it is to be.)

The filter parameter we want to test and explore is as follows...

add AutoCh indicator on the 30 or 1 hour time frame. Make it able to change TF to something other than the chart the EA is attached to. The channel it shows on the 5m TF is too small.

Using the AutoCh indicator establish the support and resistance lines for the channel. Support line is below the current price point, (bottom line) Resistance line is above the current price point. (top line) Allow the tester to choose how many bars to calculate for the indicator to use.

DISALLOW SELL IF..

We want the filter to disallow sell signals (lets say we set the 'variable1' to 20 pips for starters) which are within 20 pips of the support line (bottom of AutoCh indicator) So anywhere within 20 pips above the lower channel line all we will allow to execute are buy long signals. We will filter out all the sell signals within this proximity to the lower AutoCh indicator line.

so..

if Sell signal occurs <= Support line of AutoCh +20 ....disallow sell trades.

DISALLOW BUY IF..

We want the filter to disallow buy signals which are (lets say we set this 'variable2' to 25 pips for starters) which are within 25 pips of the resistance line (top of the AutoCh indicator) So anywhere within 25 pips below the upper channel line all we will allow to execute are the sell short signals. We will filter out all the buy signals within this proximity to the upper AutoCh indicator line.

so..

if Buy signal occurs => Resistance line of AutoCh -25 ...disallow buy trades.

It would be best to have one 'variable1' for the disallow short and another independent 'variable2' for the disallow long. Trading isn't a perfect symmerty. Often what works for long positions doesn't work as well for short positions so that is why I want to have these independently variable rather than both the same.

The exit rules I like best are what is used in the 'whatever' EA. It uses a trailing stop trigger and a trailing stop. My tests show that this is a very good exit strategy. I would like to see this used on the EMACROSS EA.

If the EMACROSS used the same exit strategy that the 'whatever' ea uses it would be alot more profitable. I have seen it take profit when there was alot more movement to gain. Actually I think it has the potential to be the most profitable of the two EA's if it had both the filter upgrade and the exit strategy of the other program.

The 'whatever' EA needs to be able to enter multiple trades at the same time and tell it how many to allow at once.

That's it.

Don't hesitate to ask if you have questions.

 
newdigital:
Which kind of dynamic? We have thread with some indicators here.

channeling mostly...

actually I have one indicator I think would work....I need help adding it...

https://www.mql5.com/en/forum/general

 

where do you put the code in the EA and how do you hook it up so it works? I would really like to understand how to do this.

If you know how to do this...are you too busy to tutor me?

please help if you can

Aaragorn

 
 

flush it down

I've never heard a faster way to lose your money....get a grip kid.............................you're all over the place, you been churning or something....

 

I have done some formulas in Excel spreadsheet and I've been reading the tutorials by coder's guru. Reading that has taught me a little about creating variables and expressions. What is tripping me up right now is the order execution lines which have all the stuff in them to place orders.

Also looking at the indicator code I see that it draws objects which are the lines. But how do you get the EA to use this information for logic purposes instead of to just draw the lines on the chart? I don't see how to hook up the variables or understand which ones are the ones that the EA needs to use from the indicator to use for it's logic to disallow orders. I just am still overwhelmed by some of the lines with so much going on in them. I am trying to see where the variables are created and what they are so I know which ones to use.

The other thing is the placement in the code of where to put the new indicator? should it be called at the first as an included code or something or pasted in some certain part of the code? Where is the right place to put a new indicator in?

 
jonnydenver69:
I've never heard a faster way to lose your money....get a grip kid.............................you're all over the place, you been churning or something....

yes I have been churning mostly because I have not been able to do programming myself to test my ideas and refine them. I am well aware of your opinions about automated trading. I would like to pursue my strategy developments as the results direct without further mockery or insults from you if you can manage that. I have not returned to the thread you are on because you said that I don't deserve to have an opinion there. I would like to deserve to have my own say on my own thread and would ask the same consideration from you here that I give you there.

I still have an interest in the system that is working well for you, I know you say it can't be automated or shouldn't be and you have your passion about that. My goal at present is still to develop an automated system. Among other things I want to learn to code. I am open to trading manually too but it is not my primary focus right now. I havn't made to the paltalk room yet but I havn't forgotten about it. I just have my own priority. I am interested to learn trading. I am open to more than one system, I'm just not finished with this yet just because you are and see no value in it. At very least I can learn something from practicing and learning to code from the effort even if the system itself doesn't become a stellar producer. The merits of the pursuit fit my current priorities for what I want to learn.

I also tried to download the elliot wave from emule to look more at the system you use but the download failed despite being left for a full day to do it. I was told it could take a while but after a full day of waiting for the download to execute I gave up on it. In the mean time I'm learning what I can about coding and trading. If this proves worthless I'll flush it. I believe however that nothing will defeat us like an attitude of contempt prior to investigation. I will therefore investigate before having contempt for anything.

churning yes, all over the place? hardly! I am quite focused on what I am doing.

Thanks for your help.

 

http://www.metatrader.info/node/40

I wonder if I can walk thru this step at a time and get it to work?

 

I see this is where the indicator makes the lines....

//===================================================================================

ObjectCreate("1"+sName,2, 0,Time[p],price_p1,Time[0],price_01);

ObjectCreate("0"+sName,2, 0,Time[p],price_p0,Time[0],price_00);

ObjectCreate("2"+sName,2, 0,Time[p],price_p2,Time[0],price_02);

//-----------------------------------------------------------------

ObjectSet("1"+sName,OBJPROP_COLOR,col);

ObjectSet("0"+sName,OBJPROP_COLOR,col);

ObjectSet("0"+sName,OBJPROP_STYLE,STYLE_DOT);

ObjectSet("2"+sName,OBJPROP_COLOR,col);

//---------------------------------------------

ObjectSet("1"+sName,OBJPROP_TIME1,Time[p]);

ObjectSet("1"+sName,OBJPROP_PRICE1,price_p1);

ObjectSet("1"+sName,OBJPROP_TIME2,Time[0]);

ObjectSet("1"+sName,OBJPROP_PRICE2,price_01);

ObjectSet("0"+sName,OBJPROP_TIME1,Time[p]);

ObjectSet("0"+sName,OBJPROP_PRICE1,price_p0);

ObjectSet("0"+sName,OBJPROP_TIME2,Time[0]);

ObjectSet("0"+sName,OBJPROP_PRICE2,price_00);

ObjectSet("2"+sName,OBJPROP_TIME1,Time[p]);

ObjectSet("2"+sName,OBJPROP_PRICE1,price_p2);

ObjectSet("2"+sName,OBJPROP_TIME2,Time[0]);

ObjectSet("2"+sName,OBJPROP_PRICE2,price_02);

//==================================================================

f=1; p1=p; p0=p; p2=p; fp=0;

//*************************************************************************************

return(0);}

which of these should the EA look at to get the value of the line for it's logic? the lines are arrays right?

 

so if I understand correctly this would be the top line of the channel...

ObjectSet("1"+sName,OBJPROP_TIME1,Time[p]);

ObjectSet("1"+sName,OBJPROP_PRICE1,price_p1);

ObjectSet("1"+sName,OBJPROP_TIME2,Time[0]);

ObjectSet("1"+sName,OBJPROP_PRICE2,price_01);[/PHP]

this is the dotted line in the middle of the channel....

ObjectSet("0"+sName,OBJPROP_TIME1,Time[p]);

ObjectSet("0"+sName,OBJPROP_PRICE1,price_p0);

ObjectSet("0"+sName,OBJPROP_TIME2,Time[0]);

ObjectSet("0"+sName,OBJPROP_PRICE2,price_00);

and this is the bottom line of the channel...

[PHP]ObjectSet("2"+sName,OBJPROP_TIME1,Time[p]);

ObjectSet("2"+sName,OBJPROP_PRICE1,price_p2);

ObjectSet("2"+sName,OBJPROP_TIME2,Time[0]);

ObjectSet("2"+sName,OBJPROP_PRICE2,price_02);

is that correct?

Files:
 

here's the whole indicator for reference...

#property copyright "ANG3110@latchess.com"

//----------------------------------

#property indicator_chart_window

//----------------------------------

extern int Hours=24;

extern color col=SkyBlue;

//------------------

double lr,lr0,lrp;

double sx,sy,sxy,sx2,aa,bb;

int p,sName,fs;

int f,f0,f1;

double dh,dl,dh_1,dl_1,dh_2,dl_2;

int ai_1,ai_2,bi_1,bi_2;

double hai,lai,dhi,dli,dhm,dlm,ha0,hap,la0,lap;

double price_p1,price_p0,price_p2,price_01,price_00,price_02;

int p1,p0,p2,fp;

//*****************************************

int init() {

p=Hours*60/Period();

if (fs==0) {sName=CurTime(); fs=1;}

return(0);}

//*******************************

int deinit() {

ObjectDelete("1"+sName);

ObjectDelete("0"+sName);

ObjectDelete("2"+sName); }

//*******************************

int start() {

int i,n;

//------------------------------------------------------------------------------

if (f==1) {

p1=iBarShift(Symbol(),Period(),ObjectGet("1"+sName,OBJPROP_TIME1));

p0=iBarShift(Symbol(),Period(),ObjectGet("0"+sName,OBJPROP_TIME1));

p2=iBarShift(Symbol(),Period(),ObjectGet("2"+sName,OBJPROP_TIME1));

if (fp==0 && p!=p1) {p=p1; fp=1;}

if (fp==0 && p!=p0) {p=p0; fp=1;}

if (fp==0 && p!=p2) {p=p2; fp=1;}

}

//====================================================

sx=0; sy=0; sxy=0; sx2=0;

for (n=0; n<=p; n++) {sx+=n; sy+=Close[n]; sxy+=n*Close[n]; sx2+=MathPow(n,2);}

aa=(sx*sy-(p+1)*sxy)/(MathPow(sx,2)-(p+1)*sx2); bb=(sy-aa*sx)/(p+1);

//----------------------------------------------------

for (i=0; i<=p; i++) {

lr=bb+aa*i;

dh=High-lr; dl=Low-lr;

//----------------------------------------------------

if (i<p/2) {if (i==0) {dh_1=0.0; dl_1=0.0; ai_1=i; bi_1=i;}

if (dh>=dh_1) {dh_1=dh; ai_1=i;}

if (dl<=dl_1) {dl_1=dl; bi_1=i;}}

//----------------------------------------------------

if (i>=p/2) {if (i==p/2) {dh_2=0.0; dl_2=0.0; ai_2=i; bi_2=i;}

if (dh>=dh_2) {dh_2=dh; ai_2=i;}

if (dl<=dl_2) {dl_2=dl; bi_2=i;}}}

//-------------------------------------

lr0=bb; lrp=bb+aa*(i+p);

//===================================================

if (MathAbs(ai_1-ai_2)>MathAbs(bi_1-bi_2)) f=1;

if (MathAbs(ai_1-ai_2)<MathAbs(bi_1-bi_2)) f=2;

if (MathAbs(ai_1-ai_2)==MathAbs(bi_1-bi_2)) {if (MathAbs(dh_1-dh_2)=MathAbs(dl_1-dl_2)) f=2;}

//=================================================

if (f==1) {

for (n=0; n<=20; n++) { f1=0;

for (i=0; i<=p; i++) {hai=High[ai_1]*(i-ai_2)/(ai_1-ai_2)+High[ai_2]*(i-ai_1)/(ai_2-ai_1);

if (i==0 || i==p/2) dhm=0.0;

if (High-hai>dhm && i<p/2) {ai_1=i; f1=1;}

if (High-hai>dhm && i>=p/2) {ai_2=i; f1=1;} }

if (f==0) break;}

//----------------------------

for (i=0; i<=p; i++) {hai=High[ai_1]*(i-ai_2)/(ai_1-ai_2)+High[ai_2]*(i-ai_1)/(ai_2-ai_1);

dli=Low-hai;

if (i==0) dlm=0.0; if (dli<dlm) dlm=dli;}

ha0=High[ai_1]*(0-ai_2)/(ai_1-ai_2)+High[ai_2]*(0-ai_1)/(ai_2-ai_1);

hap=High[ai_1]*(p-ai_2)/(ai_1-ai_2)+High[ai_2]*(p-ai_1)/(ai_2-ai_1);

//----------------------------

price_p1=hap;

price_p0=hap+dlm/2;

price_p2=hap+dlm;

price_01=ha0;

price_00=ha0+dlm/2;

price_02=ha0+dlm;

}

//=================================================

if (f==2) {

for (n=0; n<=20; n++) { f1=0;

for (i=0; i<=p; i++) {lai=Low*(i-bi_2)/(bi_1-bi_2)+Low*(i-bi_1)/(bi_2-bi_1);

if (i==0 || i==p/2) dlm=0.0;

if (Low-lai<dlm && i<p/2) {bi_1=i; f1=1;}

if (Low-lai=p/2) {bi_2=i; f1=1;}}

if (f==0) break;}

//----------------------------

for (i=0; i<=p; i++) {lai=Low*(i-bi_2)/(bi_1-bi_2)+Low*(i-bi_1)/(bi_2-bi_1);

dhi=High-lai;

if (i==0) dhm=0.0; if (dhi>dhm) dhm=dhi;}

la0=Low*(0-bi_2)/(bi_1-bi_2)+Low*(0-bi_1)/(bi_2-bi_1);

lap=Low*(p-bi_2)/(bi_1-bi_2)+Low*(p-bi_1)/(bi_2-bi_1);

//----------------------------------------------------------------

price_p1=lap;

price_p0=lap+dhm/2;

price_p2=lap+dhm;

price_01=la0;

price_00=la0+dhm/2;

price_02=la0+dhm;

}

//===================================================================================

ObjectCreate("1"+sName,2, 0,Time[p],price_p1,Time[0],price_01);

ObjectCreate("0"+sName,2, 0,Time[p],price_p0,Time[0],price_00);

ObjectCreate("2"+sName,2, 0,Time[p],price_p2,Time[0],price_02);

//-----------------------------------------------------------------

ObjectSet("1"+sName,OBJPROP_COLOR,col);

ObjectSet("0"+sName,OBJPROP_COLOR,col);

ObjectSet("0"+sName,OBJPROP_STYLE,STYLE_DOT);

ObjectSet("2"+sName,OBJPROP_COLOR,col);

//---------------------------------------------

ObjectSet("1"+sName,OBJPROP_TIME1,Time[p]);

ObjectSet("1"+sName,OBJPROP_PRICE1,price_p1);

ObjectSet("1"+sName,OBJPROP_TIME2,Time[0]);

ObjectSet("1"+sName,OBJPROP_PRICE2,price_01);

ObjectSet("0"+sName,OBJPROP_TIME1,Time[p]);

ObjectSet("0"+sName,OBJPROP_PRICE1,price_p0);

ObjectSet("0"+sName,OBJPROP_TIME2,Time[0]);

ObjectSet("0"+sName,OBJPROP_PRICE2,price_00);

ObjectSet("2"+sName,OBJPROP_TIME1,Time[p]);

ObjectSet("2"+sName,OBJPROP_PRICE1,price_p2);

ObjectSet("2"+sName,OBJPROP_TIME2,Time[0]);

ObjectSet("2"+sName,OBJPROP_PRICE2,price_02);

//==================================================================

f=1; p1=p; p0=p; p2=p; fp=0;

//*************************************************************************************

return(0);}

//=====================================================================================
Files:
Reason: