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

 
Alexey Viktorov:
I'll give you that. But it takes a lot of effort to figure out that this is the "Trading" window and not the "Account History" window. Inattentiveness and laziness, without straining my head muscles, led me to believe it was the Account History window.

It happens. Forgivable.

 

Disabled the standard bid line on the chart because of the inconvenience of reading five digits, made the output 4 digits in the upper corner, but sometimes the price goes down, which again causes inconvenience :-)

I want to make the Label object move with the price, right price tagOBJ_ARROW_RIGHT_PRICE I don't like because of the frame.

But for some reason the positioning by price bid doesn't work, the label is displayed in the upper left corner


//+------------------------------------------------------------------+
//|                                              CandleTimeStationary|
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property strict

//---- input parameters
input color Clock_Color = clrCrimson;

string objname="Bid";


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
        ObjectCreate(0, objname, OBJ_LABEL,0, 0, 0);
        
    

        return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason) { ObjectDelete(0, objname); } 

//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, const int prev_calculated, const datetime& time[], const double& open[], const double& high[], const double& low[], const double& close[], const long& tick_volume[], const long& volume[], const int& spreads[])
{

        ObjectSetDouble(0, objname, OBJPROP_PRICE, SymbolInfoDouble(Symbol(), SYMBOL_BID));     
        ObjectSetString(0, objname, OBJPROP_TEXT, DoubleToString(SymbolInfoDouble(Symbol(), SYMBOL_BID), _Digits-1));
        ObjectSetInteger(0, objname, OBJPROP_FONTSIZE, 12);
        ObjectSetInteger(0, objname, OBJPROP_COLOR, Clock_Color);
        ObjectSetString(0, objname, OBJPROP_FONT, "Verdana");
        
        return(rates_total);
}
 
psyman:

Disabled the standard bid line on the chart because of the inconvenience of reading five digits, made the output 4 digits in the upper corner, but sometimes the price goes down, which again causes inconvenience :-)

I want to make the Label object move with the price, right price tagOBJ_ARROW_RIGHT_PRICE I don't like because of the frame.

But for some reason the positioning by price bid doesn't work, the label is displayed in the upper left corner


ForOBJ_LABEL the position report is specified in pixels.

ChartTimePriceToXY(0, 0, TimeCurrent(), Bid, x, y); // x, y добавьте в переменные, тип int
ObjectSetInteger(0, objname, OBJPROP_YDISTANCE, ulong(y)); //если на эту строчку будет предупреждение в компиляторе то, значит ulong ненужен
//ObjectSetDouble(0, objname, OBJPROP_PRICE, SymbolInfoDouble(Symbol(), SYMBOL_BID));
ObjectSetString(0, objname, OBJPROP_TEXT, DoubleToString(Bid, _Digits-1));
 
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+

double Znomer()
{
zn=0; // z-число
psd=0; // кол. положительных сделок
usd=0; // количество отрицательных сделок 
ww=0; // боол переменная 
nn=0; // боол переменная
C=0; // C = количество чередований между отрицательными и положительными сделками
index=OrdersHistoryTotal(); 
if(OrdersHistoryTotal()>302) index=301; // берём не более 301 сделки
if(index<30) return(1); // берём не менее 30
count=OrdersHistoryTotal(); // считаем от скольки 
prom=count-index; // выделяем только последние сделки
if (prom<0) prom=0; // исключаем ошибки

for( i=count;i>prom;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)== true)
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{// далее магия
pribul=OrderProfit(); 
if (ww==0&&pribul>1){C++;ww=1;nn=0;}// подсчитываем смену тенденции
if (nn==0&&pribul<1){C++;ww=0;nn=1;}// подсчитываем смену тенденции 
if (pribul>1){psd++;}//прибыльные сделки
if (pribul<1){usd++;}// убыточные сделки

}
}
}
/*/*
Величина Z = (A * (C — 0.5) — B)/ ((B*(B — C))/(C -1))^(1/2), где:
A = количество анализируемых сделок;
B = 2*количество прибыльных сделок * количество убыточных сделок;
C = количество чередований в выборке (чередованием считается каждая пара сделок, 
когда прибыльная сделка сменяет убыточную либо наоборот).
*/
zn = (index*(C-0.5)-(2*psd*usd))/
((((2*psd*usd)*((2*psd*usd)-C))/
(C-1))*((((2*psd*usd)*((2*psd*usd)-C))/
(C-1))*0.5));



return(zn);
}

I decided to write a simple code to calculate the tendency of losing an account. For this purpose I took a simple Z-account formula and tried to transfer it to mq4 code.
Everything seems to be correct, but when I run simple output using Print the EA does not work at once. I don't get any errors when compiling.
I've already racked my brains on simple code.

Thank you if you can help !

 
Aliaksei Karalkou:

I decided to write a simple code for calculating the tendency of losing an account. For this purpose I took a simple formula of Z-account and tried to use it in mq4 code.
Everything seems to be correct, but when I run simple output using Print the EA does not work at once. I don't get any errors when compiling.
I've already racked my brains on simple code.

Thanks if you can help !

Check the work permit for the EA. And where in the print output? This piece of code must return something, if there are no errors, then the problem is outside of this piece of code. Except that division by 0 may occur in this block.

 
Ilya Prozumentov:

ForOBJ_LABEL the position report is specified in pixels.

Ilya, thank you, it worked.

Only when going to the next stage - accounting for window resizing - the compiler gives a warning about data type conversion:

int width = ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);

possible loss of data due to type conversion 4digit+.mq5 36 14


Although the function returns int type.


 
psyman:

Ilya, thank you, it worked.

Only when going to the next stage - accounting for window resizing - the compiler gives a warning about data type conversion:

possible loss of data due to type conversion 4digit+.mq5 36 14


Although the function returns the int type.


The function returns the long type
 
novichok2018:

Really?! And where does it show that the order has closed?

A green TP in the "trade" window means that the current price is within -100 pips of the TP, or, to be more correct, within 100 pips of the TP.

Thank you!
 
Artyom Trishkin:
The function returns long type

What should I do in such cases, change the type of the variable or leave it as it is?

 
psyman:

What is recommended to do in such cases, change the type of variable or leave it as it is?

int width = (int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);