Coding help - page 350

 
apprentice coder:
How can I test from the code if the connection to the broker is on or off?

You can use the IsConnected() function for that, but ...

That function will never be reached if there are no new ticks coming in.

So, you have to keep it in either an endless loop (which is unacceptable for an EA) or you have to use timer events to check that (in which case, if it is an EA, it could warn you that there is no connection. I assume that we all consider indicators as less connection critical - no operations with orders and so on - so the timer solution can be applied to indicators too, but are probably less important to check from there than from EA) . Otherwise your code will not know that the connection has been lost

 
mladen:
You can use the IsConnected() function for that, but ...

That function will never be reached if there are no new ticks coming in.

So, you have to keep it in either an endless loop (which is unacceptable for an EA) or you have to use timer events to check that (in which case, if it is an EA, it could warn you that there is no connection. I assume that we all consider indicators as less connection critical - no operations with orders and so on - so the timer solution can be applied to indicators too, but are probably less important to check from there than from EA) . Otherwise your code will not know that the connection has been lost

can you post some code example that would do that, please?

 
apprentice coder:
can you post some code example that would do that, please?

Will post an example tomorrow. OK?

 
mladen:
Will post an example tomorrow. OK?

OK. Lets take some rest

 
apprentice coder:
can you post some code example that would do that, please?

apprentice coder

Here is a simple indicator (but the way how it is used, you can do it exactly the same in the EA) that checks the broker connection status at a desired time interval : _check_connection.mq4

#property indicator_chart_window

extern int CheckStatusEveryNMilliseconds = 250;

int init() { EventSetMillisecondTimer(CheckStatusEveryNMilliseconds); return(0); }

int deinit() { EventKillTimer(); return(0); }

int start() { return(0); }

void OnTimer()

{

static bool previouslyConnected = true;

bool currentlyConnected = IsConnected();

if (previouslyConnected != currentlyConnected)

{

previouslyConnected = currentlyConnected;

string cdescription = "disconnected"; if (currentlyConnected) cdescription = "connected";

Comment("connection status changed.\nterminal is now : "+cdescription);

}

As you can see, it is a simple example how it can be done

Files:
 
mladen:
apprentice coder

Here is a simple indicator (but the way how it is used, you can do it exactly the same in the EA) that checks the broker connection status at a desired time interval : _check_connection.mq4

#property indicator_chart_window

extern int CheckStatusEveryNMilliseconds = 250;

int init() { EventSetMillisecondTimer(CheckStatusEveryNMilliseconds); return(0); }

int deinit() { EventKillTimer(); return(0); }

int start() { return(0); }

void OnTimer()

{

static bool previouslyConnected = true;

bool currentlyConnected = IsConnected();

if (previouslyConnected != currentlyConnected)

{

previouslyConnected = currentlyConnected;

string cdescription = "disconnected"; if (currentlyConnected) cdescription = "connected";

Comment("connection status changed.\nterminal is now : "+cdescription);

}

As you can see, it is a simple example how it can be done

thanks :0

I see it work even today (without ticks). interesting. learning, learning

 
mladen:
Change the name of either the fxpreislevelsv5.ex4 or fxpreislevelsv5.dll (metatrader does not recognize extensions in this case - you have to have different name of the file regardless of the extension)

Thanks for the help!!!

But i ran into a diffrent problem after compiling there were no errors but it doesn't run and keeps on removing

"2014.09.20 19:56:40.262 Custom indicator Trend_Imperator_V2e GBPUSDe,M5: removed

2014.09.20 19:56:38.901 Custom indicator Trend_Imperator_V2e GBPUSDe,M5: loaded successfully"

always happens do i have to update codes?

 
forexeaexpert:
Thanks for the help!!!

But i ran into a diffrent problem after compiling there were no errors but it doesn't run and keeps on removing

"2014.09.20 19:56:40.262 Custom indicator Trend_Imperator_V2e GBPUSDe,M5: removed

2014.09.20 19:56:38.901 Custom indicator Trend_Imperator_V2e GBPUSDe,M5: loaded successfully"

always happens do i have to update codes?

forexeaexpert

That error usually happens when the indicator is called with wrong parameters

Check the parameters in the iCustom() call to that indicator

 

Hello mladen ,

I was trying to insert this indicator to my ea .

But after testing it was only getting a buy signal .

Please help me to see is that a right code i insert

MACD = iCustom(NULL,0,"MACD_ColorHist_Alert_EMA 2",FastEMA,SlowEMA,SignalEMA,true,true,true,false,false,false,false,false,false,false,false,0);

And i know macd>0 and macd<0 is the signal crossing zero line .

But how can i get another signal from the slope direction ?

I was very confuse , after trying so many time

 
stevenpun:
Hello mladen ,

I was trying to insert this indicator to my ea .

But after testing it was only getting a buy signal .

Please help me to see is that a right code i insert

MACD = iCustom(NULL,0,"MACD_ColorHist_Alert_EMA 2",FastEMA,SlowEMA,SignalEMA,true,true,true,false,false,false,false,false,false,false,false,0);

And i know macd>0 and macd<0 is the signal crossing zero line .

But how can i get another signal from the slope direction ?

I was very confuse , after trying so many time

stevenpun

For that it would be the easiest to add some "slope direction" buffer to that indicator or to use some other MACD that already has that slope solved in a buffer

Reason: