MQL4 Learning - page 123

 

...

If you want to retrieve NonLag ma value from that indicator you have to use buffer 0 - like this :

iCustom(NULL, 0, "NonLagMA_v7_M",0,10,0,0);

buffer 2 is used to draw colors and it will sometimes have values (when the slope is down), and sometimes it will have an EMPTY_VALUE (that 2147483647) when the slope is up. So, use buffer 0, and it will be OK

ravsavs:
Hi,

I am a relatively new programmer in mql4, please excuse my in-experience in this subject. Now while trying to develop an indicator I am stuck at a place when I try to extract value from iCustom(NULL, 0, "NonLagMA_v7_M",0,10,2,0); it gives correct values on some time-frames but 2147483647 on other time frames.

I do not know what is causing it. I assume when it is able to draw a value on the chart it should be able to generate that value and iCustom() should return it.

I searched a lot on the internet but no luck. If somebody has any info/solution to my problem, please reply back. I need help!!!

Thanks in advance.
 

What function or operaator?

Hello all,

I am developing my own EA and learning MQL4 as I go. I have completed about 80% of it but am stumped on one part.

What function or operator would I need to use if I wanted my system to be in a bullish bias (so only consider long positions not short) if it goes above a price of 1.3000 (but not actually open a position like a donchian breakout- just recognises this as an uptrend say), but if it then goes below 1.3000 I want it to still be bullish unless it goes below another price, say 1.2500.

How would I do this? Some guidance is all I need I can research further using MQL4 book. Thanks.

PS-The price figures I gave in my example above were picked out of thin air and the price does change each hour in my strategy, which I have allocated to variables.

 

By the way this is what ive done so far:

bool UpTrend

bool DownTrend

If Ask > 1.3000

{

while(Ask > 1.2500)

UpTrend = TRUE

}

So I want the while function to only initiate if the if command is true. But I dont think this will work because each tick the code gets executed so if price drops below 1.3000 (I still want it to have a bullish stance) it will be false on the if command and not even get to the while function?

 

...

Try something like this :

static bool UpTrend = false;

static bool DownTrend = false;

if (Ask > 1.3000) { UpTrend = true; DownTrend = false; }

if (Ask < 1.2500) { DownTrend = true; UpTrend = false; }

crsnape@btinternet.com:
By the way this is what ive done so far:

bool UpTrend

bool DownTrend

If Ask > 1.3000

{

while(Ask > 1.2500)

UpTrend = TRUE

}

So I want the while function to only initiate if the if command is true. But I dont think this will work because each tick the code gets executed so if price drops below 1.3000 (I still want it to have a bullish stance) it will be false on the if command and not even get to the while function?
 

Thanks mladen.

So if price breaks above 1.3000 it assigns true for UpTrend and false for DownTrend. If it then falls back below 1.3000 (but remains above 1.2500) UpTrend remains true and DownTrend remains false because the static variable saves this in memory? Only when price falls below 1.2500 will the static variable recalculate from the if command, hence DownTrend = true, Uptrend = false. And so it continues. . . Is this right?

 

...

Yes And the same is valid for opposite direction. If it is DownTrend it will not become UpTrend till the Ask does not get > 1.3000

crsnape@btinternet.com:
Thanks mladen. So if price breaks above 1.3000 it assigns true for UpTrend and false for DownTrend. If it then falls back below 1.3000 (but remains above 1.2500) UpTrend remains true and DownTrend remains false because the static variable saves this in memory? Only when price falls below 1.2500 will the static variable recalculate from the if command, hence DownTrend = true, Uptrend = false. And so it continues. . . Is this right?
 

Thats perfect then. Thanks a lot!

Whats the reason to declare the static variables to false to start with? Is this to stop it opening trades incorrectly when its first run? t

Also I've just had a thought, if price went above 1.3000, then went back down under. And then I shut down my MT4 platform with the EA running in real time, then re-opened it say the next day, would the UpTrend and DownTrend be false because price is under 1.3000? It wouldnt re-trigger the UpTrend = true, DownTrend = false until it goes back above 1.3000?

 

...

1. they are set to initial false in order to avoid false signals

2. yes. To avoid that you would have to write an indicator that would be able to historically "reconstruct" states for each and every bar, but in that case you can not work with the Ask price (since metatrader does not keep "historical" values for Ask or Bid)

crsnape@btinternet.com:
Thats perfect then. Thanks a lot!

Whats the reason to declare the static variables to false to start with? Is this to stop it opening trades incorrectly when its first run? t

Also I've just had a thought, if price went above 1.3000, then went back down under. And then I shut down my MT4 platform with the EA running in real time, then re-opened it say the next day, would the UpTrend and DownTrend be false because price is under 1.3000? It wouldnt re-trigger the UpTrend = true, DownTrend = false until it goes back above 1.3000?
 

Hi can you do SendMail with lots of data inputs like this?

if (AllowSendingMails == true)

{

SendMail("MQL4 EA AUTOMATED MAIL - BUY ORDER", "Currency bought: ", Symbol(), "Opened at: ", OrderOpenTime(), "Ticket number: ", ticket, "Open Price: ", OrderOpenPrice(), "Stop loss: ", OrderStopLoss(), "Take profit: ", OrderTakeProfit(), "Lots bought: ", OrderLots(), "Spread paid ", OrderCommission());

}

It says ')' wrong parameters count but I've checked it and their equal. Referred to MQL4 book and it looks right.

 

Hi crsnape,

the "SendMail" function need to follow the proper sintax as follow:

void SendMail(string subject, string some_text)

so you need to create two strings; 1 as subject for the email and 1 as the body of the email.

in example:

String subject = "MQL4 EA AUTOMATED MAIL - BUY ORDER";

String body = StringConcatenate(Symbol(), "Open Price: ", DoubleToString(OrderOpenPrice(), Digits), etc, etc)

if (AllowSendingMails == true)

SendMail(subject, body);

Hope this help

Regards

crsnape@btinternet.com:
Hi can you do SendMail with lots of data inputs like this?

if (AllowSendingMails == true)

{

SendMail("MQL4 EA AUTOMATED MAIL - BUY ORDER", "Currency bought: ", Symbol(), "Opened at: ", OrderOpenTime(), "Ticket number: ", ticket, "Open Price: ", OrderOpenPrice(), "Stop loss: ", OrderStopLoss(), "Take profit: ", OrderTakeProfit(), "Lots bought: ", OrderLots(), "Spread paid ", OrderCommission());

}

It says ')' wrong parameters count but I've checked it and their equal. Referred to MQL4 book and it looks right.
Reason: