How to code? - page 280

 

Certainly problems can occur in real accounts that don't show up in demo or strategy tester, but usually they are not recurring and are infrequent. I have never seen or heard of this one.

From your explanation, I can't determine how many trades are open when the problem occurs. If the error is happening with no trades open, that is a mystery. If it occurs with say 5 trades open, that probably has something to do with the problem.

ERR_TRADE_DISABLED 133 Trade is disabled. All attempts to trade must be stopped.

The documentation for this error would seem to indicate that something is wrong with the way the EA is placing the trade. But since both EAs are using the same OrderSend() logic, I wonder if it has something to do with the fact you have 2 EAs running. Normally any contention issue causes a "Trade Context Busy" (146) and any account problems would cause an "Insufficient Funds" (134) error. It would be worth trying to run only one EA at a time and see if that makes a difference.

 

Avasys

This may sound silly, but you did compile the EA, right?

After compilation, there should be an ex4 file in the Experts folder.

 
michaelB:
This may sound silly, but you did compile the EA, right? After compilation, there should be an ex4 file in the Experts folder.

This is what I need to know too

I pasted mq4 file in experts folder, but when I restarted MT4 it did not create ex4 file in experts folder,

so I need to check the code if it has error

 

How to change color of IndicatorShortName

Dear Sirs,

How can I add in the code my own color for this line

IndicatorShortName(GetTimeFrameStr() + " MACD ("+FastEma+","+SlowEma+","+SignalSMMA+")");

in order to change color of small info that I have in separate window of indicator on the left up corner?

Pucio

 

ANYBODY CAN TELL ME WHAT'S WRONG WITH THIS CODE?

IS THERE ANY ERROR, BECAUSE IT DOES NOT CREATE EX4 FILE WHEN I PASTE MQ4 FILE IN EXPERTS FOLDER

//+------------------------------------------------------------------+

//| simple EA.mq4 |

//| Copyright © 2011, luktom.biz |

//| www.luktom.biz/en |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2011, luktom.biz."

#property link "http://www.luktom.biz"

extern double stopLoss = 300.0;

extern double takeProfit = 500.0;

extern string Begin = "2: 00";

extern string End = "10: 00";

extern double distance = 60;

bool isECN = true;

bool cond = false;

bool cond2 = false;

double low;

double high;

extern double lots = 0.1;

int magic = 1232344524285020;

int slippage = 1;

string comment = "";

int ticket;

int short = 0;

long int = 0;

//+------------------------------------------------------------------+

//| expert initialization function |

//+------------------------------------------------------------------+

int init()

{

//----

//----

(0) return;

}

//+------------------------------------------------------------------+

//| expert deinitialization function |

//+------------------------------------------------------------------+

int deinit ()

{

//----

Print (countOrders (magic, OP_BUY));

//----

(0) return;

}

//+------------------------------------------------------------------+

//| expert start function |

//+------------------------------------------------------------------+

int start()

{

Print (AccountCurrency ());

//----

if (isGoodTime (Begin, End))

{

short = 0;

long = 0;

if (! cond)

{

low = Bid;

high = Ask;

}

cond = true;

if (Bid < low) low = Bid;

if (Ask > high) high = Ask;

}

if ((high-low) * 1000 > distance)

{

cond2 = true;

}

if (! isGoodTime (Begin, End))

{

cond = false;

}

if (! isGoodTime (Begin, End) & & cond2)

{

if (countOrders (magic, OP_SELL) == 0)

{

if (Bid « = (CRL-0.0005) & & short == 0)

{

short + +;

if (isECN == false)

{

OrderSend (Symbol (), OP_SELL, lots, Bid, slippage, sltpValue (Ask + stopLoss * Point, stopLoss), sltpValue (Ask-takeProfit * Point, takeProfit), comment, magic);

}

if (isECN)

{

ticket = OrderSend (Symbol (), OP_SELL, lots, Bid, slippage, 0,0, comment, magic);

OrderSelect (ticket, SELECT_BY_TICKET);

OrderModify (ticket, OrderOpenPrice (), sltpValue (Ask + stopLoss * Point, stopLoss), sltpValue (Bid-takeProfit * Point, takeProfit), 0);

}

}

}

if (countOrders (magic, OP_BUY) == 0)

{

if ((Ask-high) > = 0.005 & & long = = 0)

{

long + +;

if (isECN == false)

{

OrderSend (Symbol (), OP_BUY, lots, Ask, slippage, sltpValue (Ask-stopLoss * Point, stopLoss), sltpValue (Bid + takeProfit * Point, takeProfit), comment, magic);

}

if (isECN)

{

ticket = OrderSend (Symbol (), OP_BUY, lots, Ask, slippage, 0,0, comment, magic);

OrderSelect (ticket, SELECT_BY_TICKET);

OrderModify (ticket, OrderOpenPrice (), sltpValue (Bid-stopLoss * Point, stopLoss), sltpValue (Ask + takeProfit * Point, takeProfit), 0);

}

}

}

}

//----

(0) return;

}

