[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 82

 
nemo811:
Thanks for the help. I understood the logic of setting the flag and function of returning the number of orders. But I am also interested in the moment when the order is closed. It looks like the flag condition tries to place an order again but the function returning the order number says that it has decreased by 1 and initializes opening of a position as well. Correct me if I have missed something.


In the code that you provided, the condition is in one place (BUY=true) and until the flag changes, the reopening will not happen...because the function call to open a position comes from this condition block...And the flag in this code can only change after the EA is restarted, when the variable with the value true will be initialized.

Or maybe I don't understand the question:)

 
NameLess:


The flag in this code can change only after restarting the Expert Advisor, when the variable with the value true is initialized.

or I don't understand the question:)


Thank you, you got it right. I am going to implement it now.
 
NameLess:


This is the version that turned out to work. Many thanks to you and IgorM:

extern bool BUY = true;
extern int Magic = 0;
extern double Lot = 0.1;
extern int takeprofit = 0;
extern int stoploss = 0;
extern int slippage = 3; 
double SL,TP;
int init(){
return(0);
}
int start()
{
if (BUY)
{
if (takeprofit!=0) TP = NormalizeDouble(Ask + takeprofit*Point,Digits); else TP=0;
if (stoploss!=0) SL = NormalizeDouble(Ask - stoploss*Point,Digits); else SL=0; 
OPENORDER ("Buy");

BUY=false;
}

return(0);
}
void OPENORDER(string ord)
{
int ticket = -1;
while (ticket<0)
{
if (ord=="Buy") ticket=OrderSend(Symbol(),OP_BUY, Lot,NormalizeDouble(Ask,Digits),slippage,SL,TP,"",Magic,0);
Sleep(500);
}
return;
}
 

string Val="";
Val = iBands(NULL,0,50,2,0,PRICE_CLOSE,MODE_LOWER,0);
string substr=StringSubstr(Val,0,1);
point_low=StrToDouble(substr);
substr=StringSubstr(Val,2,1);
point_low+=StrToDouble(substr)/10;
substr=StringSubstr(Val,3,1);
point_low+=StrToDouble(substr)/100;
substr=StringSubstr(Val,4,1);
point_low+=StrToDouble(substr)/1000;
substr=StringSubstr(Val,5,1);
point_low+=StrToDouble(substr)/10000;
substr=StringSubstr(Val,6,1);
point_low+=StrToDouble(substr)/100000;

substr=StringSubstr(Val,7,1);
point_low+=StrToDouble(substr)/1000000; //тут плюсуем 6-ю цифру после запятой.

People, nothing helps! I can't get a value with 5 decimal places. i've tried all the options i could think of, i've translated a string into a number, i've translated a substring into a number, i've taken out digits (example above) and i've stupidly added them one by one, beyond 4 decimal places it just doesn't add and starts rounding to 4 decimal places. even i added the 6th decimal place. still, it's no good(

Can it be that Alert does not display double variables beyond the 4th sign? I don't know what to think... some kind of mystery(

 

I've written two EAs linked together (they don't trade, just create gobals) and I think I can use them to make an equi volume chart indicator similar to regular price chart in mt4. Or if someone has already used something similar, please share the code:)

Files:
eqvol.rar  3 kb
 
NameLess:

Can it be that Alert doesn't display double variables beyond the 4th digit? I don't know what to think... some kind of mystery(

Yes. It (like Print) displays the standard 4 digits if only one number is output.

Use DoubleToStr to be more accurate.

 

Rrrrrrrrrrrrrrr. right, the terminal in Alert is not displaying beyond 4 characters. i switched the double back to the line and took it out to look at the screen - everything is correct.

killed half a day for this nonsense. tinny, and everything was working initially(

 
NameLess:

People, nothing helps! I can't get a value with 5 decimal places. i've tried all the options i could think of, i've translated a string into a number, i've translated a substring into a number, i've taken out digits (example above) and i've stupidly added them one by one, beyond 4 decimal places it just doesn't add and starts rounding to 4 decimal places. even i added the 6th decimal place. still, it's no good(

Can it be that Alert does not display beyond the 4th sign of the variable double? (The string shows all) I already do not know what to think.

Well, as always all rests in the experiment. We write the script:

#property copyright ""
#property link      ""
#include <Basic_dll.mqh>

//+------------------------------------------------------------------+
//|                 Старт работы скрипта                             |
//+------------------------------------------------------------------+
int start(){
  string Stroka,Podstroka,SMB;
        int DGS,BezDrobi;
        double Rezult;
        SMB=Symbol();
        //DGS=MarketInfo(SMB,MODE_DIGITS);
        DGS=5;// дигитс задаём принудительно, чтоб можно было проверить на любой валюте
        // передаём левое значение в переменную
        Rezult=1.252546987;
        // возводим число в степень
        for(int i=1;i<=DGS;i++){
                Rezult=Rezult*10;
        }
        // В степень возвели. Теперь отбрасываем дробную часть.
        BezDrobi=OtbrosDrobnChasti(Rezult);// функция отбрасывает дробную часть числа
        Alert("BezDrobi = ",BezDrobi);
        // теперь ставим на место запятую
        Rezult=BezDrobi*1.0;
        for(i=1;i<=DGS;i++){
                Rezult=Rezult/10;
                Alert("Rezult = ",Rezult);
        }
        Alert("----------- ",SMB," -----------");
        return(0);
}

As we can see, there is a dll-card connected to the script. It has only one function that strips the fractional part of the number. The dll file is attached to this post. Now we should sequentially apply the script to 2 currency pairs. I put it on the pound and the euro-japanese. In the pound, I have 4 decimal places. On the euro-Japanese currency pair - two. Here is the result of the script operation:

In the pound, you can see how the comma moves sequentially. And you can also see that the last division leaves 4 digits in the fractional part. We can make an assumption that since my Digits = 4, the fifth digit after the decimal point is cut off. So the EuroJapanese should also result in only 2 digits after the decimal point, since digits on it = 2. However, the experiment shows that it, too, yields 4 digits after the decimal point. So our assumption is not correct and rounding may be taking place. Let's try replacing the final 4 with 7. The result:

What do we see? The resulting five now becomes a six. Consequently, automatic rounding takes place.

I do not know how the script will behave on the five-digit character, but I was not satisfied with the work on the four and two-digit characters - the terminal interfered and rounded off without being asked to do so. So I have to ask questions to the developers. Or - option 2 - take indicator readings, put them into a string, send the string to a dll, process the data there as we need and return the trade order from the dll.

Files:
experts.rar  42 kb
 

Information from the help (According to the Alert):

Данные типа double выводятся с 4 десятичными цифрами после точки. Для вывода чисел с большей точностью используйте функцию DoubleToStr().

Go figure out why the developers did this...

 
drknn:


Thanks, studied the code, very interesting. Everything, as I described above, turned out to be simpler: the terminal simply does not display further than the 4th digit in the window. and all the ideas worked, just solved the conversion issue in different ways :)

zy. Once again I am convinced that all problems are solved logically, and here the situation was originally illogical, so we were looking for a hitch in the wrong place :)

Reason: