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

 

Good afternoon, gentlemen. )) apologies for the amateurism...

I don't understand how OrderClose works :(

I need a maximum of 1 order, i.e. before opening a new one, i want the previous one to be closed...

Why does it not work this way?


OrderClose(nom, 0.01, Bid,5, Red);

OrderSend(Symbol(), OP_SELL, 0.01 , NormalizeDouble(Bid,5), 3 , NormalizeDouble(Ask+0.0005,5), NormalizeDouble(Bid-0.0008,5), "", nom,0,Red);


the log is basically swearing about an invalid Ticket .

in OrderClose instead of nom, what should I put? or am I thinking in the wrong direction at all?)

 
Sergey Voytsekhovsky:

Try minStopLoss = Current price +/- (MaxValue(2*Spread, StopLoss));

I tried it. Two spreads is 24, will not work that way, starts working at 19 from closing price. From the current opening price works with three spreads.
I increased the stop by one point in the loop and opened an order. It opened on 19. The question is not how to set it. The question is how to calculate correctly. There are no prices; they show up during manual opening of an order if you set the stop with the stop button. This is ridiculous. I'm having a mass reading of this forum. I have found some functions on the 7th page (message #65). I will let you know when I check it.

 
Sergey Voytsekhovsky:

I studied it, but nothing new, apparently it is (new to me) of course, obvious to all the initiated, self-explanatory. I couldn't find anything new, except the above-described feature of mutual arrangement of buffers during indexing. This sequence respected, got an even cheesier picture.

Pictures below, file attached

Maybe you are very unlucky but I don't like poking around in other people's code. All the more so when it comes to fixing it...

The next question: how often do you think the indicator value will be exactly 50?

         ColorHistogram_2Buffer1[i]=50; 

As I understood the problem, it should be one colour >50 and another <50, but I haven't seen ==50. Of course, to eliminate loss in case ==50, we must add to one of the comparisons >=50 or the other <=50, as religion allows. It may look better.

And the second question: how much you think it was necessary to change all indexing of buffers? After reindexing, did you fix everything in the code exactly? Maybe it would be easier to make colour buffer index 4, and auxiliary buffers 5 and 6 accordingly. There would be less need to edit and less chance of making some more errors.

 
klok79:
I tried it. Two spreads is 24, will not work that way, starts working at 19 from closing price. From the current open price it works with three spreads.
I increased the stop by one point in the loop and opened the order. At 19 it opened. It's not a question of how to pick. The question is how to calculate it correctly. There are no prices that appear when I open an order manually if I set a stop with the button. This is ridiculous. I'm having a mass reading of this forum. I have found some functions on the 7th page (message #65). I will have to check it and report.

Checked. Works
This is all strange, it says the same minStopLoss = Current Price +/- (max value(2*Spread, StopLoss)), only under Current Price we understand not the open price of the order but the mirror price.
Why is the double spread suitable?
Two more questions arise.
1. Why is SymbolInfoInteger used to get Digits() and Point(); values ?
2. Why is an entry (int) used before calling the SymbolInfoInteger function ? As I understand it, this is a forced type conversion.

 
klok79:

Checked it. It works
This is all weird, they still write the same minStopLoss = Current Price +/- (maxZen(2*Spread, StopLoss)) but the Current Price is not the opening price of the order but the mirror price.
Why is the double spread suitable?
Two more questions arise.
1. Why is SymbolInfoInteger used to get Digits() and Point(); values ?
2. Why is an entry (int) used before calling the SymbolInfoInteger function ? As I understand it, this is a forced type conversion.

To get Point() SymbolInfoInteger will not work in any way.))

In general, it is necessary to remember that Point() or _Point is only for the current symbol. For characters other than the one on which the EA works, you must use this very function.

The SymbolInfoInteger function returns not only int values, but also long, bool and enumerations.

 

Sergey Voytsekhovsky, thanks for your help. And one more question, if you don't mind, please suggest the function inverse to functionCharToStr
(to get its code from a symbol), because I've got functions for it in Beisic and Delphi, but in C++, as far as I know, there are two methods:
1 -Ascii_cod function, which is not in mql4
2. - Direct type conversion. But my code is
string st="A";
Print ("Character code A=",(int)st);

Outputs text Character code A=0.

What to do?

 
klok79:

Sergey Voytsekhovsky, thank you for your help. And one more question, if you don't mind, could you suggest the function reverse functionCharToStr
(to get its code from a symbol), because I've got functions for it in Beisic and Delphi, but in C++, as I understand it, there are two methods:
1 -Ascii_cod function, which is not in mql4
2. - Direct type conversion. But my code is
string st="A";
Print ("Character code A=",(int)st);

Outputs text Character code A=0.

What to do?

StringToCharArray, unlike the wiki function, doesn't convert just one character at a time, but can convert a string to an array of ucar type with codes of all characters in the string.

mql4 also has such a function.

Документация по MQL5: Преобразование данных / StringToCharArray
Документация по MQL5: Преобразование данных / StringToCharArray
  • www.mql5.com
Посимвольно копирует преобразованную из unicode в ansi строку в указанное место массива типа uchar. Функция возвращает количество скопированных элементов. [in]  Количество элементов массива для копирования. Определяет длину результатной строки. По умолчанию -1, что означает копирование до конца массива, либо...
 
Alexey Viktorov:

To get Point() SymbolInfoInteger will not work in any way.))

In general, it is necessary to remember that Point() or _Point is only for the current symbol. For characters other than the one on which the EA works, you should use this function.

The SymbolInfoInteger function returns not only int values, but also long, bool and enumerations.

Actually Point has value double. This means that we should call it from SymbolInfoDouble

 
Konstantin Nikitin:

Well, Point actually has a value of double. It means that the request should be made by SymbolInfoDouble

It's about these functions for MQL4 from post #65:

//+------------------------------------------------------------------+
double CorrectStopLoss(string symbol_name,int op,double price_set,double stop_loss) {
   if(stop_loss==0) return(0);
   double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
   double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
   int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
   if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmin(price-(lv+1)*pt,stop_loss),dg));
   else return(NormalizeDouble(fmax(price+(lv+1)*pt,stop_loss),dg));
}
//+------------------------------------------------------------------+
double CorrectStopLoss(string symbol_name,int op,double price_set,int stop_loss) {
   if(stop_loss==0) return(0);
   double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
   double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
   int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
   if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmin(price-(lv+1)*pt,price-stop_loss*pt),dg));
   else return(NormalizeDouble(fmax(price+(lv+1)*pt,price+stop_loss*pt),dg));
}
//+------------------------------------------------------------------+
double CorrectTakeProfit(string symbol_name,int op,double price_set,double take_profit) {
   if(take_profit==0) return(0);
   double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
   double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
   int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
   if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmax(price+(lv+1)*pt,take_profit),dg));
   else return(NormalizeDouble(fmin(price-(lv+1)*pt,take_profit),dg));
}
//+------------------------------------------------------------------+
double CorrectTakeProfit(string symbol_name,int op,double price_set,int take_profit) {
   if(take_profit==0) return(0);
   double pt=SymbolInfoDouble(symbol_name,SYMBOL_POINT);
   double price=(op==OP_BUY)?SymbolInfoDouble(symbol_name,SYMBOL_BID):(op==OP_SELL)?SymbolInfoDouble(symbol_name,SYMBOL_ASK):price_set;
   int lv=StopLevel(symbol_name), dg=(int)SymbolInfoInteger(symbol_name,SYMBOL_DIGITS);
   if(op==OP_BUY || op==OP_BUYLIMIT || op==OP_BUYSTOP) return(NormalizeDouble(fmax(price+(lv+1)*pt,price+take_profit*pt),dg));
   else return(NormalizeDouble(fmin(price-(lv+1)*pt,price-take_profit*pt),dg));
}
//+------------------------------------------------------------------+
int StopLevel(string symbol_name) {
   int sp=(int)SymbolInfoInteger(symbol_name,SYMBOL_SPREAD);
   int lv=(int)SymbolInfoInteger(symbol_name,SYMBOL_TRADE_STOPS_LEVEL);
   return((lv==0)?sp*2:lv);
   }
//+------------------------------------------------------------------+

I didn't see where Point is obtained via SymbolInfoInteger()

 
Artyom Trishkin:

It's about those MQL4 functions from post #65:

I didn't see where Point is obtained via SymbolInfoInteger()

Yes, the same. We have slipped through it. The main thing is that he understands what's what...

Reason: