Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 191

 
Vitaly Muzichenko:

Try commenting out the line, make one function work


interesting if you know how)
 
Rustam Bikbulatov:

interesting if you know how)
you don't need to know anything, I showed it in the code //
 
Rustam Bikbulatov:

Hello again. Can you tell me how to change the code of a known programmer. At the moment this owl closes about one trade per second. I would like to change it to close trades instantly as it crosses a certain profit regardless of positive or negative trades.

Are there any error messages written to the log?

Can you reduce the delay inside ClosePosBySelect to more reasonable values. For every order there are several attempts to close it, and every time we get Sleep in case of failure.

By the way, recovery from errors can be done in a better way (since the moment of creation of these functions, MT has learned to generate a different code than ERR_CONTEXT_BUSY).

 
Rustam Bikbulatov:

It's interesting if you know how)
You can replace those two with this one, it works fine for me, but a lot depends on how fast your DC executes orders.
 
Maxim Kuznetsov:

Are any error messages being logged?

You can reduce delays inside ClosePosBySelect to more reasonable values. There are several attempts to close each order and each time, if unsuccessful, Sleep is shown.

By the way, recovery from errors can be done in a better way (since the moment of creation of these functions, MT has learned to generate a different code than ERR_CONTEXT_BUSY).

I tried to remove Sleep altogether, but it is different.
 
Vitaly Muzichenko:
You can replace those two with this one, it works fine for me, but a lot depends on how fast your brokerage company executes orders.

Is it a complete owl or part of code from something?
 

Gentlemen experts, help!!! I've been working on this problem for three days. I used the standard function in my Expert Advisor (I've seen it everywhere) to read a file from the Internet using wininet.dll for further analysis:


string ReadHTML()

{

if(!IsDllsAllowed())

{

Alert("You need to allow DLLs in settings;)

return(");

}

int rv = InternetAttemptConnect(0);

if(rv != 0)

{

Alert("Error while calling InternetAttemptConnect()");

return(");

}

int hInternetSession = InternetOpenW("Microsoft Internet Explorer", 0, "", "", 0);

if(hInternetSession <= 0)

{

Alert("Error calling InternetOpenW()");

return(");

}

int hURL = InternetOpenUrlW(hInternetSession,URL, "", 0, 0, 0);

if(hURL <= 0)

{

Alert("Error calling InternetOpenUrlW();

InternetCloseHandle(hInternetSession);

return("");

}

int cBuffer[256];

int dwBytesRead[1];

string TXT = "";

while(!IsStopped())

{

bool bResult = InternetReadFile(hURL, cBuffer, 1024, dwBytesRead);

if(dwBytesRead[0] == 0)

break;

string text = "";

string text0= "";

for(int i = 0; i < 256; i++)

{

text0= CharToStr((char)(cBuffer[i] & 0x000000FF));

if (text0!="\r") text = text + text0;

else dwBytesRead[0]--;

if(StringLen(text) == dwBytesRead[0]) break;

text0= CharToStr((char)(cBuffer[i] >> (8 & 0x000000FF));

if (text0!="\r") text = text + text0;

else dwBytesRead[0]--;

if(StringLen(text) == dwBytesRead[0]) break;

text0= CharToStr((char)(cBuffer[i] >> (16 & 0x000000FF));

if (text0!="\r") text = text + text0;

else dwBytesRead[0]--;

if(StringLen(text) == dwBytesRead[0]) break;


text0= CharToStr((char)(cBuffer[i] >> (24 & 0x000000FF));

if (text0!="\r") text = text + text0;

else dwBytesRead[0]--;

if(StringLen(text) == dwBytesRead[0]) break;

}

TXT = TXT + text;

Sleep(1);

}

InternetCloseHandle(hURL);

InternetCloseHandle(hInternetSession);

return(TXT);

}


All ok, only once read site, which is subsequently updated, on subsequent calls to this function (with a period of 1 minute or less, although the site is updated more often) gives the same site unchanged (as it was read the first time). Restarting the Expert Advisor does not help, as the file was read the first time after starting the terminal, so it appears. The only way to update is to manually open Internet Explorer with the required site (respectively, with updated information) and the function starts reading the updated information and then freezes this configuration of the site, or when restarting the terminal MT4 (and also when read for the first time after restarting the terminal, so it keeps on outputting). I suspect it has something to do with parameters InternetOpenW or InternetOpenUrlW, I've got zeros everywhere by default but I can't find any clear description of it and it somehow works with other EAs (I took it from Expert Advisors that retransmit news from sites to the terminal). Yes, in terminal settings "Allow WebRequest for..." for required site.

 

Good afternoon.

Already my RAM is fuming: A problem arose in the EA, after taking a TP or SL, it opens an order again!

I cannot think of a condition when the EA would be bound only to the 2nd bar after the signal from the indicator

or if a TP or SL triggered, it would wait for a new signal, but only when the indicator signal changes.


void OnTick()

{

uptr = NormalizeDouble(iCustom(NULL, 0, "Slope Direction Line", period, method, price, 0, n), 4);

dntr = NormalizeDouble(iCustom(NULL, 0, "Slope Direction Line", period, method, price, 1, n), 4);

if(DN_Trend()==true)

{

if(CountSell() == 0 && Bid < dntr && Open[3] < dntr && Close[3] < dntr)

{

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "Sloper", Magic, 0, Red);

if (ticket > 0)

{

SL = NormalizeDouble(Bid + StopLoss*Point, Digits);

TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);

if (OrderSelect(ticket, SELECT_BY_TICKET))

if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Print("Sales error");

}

}

 
d1w4m3:

Good afternoon.

Already my RAM is fuming: A problem arose in the EA, after taking a TP or SL, it opens an order again!

I cannot think of a condition when the EA would be bound only to the 2nd bar after the signal from the indicator

Or, if a TP or SL triggered, the Expert Advisor would wait for a new signal, but only when the indicator signal changes.

If the last closed position is of the same type as the signal and if this position was closed on one of the stop orders, then do not open a position.
 
Artyom Trishkin:
If the last closed position is of the same type as the signal came in, and if this position was closed on one of the stop orders, then don't open the position.


Thanks for the answer, but I've only just started learning for a couple of weeks, how to implement this in code, or tell me where to read please. Or according to Igor Kim?

And yet it will open a position, not according to the system, when just starting its work, your condition does not avoid this problem.

Reason: