MQL4 Learning - page 103

 

How to read MT4 Journal Messages with EA?

Hi,

How do I code my EA to read MT4 Journal Messages and compare the String Generated?

What is the code to detect if the order buy message in the MT4 journal contains the string "opening at 0.00000" or "failed" or "[Off quotes]"?

 

============

Files:
 

How to improve this code

I am trying to code an improved version of the ATR indicator. I want to be able to have the ATR indicator but based only on the candle from 2:00 am to 11:00 am for a period P.

For example: on an hourly chart I want an to find the ATR over 120 periods (+/- 120 hours = 5days) but only with the bars between 2:00 am to 11:00 am during those 120 hours.

If anybody has an idea how to modify the standard ATR code to do what I am trying to do... please answer to this post with you code...

Thanks...

 

Need help for complete my code

Dear Sirs,

I want write a function for my EA that after X continuous loose trades sleep for Y times and next starts.

After new start if we meet again X continuous loose trades sleep for Y times and next starts.

I want do this cycle when meet it.

I am tried and wrote below code:

extern int loose_step=2;

extern double time_sleep=0.03;

double last_ticket=0;

bool time_sleep(){

bool allow_trade=true;

int Trade_Count = 0;

int Idenn;

int loose_total=0;

double Last_order_profits[200];

double order_ticket[200];

datetime Last_Order_time[200];

for(Idenn=OrdersHistoryTotal()-1;Idenn>=0;Idenn--)

{

OrderSelect(Idenn, SELECT_BY_POS, MODE_HISTORY);

if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic_Number )

{

Last_Order_time[Trade_Count]=OrderCloseTime();

Last_order_profits[Trade_Count] = OrderProfit();

order_ticket[Trade_Count]=OrderTicket();

Trade_Count++;

}

}

for(int j=0;j<loose_step;j++)

{

if(Last_order_profits[j]<0 && order_ticket[0]< last_ticket)loose_total++;

if(loose_total==loose_step)last_ticket=order_ticket[0];

}

if(loose_total>=loose_step && TimeCurrent()-Last_Order_time[0]<time_sleep*3600)

{

allow_trade=false;

}

else

{

allow_trade=true;

}

return(allow_trade);

}

anybody can help me?

Thanks.

 

Quick Time[] conversion

Hello, for some reason I can't figure out how to convert the Time[] seconds number (126858000) to display the actual 24hr (Hour+Minute) time.

What is the formula please?

Thanks

 

Please help!

Please help!

An OP_BUYSTOP order has been activated, I want to put an op_sellstop order at the same position, how should I program.( what command could detect an pending order has been activated and price).Thanks.

 

decimal numbers: please suggest reliable round down or perhaps chop

Using normalizedouble on eg: 0.667 to 2 places gives 0.67 and require 0.66

Is there a simple way to always ensure that round down occurs?

Other than writing a function with value and decimal places actuals eg; fred(double d,int digits)

if used 'fred' maybe is like this:

a = fred(0.667,3); and fred does: {return(NormalizeDouble(d-(5.0/MathPow(10,digits+1)),digits));}

Just seems that is an uneducated solving which maths mind could put me right... - can simpler method be done?

thanks

blow seem ok but must be another way

Print("fred(0.667,2) -> ",fred(0.667,2));

Print("fred(0.67,1) -> ",fred(0.67,1));

Print("fred(0.660,2) -> ",fred(0.660,2));

Print("fred(0.661,2) -> ",fred(0.661,2));

Print("fred(0.669,2) -> ",fred(0.669,2));

_test GBPUSD,M5: fred(0.669,2) -> 0.66

_test GBPUSD,M5: fred(0.661,2) -> 0.66

_test GBPUSD,M5: fred(0.660,2) -> 0.66

_test GBPUSD,M5: fred(0.67,1) -> 0.6

_test GBPUSD,M5: fred(0.667,2) -> 0.66

 

From another forum I was given idea which I coded up to produce below:

2010.08.13 20:04:53 _test EURUSD,M15: d = 0.667*100.0; --> d = 66.7

2010.08.13 20:04:53 _test EURUSD,M15: d = MathFloor(d); --> d = 66

2010.08.13 20:04:53 _test EURUSD,M15: d /= 100.0; --> d = 0.66

ie: multiply by 100, MathFloor(result), divide by 100

maybe i make function so can be generic answer by passing 10,100,1000,...

 

ObjectSetText text_color

Hi Guru,

For ObjectSetText, I would like the text_color parameter is retrieved from ObjectGet (...OBJPROP_COLOR) dynamically, is that possible ?

i.e

for (i=0, i < StrCurPairCount, i++)

color getColor = ObjectGet(StrCurPairList, OBJPROP_COLOR);

...

...

ObjectSetText(StrCurPairList, StrCurPairList, 8, "Arial Black", getColor);

}

But it seems not working. How to fix it ?

Regards,

Magix

 
magix826:
Hi Guru,

For ObjectSetText, I would like the text_color parameter is retrieved from ObjectGet (...OBJPROP_COLOR) dynamically, is that possible ?

i.e

for (i=0, i < StrCurPairCount, i++)

color getColor = ObjectGet(StrCurPairList, OBJPROP_COLOR);

...

...

ObjectSetText(StrCurPairList, StrCurPairList, 8, "Arial Black", getColor);

}

But it seems not working. How to fix it ?

Regards,

Magix

Below should work (untested);

I put getColor declaration outside the loop as may cause unecessary overhead if encountered each time loop iterates. (my way, is of course up to you

Notice also your quoted for loop code block has missing {. This would also add to your 'no show' issue...

Your code will change the color attributes but WindowRedraw() is VIP.

ref: editor's help (MQL4 Reference - Window functions - WindowRedraw):

void WindowRedraw( ) Redraws the current chart forcedly. It is normally used after the objects properties have been changed.
color getColor;

for (i=0, i < StrCurPairCount, i++)

{

getColor = ObjectGet(StrCurPairList, OBJPROP_COLOR);

...

...

ObjectSetText(StrCurPairList, StrCurPairList, 8, "Arial Black", getColor);

WindowRedraw();

}

hth !