//+------------------------------------------------------------------+

bool isGoodTime (string, string, Begin, End) {

if (TimeCurrent () > Localtime (Begin) & & TimeCurrent < Localtime () (End)) {

return (true);

}

return (false);

}

int countOrders (int, int oMagic oType) {

int count = 0;

for (int i = 0; i < OrdersTotal (); i ++) {

if (OrderSelect (i, SELECT_BY_POS)) {

if (OrderMagicNumber () == oMagic) {

if (OrderSymbol () = the = Symbol ()) {

if (OrderType () == oType || oType < 0) {

count ++;

}

}

}

}

}

return (count);

}

double sltpValue (double, int w1 w2)

{

if (w2 = = 0)

return (0);

return (NormalizeDouble (w1, Digits));

}

 
Avasys:
ANYBODY CAN TELL ME WHAT'S WRONG WITH THIS CODE?

IS THERE ANY ERROR, BECAUSE IT DOES NOT CREATE EX4 FILE WHEN I PASTE MQ4 FILE IN EXPERTS FOLDER

Can you tell us where did you got this ea?

It looks like the ea is jumbled. For example in line 129 where you have definition of function isGoodTime we see:

bool isGoodTime (string, string, Begin, End)

it should be:

bool isGoodTime (string Begin, string End)

There are many errors like that in ea. Looks like the code is incomplete, or protected by code change like this and this makes this source usless.

 
Kalenzo:
Can you tell us where did you got this ea?

It looks like the ea is jumbled. For example in line 129 where you have definition of function isGoodTime we see:

bool isGoodTime (string, string, Begin, End)

it should be:

bool isGoodTime (string Begin, string End)

There are many errors like that in ea. Looks like the code is incomplete, or protected by code change like this and this makes this source usless.

[lang=pl]I'm an author. I attache mq4 file for Avasys. I dont who change in the code function isGoodTime. In my terminal its working. Avasys why you so nervous ??

If you have problem just contact me instead of talking about this on the forum.[/lang]

Files:
 
g.pociejewski:
[lang=pl]I'm an author. I attache mq4 file for Avasys. I dont who change in the code function isGoodTime. In my terminal its working. Avasys why you so nervous ?? If you have problem just contact me instead of talking about this on the forum.[/lang]

I am not nervous, I could not find you on forum

this EA works fine but makes multiple trades per day again. So my worries was to ask EA to make just one trade per day

 
CodeMeister:
Certainly problems can occur in real accounts that don't show up in demo or strategy tester, but usually they are not recurring and are infrequent. I have never seen or heard of this one.

From your explanation, I can't determine how many trades are open when the problem occurs. If the error is happening with no trades open, that is a mystery. If it occurs with say 5 trades open, that probably has something to do with the problem.

ERR_TRADE_DISABLED 133 Trade is disabled. All attempts to trade must be stopped.

The documentation for this error would seem to indicate that something is wrong with the way the EA is placing the trade. But since both EAs are using the same OrderSend() logic, I wonder if it has something to do with the fact you have 2 EAs running. Normally any contention issue causes a "Trade Context Busy" (146) and any account problems would cause an "Insufficient Funds" (134) error. It would be worth trying to run only one EA at a time and see if that makes a difference.

The EA that is having the problems only opens one trade at a time. No other trades have been open when the errors occurred. I will try running only one EA and see if that helps. Thanks for the advice.

 

How to read a MT4 label

Hey there,

I have modified an indicator and I have created a OBJ_LABEL object with values so that my EA can pick up the values in the OBJ_LABEL. These values are price points and I cannot create another buffer in the indicator to hold them, so I have just place them in these labels. Seems like a good solution, BUT, I cannot figure out how to READ a label in MT4 in my EA!! I use the GETOBJECT function, but it will only return certain properties and text value of a label or text object is not one of them!!

Can anyone help me here?

Thanks!

Reason: