MQL4 Learning - page 44

 

MA Signals

Dave137:
I need your help! How do I read the color change in this indicator for my ea?? The buffers seem to only describe how to create the candle and wick. The condition to change the color is in the indicator (Highlighted with arrows - //<<<< - in the program coding), but no values seem to be connected to the buffers (I do not believe).

Can somebody modify this indicator so that a buffer or 2 buffers will indicate a value change that I can sense in my ea I am trying to create. Please help me if you can - Thanks!

Dave

Indicator attached! Very frustrating. I can create ea's, but indicators still puzzle me at times.

Take these 2 lines of code

double MA_1 (int i = 0){return(iMA(NULL,0,MA1,MA1_SHIFT,MA1_MODE, MA1_PRICE,i));}

double MA_2 (int i = 0){return(iMA(NULL,0,MA2,MA2_SHIFT,MA2_MODE, MA2_PRICE,i));}

and these conditions

if(Ma1 > Ma2) SetCandleColor(1,i);

else if(Ma1 < Ma2) SetCandleColor(2,i);

and rewrite them into your EA with the same inputs from the candle indicator and either paste in the MA extern functions from the candle indicator or hard code them straight into these lines of code.

double Ma1 = iMA(NULL,0,MA1,MA1_SHIFT,MA1_MODE, MA1_PRICE,0);

double Ma2 = iMA(NULL,0,MA2,MA2_SHIFT,MA2_MODE, MA2_PRICE,0);

if(Ma1 > Ma2) BUY

if(Ma1 < Ma2) SELL

 
whateveryouwant:
Yes I havd live trading enabled and allows DLL calls etc as required for all EA's to trade live. That is why I stated that that section is set up correctly.

However my EA runs in the tester and is very good, but I must be missing some function call; that enables trading that has nothing to do with the EA setup from Metatrader interface.

Is there any Function call in the code preamble necessary to enable live trading?

It is really weird... it works in the tester but not in Live trading and yes I have a smiley face.

If you don't have error messages in "journal" and "expert" tabs, then all indicators/files called by the EA are loaded correctly and nothing is wrong.

FerruFx

 
cja:
Take these 2 lines of code

double MA_1 (int i = 0){return(iMA(NULL,0,MA1,MA1_SHIFT,MA1_MODE, MA1_PRICE,i));}

double MA_2 (int i = 0){return(iMA(NULL,0,MA2,MA2_SHIFT,MA2_MODE, MA2_PRICE,i));}

and these conditions

if(Ma1 > Ma2) SetCandleColor(1,i);

else if(Ma1 < Ma2) SetCandleColor(2,i);

and rewrite them into your EA with the same inputs from the candle indicator and either paste in the MA extern functions from the candle indicator or hard code them straight into these lines of code.

double Ma1 = iMA(NULL,0,MA1,MA1_SHIFT,MA1_MODE, MA1_PRICE,0);

double Ma2 = iMA(NULL,0,MA2,MA2_SHIFT,MA2_MODE, MA2_PRICE,0);

if(Ma1 > Ma2) BUY

if(Ma1 < Ma2) SELL

Thank you ever so kindly! You made my week!!

 

Is there anyway to stop trading for a certain amount of time after a trade has been closed?

 
Files:
1_2.jpg  96 kb
 

REQUEST: OP on Multiple Currencies Code

Friends,

I have been learning to code MQL4 on the past few weeks, it's not easy I thought, but it's really worth to try ( hopefully will paid off soon )

Right now, I am stuck on coding for openning position of multiple currencies, since sendorder() function only knows symbol() for the running chart.

Please someone give me some sample on how to code that subject.

The Idea of my EA is to open position of several pairs on particular time ( ie. EURUSD, USDJPY at 4AM ).

Thanks before.

 
ichanz:
Friends,

I have been learning to code MQL4 on the past few weeks, it's not easy I thought, but it's really worth to try ( hopefully will paid off soon )

Right now, I am stuck on coding for openning position of multiple currencies, since sendorder() function only knows symbol() for the running chart.

Please someone give me some sample on how to code that subject.

The Idea of my EA is to open position of several pairs on particular time ( ie. EURUSD, USDJPY at 4AM ).

Thanks before.

If you need open a position for a pair which is different than the chart you attach the EA, the Symbol() function must be replaced by the pairs you need (ie "EURUSD" "EURJPY" ... etc).

Dont forget to add the "m" or whatever is after the pair name if your broker add.

FerruFx

 

How do I know I a new bar added

Hi ,

How could I calculate if some new bar added to my chart in any timeframe?

Thank you very much.

 

This function will do the trick...

bool NewBar() {

static datetime LastTime = 0;

if (Time[0] != LastTime) {

LastTime = Time[0];

return (true);

} else

return (false);

}

Lux

 

Thank you very very much!

Reason: