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

 
you forget to include order volumes - then the calculation is correct...
 
isiklik:
...

Please write a code in MQL4

...
This is a help for those who write their own code, not free code writing. Show me the code you are trying to do yourself, but it doesn't work.
 

Sorry to disturb your peace. This is the first time I've ever come across this. If I knew how to write code, I would have written it myself. I wanted to create my own EA. All I had to do now was to write the code. I did the rest with Forex EA Generator. I have not found a way to make this small piece by myself.

I will look for it somewhere else.

 
isiklik:

Guys, let's live together. :)

This is a piece of my TS, where all open trade prices on the BAY side should be summed, divided by the number of trades and added 200 pips. And in the direction of sell subtract 200 pips.

Who may help me write MQL4 code?

X1 - X open trades

Y - number of open trades

The formula should look something like this: X1 + X2 + X3 + X4 + X... / Y+200

For example, if I have 5 open trades in BAI, I should sum them up, divide by 5 and add 200. And 8 open trades in sell should be summed, divided by 8 and subtract 200.


Please send me the code in MQL4.


Thank you very much!


//Профит для бая и селла
double tp_buy = AvgPrice(OP_BUY, 200);
double tp_sell = AvgPrice(OP_SELL, 200);




//Считаем среднюю цену открытия и прибавляем Отступ (TP)
double AvgPrice (int type, double TP=0)
   {
   double sum_price=0;
   double sum_comission=0;
   double avg_price=0;
   double order_lots=0;
   
   //складываем Лоты, Цену, Комиссии
   for(int i=OrdersTotal()-1; i>=0; i--)
      {
      bool i2=false; while(i2==false && !IsStopped())i2=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
   
      if(OrderType()==type && OrderSymbol()==_Symbol && Magic==OrderMagicNumber() && OrderCloseTime()==0)
         {
         sum_price += OrderOpenPrice() * OrderLots();
         order_lots += OrderLots();
         sum_comission += OrderSwap()+OrderCommission();
         }
      }
   
   //определяем среднюю цену и прибавляем Отступ
   if (order_lots>0)
      {
      sum_comission = sum_comission / order_lots / MarketInfo(Symbol(),MODE_TICKVALUE) * _Point;
      
      if (type == OP_BUY)
         avg_price = sum_price / order_lots + sum_comission + TP*_Point;
   
      else
         avg_price = sum_price / order_lots - sum_comission - TP*_Point;
      }
   
   return (NormalizeDouble(avg_price,_Digits));
   }
 
Taras Slobodyanik:

Thank you very much Taras!

You've got such mistakes. I will try to google it.

error 168: 'AvgPrice' - function not defined
error 168: 'AvgPrice' - function not defined
error 256: 'Magic' - undeclared identifier
Result: 3 error(s), 0 warning(s)
 
Who knows? FORMULA for calculating the TREND LINE BY ANGLE. Based on what values does this tool calculate the angle in MT4?
 
Taras Slobodyanik:


Google doesn't help me at all. I can't figure out what's wrong withAvgPrice andMagic.

What I understand about this code is that it calculates commissions, swaps, lots. I don't need that at all. :(

 
isiklik:


Google doesn't help me at all. I can't figure out what's wrong withAvgPrice andMagic.

What I understand about this code is that it calculates commissions, swaps, lots. I don't need that at all. :(

Yeah we understood 100% too, that's what you need
 
Sergey Gritsay:
To do this, you need to create a server outside the local computer and transfer data through this server, respectively, for MT you write an indicator or advisor that processes this data, or put the terminals on a VPN server and there you set up a copier of deals from your account to your friends' accounts. Another option is to copy your trades executed on given levels through signals service. In general, we should consider your financial capabilities to order the appropriate software.

Let me remind you of the prehistory. I have an indicator that receives daily data from csv and displays them (horizontal levels) on the chart. I have created a server from a home laptop (weak, but the calculations there are no need and will give the csv, and they are very small). On the server for the test connection poured the usual forum engine - everything seems to be visible from the outside. Help with advice. That should be on the server to read from it indicator csv files? I.e. how does the indicator communicates with the csv database? Maybe fill in the engine fTP server or something else and can for MT need to open some special ports? Or I got into the wrong direction in general? Thanks
 
MosheDayan:

Let me remind you of the prehistory. There is an indicator that receives daily data from csv and displays it (horizontal levels) on the chart. Created a server from a home laptop (weak, but the calculations there are not needed and will give csv, and they are very small). On the server for the test connection poured the usual forum engine - everything seems to be visible from the outside. Help with advice. That should be on the server to read from it indicator csv files? I.e. how does the indicator communicates with the csv database? Can fill the engine fTP server or something else and can for MT need to open some special ports? Or I got into the wrong direction in general? Thanks

Dig MySQL.
Reason: