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

 
Igor Makanu:

I wrote above, about the level of questions ;)

and you started looking for optimality of initialization in OnTick/OnInit - everything is simpler there, you need protection for found code to share it with the same friends ))))

I see, then a toast: to found "friends"!

 
Igor Makanu:

Need protection for found code to share with similar friends )))

Beautifully put. We probably look like nerds, but we're having fun!

 
Vitaly Muzichenko:

Well, that's the limit of everything :(


Vitaly, what's with the negativity? The man is just asking to troll him, it is necessary to respect)

Igor Makanu:

I wrote above, about the level of questions ;)

and you started looking for optimality of initialization in OnTick/OnInit - everything is simpler there, you need protection for the found code, to share with the same friends )))

))))

 
Aleksey Mavrin:

Vitaly, what's with the negativity? The man is just asking to be trolled, you should respect him)

))))

All right, a little positivity.

 
Hello, could you advise me please? The manual states that the Initevent is processed by the OnInit() function. This event is also generated after a financial instrumentand/or chart period change.

Here I have a simple code. When I change the timeframe, the function works, but not when I change the instrument. Or maybe I misunderstand the term "change of financial instrument"?

int OnInit()
  {
    Print("HALLO");
    return(INIT_SUCCEEDED);
  }
Документация по MQL5: Основы языка / Функции / Функции обработки событий
Документация по MQL5: Основы языка / Функции / Функции обработки событий
  • www.mql5.com
В языке MQL5 предусмотрена обработка некоторых предопределенных событий. Функции для обработки этих событий должны быть определены в программе MQL5: имя функции, тип возвращаемого значения, состав параметров (если они есть) и их типы должны строго соответствовать описанию функции-обработчика события. Именно по типу возвращаемого значения и по...
 
WinProject:
Good time, please advise. The handbook says that the Init event is handled by the OnInit() function. This event is also generated after a financial instrumentand/or chart period change.

Here I have a simple code. When I change the timeframe, the function works, but not when I change the instrument. Or maybe I misunderstand the term "change of financial instrument"?

int OnInit()
  {
    Print("HALLO Period()= ",Period(),"Symbol()=",Symbol());
    return(INIT_SUCCEEDED);
  }

For correctness of perception, it is better like this. If you put a new symbol on the chart, OnDynit should work and start with OnInit

 
Valeriy Yastremskiy:

For the sake of fidelity, it's better this way. If you put a new symbol on the chart, OnDeinit should work and start with OnInit

Thanks, so many years with the terminal and didn't know you could cast to a chart from a market overview, thought changing a financial instrument was a switch to a chart window with a different instrument.

 

Hello, could you tell me if this is a bug or am I mistaken?

I was doing some calculations, which you can also get through ready-made functions and noticed a difference.

I was calculating margin, and in the tester margin calculation and AccountInfoDouble(ACCOUNT_MARGIN) give different results, and there is no difference in the demo.

#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
 

input double lot=0.1;
input int plecho=100;
input double lot_increment=1; //увеличение лота
input int level_size=50;
input int Magic = 0;
input int deviation = 10; //допустимое проскальзывание

double margin, margin_free, uroven, sredstva_pri_s_o, margin_call, stop_out;
int N;



int OnInit(){

Print("Bid ", Bid);

int ticket=OrderSend(NULL, OP_BUY, lot, Ask, 0, 0, 0, "", Magic, 0);
    //ticket=OrderSend(NULL, OP_SELL, lot, Bid, 0, 0, 0);


Print("  ACCOUNT_MARGIN ", AccountInfoDouble(ACCOUNT_MARGIN)
, "  ACCOUNT_MARGIN_LEVEL ", AccountInfoDouble(ACCOUNT_MARGIN_LEVEL));

margin=(OrderLot()*100000*OrderPrice())/plecho;
Print("OrderLot() ", OrderLot(), "  OrderPrice() ", OrderPrice());
margin_free=AccountInfoDouble(ACCOUNT_EQUITY)-margin;
uroven=(AccountInfoDouble(ACCOUNT_EQUITY)/margin)*100;
sredstva_pri_s_o=(margin*AccountInfoDouble(ACCOUNT_MARGIN_SO_SO))/100;
N=(int)NormalizeDouble((AccountInfoDouble(ACCOUNT_BALANCE)-sredstva_pri_s_o)
/MarketInfo(Symbol(), MODE_TICKVALUE), 0);
stop_out=OrderPrice()-(N*Point());

Print("stop_out ", stop_out, "  margin ", margin, "  uroven ", uroven
, "  ACCOUNT_MARGIN_SO_SO ", AccountInfoDouble(ACCOUNT_MARGIN_SO_SO)
, "  ACCOUNT_MARGIN_LEVEL ", AccountInfoDouble(ACCOUNT_MARGIN_LEVEL)
, "  ACCOUNT_MARGIN ", AccountInfoDouble(ACCOUNT_MARGIN));
return(INIT_SUCCEEDED);
}//+------------------------------------------------------------------+
void OnDeinit(const int reason){
}//+------------------------------------------------------------------+
void OnTick(){


Print("  ACCOUNT_MARGIN ", AccountInfoDouble(ACCOUNT_MARGIN)
, "  ACCOUNT_MARGIN_LEVEL ", AccountInfoDouble(ACCOUNT_MARGIN_LEVEL));

Comment("AccountInfoDouble(ACCOUNT_MARGIN_SO_CALL) ", AccountInfoDouble(ACCOUNT_MARGIN_SO_CALL)
, "  AccountInfoDouble(ACCOUNT_MARGIN_SO_SO) ", AccountInfoDouble(ACCOUNT_MARGIN_SO_SO)
, "  AccountInfoDouble(ACCOUNT_MARGIN_LEVEL) ", AccountInfoDouble(ACCOUNT_MARGIN_LEVEL)
, "  AccountInfoDouble(ACCOUNT_MARGIN) ", AccountInfoDouble(ACCOUNT_MARGIN)
, "  MarketInfo(Symbol(), MODE_MARGINREQUIRED) ", MarketInfo(Symbol(), MODE_MARGINREQUIRED) , "\n"
, "margin ", margin
, "  margin_free ", margin_free 
, "  uroven ", uroven );
}//+------------------------------------------------------------------+

double OrderPrice(){
   double count=0;
   for (int i=OrdersTotal()-1; i>=0; i--){
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
         if (OrderSymbol() == Symbol()  && OrderMagicNumber()==Magic )
            count=OrderOpenPrice();
      }   
   } 
   return(count);   
}
double OrderLot(){
   double count=0;
   for (int i=OrdersTotal()-1; i>=0; i--){
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
         if (OrderSymbol() == Symbol()  && OrderMagicNumber()==Magic )
            count=OrderLots();
      }   
   } 
   return(count);   
}


 
Please help.

I've tried everything and still get error 130.
Files:
Wai_v_5.0.mq4  59 kb
 
Good afternoon to all. I'm trying to write a grail advisor of my own ;-). But for some reason it does not want to work. I have recorded a video, the link to the video is in my message. This will be both clearer and faster. The question itself is in the video. Thank you in advance. https://youtu.be/tqZrXjMONrE
ВОПРОС ПО НАПИСАНИЮ СОВЕТНИКА
ВОПРОС ПО НАПИСАНИЮ СОВЕТНИКА
  • 2020.12.09
  • www.youtube.com
ПИШУ СОВЕТНИК НА MQL4, А ГДЕ-ТО ДОПУСТИЛ ОШИБКУ- ПОМОИГИТЕ ПОЖАЛУЙСТА ПОНЯТЬ ГДЕ И В ЧЁМ ЭТА ОШИБКА ПОЛУЧИЛАСЬ?