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

 
ANDREY:

Good day to all!

I have started studying mql5. I started by studying how orders are opened. I have understood that the code for opening an order is written in a separate include file. I have now mastered this code and its final variant for trading. I was amazed that the order opening in mql4 is much easier and simpler than in mql5.

I would like to ask if I am sure I already have the file with the code to open the order and I don't need to write this code. If such a file is available somewhere, then I only need to connect it to my EA and set the values of the order parameters I need? If there is such a file, where and how it should be found, and what its name is.

Thank you.

If I understand you correctly, it is #include <Trade\Trade.mqh>.

Files:
ng4txc.PNG  116 kb
15vegf1.PNG  114 kb
 
SanAlex:

If I understand you correctly, it is #include <Trade\Trade.mqh>.

Thank you very much for this valuable information.

Do I correctly understand that I don't have to look for these files anywhere, but just write in the right place of the code #include <Trade\Trade.mqh> and this file will automatically join my Expert Advisor and it will access it when needed?

 
ANDREY:

Thank you very much for the valuable information.

Do I correctly understand that I don't have to look for these files anywhere, but just write in the right place of the code #include <Trade\Trade.mqh> and this file will automatically join my EA and the EA will access it when needed?

Yes! You don't have to look for it, it's already there.

You can look at the code file(Moving Averages.mq5 or MACD Sample.mq5), from the terminal.

 
SanAlex:

Yes! You don't have to look for it, it's already there.

Thank you very much for the valuable information.
If I understood correctly the file you have sent me is called CLASS This file is intended for opening an order. I think there are a lot of CLASSES and each one has its own purpose, for example to close the order, to modify the order, to output some information, etc.

Q: Where can I find a list of all classes with their detailed descriptions?
Thank you again for your help.

 
ANDREY:

Thank you very much for the valuable information.
If I understand correctly the file you sent me is called CLASS This file is for opening an order. I think there are a lot of CLASSES and each one has its own specific purpose, e.g. to close an order, to modify an order, to output some information, etc.

Q: Where can I find a list of all classes with their detailed descriptions?
Thank you again for your help.

Документация по MQL5: Стандартная библиотека
Документация по MQL5: Стандартная библиотека
  • www.mql5.com
Стандартная библиотека MQL5 написана на языке MQL5 и предназначена для облегчения написания программ (индикаторов, скриптов, экспертов) конечным пользователям. Библиотека обеспечивает удобный доступ к большинству внутренних функций MQL5.
 
Artyom Trishkin:

Thank you very much for the valuable information. I will now start digesting it, i.e. assimilating ..... as far as my mental capacity is concerned.

 
ANDREY:

Good day to all!

I have started studying mql5. I started by studying how orders are opened. I have understood that the code for opening an order is written in a separate include file. I have now mastered this code and its final variant for trading. I was amazed that the order opening in mql4 is much easier and simpler than in mql5.

I would like to ask if I am sure I already have the file with the code to open the order and I don't need to write this code. If such a file is available somewhere, then I only need to connect it to my EA and set the values of the order parameters I need? If there is such a file, where and how it should be found, and what its name is.

Thank you.

I have a different approach to writing an EA for me. I just need to correct it for myself.

-( why reinvent the wheel when it's already been created )

----------------------------------------------------------------------

this is where we pick up the Indicators

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//--- prepare trade class to control positions if hedging mode is active
   ExtHedging=((ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE)==ACCOUNT_MARGIN_MODE_RETAIL_HEDGING);
   ExtTrade.SetExpertMagicNumber(MA_MAGIC);
   ExtTrade.SetMarginMode();
   ExtTrade.SetTypeFillingBySymbol(Symbol());
//--- Moving Average indicator
   ExtHandle=iMA(_Symbol,_Period,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE);
   if(ExtHandle==INVALID_HANDLE)
     {
      printf("Error creating MA indicator");
      return(INIT_FAILED);
     }
//--- ok
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+

and here we set them so that indicators open correctly according to the signal

//+------------------------------------------------------------------+
//| Check for open position conditions                               |
//+------------------------------------------------------------------+
void CheckForOpen(void)
  {
   MqlRates rt[2];
//--- go trading only for first ticks of new bar
   if(CopyRates(_Symbol,_Period,0,2,rt)!=2)
     {
      Print("CopyRates of ",_Symbol," failed, no history");
      return;
     }
   if(rt[1].tick_volume>1)
      return;
//--- get current Moving Average 

   double   ma[1];
   if(CopyBuffer(ExtHandle,0,0,1,ma)!=1)
     {
      Print("CopyBuffer from iMA failed, no data");
      return;

     }
//--- check signals
   ENUM_ORDER_TYPE signal=WRONG_VALUE;

   if(rt[0].open>ma[0] && rt[0].close<ma[0])
      signal=ORDER_TYPE_SELL;    // sell conditions
   else
     {
      if(rt[0].open<ma[0] && rt[0].close>ma[0])
         signal=ORDER_TYPE_BUY;  // buy conditions
     }
//--- additional checking
   if(signal!=WRONG_VALUE)
     {
      if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) && Bars(_Symbol,_Period)>100)
         ExtTrade.PositionOpen(_Symbol,signal,TradeSizeOptimized(),
                               SymbolInfoDouble(_Symbol,signal==ORDER_TYPE_SELL ? SYMBOL_BID:SYMBOL_ASK),
                               0,0);
     }
//---
  }
//+------------------------------------------------------------------+
 
Artyom Trishkin:

To help me get a better understanding of MQL5, I'd be very grateful if you could translate this simple code from MQL4 into MQL5 code

Thanks for the help.

int s1,SL,a;
double Lou=Bid,Hay,DL=0.0030;
void OnTick()
{
if (Bid < Lou)
{
Lou=Bid;
}
if (Bid > Hay)
Hay=Bid;
if (Bid - Lou > DL&& Lou!=0)
{
Lou=Bid;
Hay=Bid;
s1=1;
}
////=======================
if (Hay-Bid>0.0000)
if (s1==1)
{
for(int c=0; c<=500;c+=20)
{
a++;
{
SL=300+c;
OrderSend(Symbol(),OP_SELL,0.1,Bid, 3,Ask+SL*Point,Ask-SL/3*Point,"300",100);
Lou=Bid;
Hay=Bid;
}
}
a=0;
s1=0;
}
}
 

numPosOr= 4;

numStepCount= 1;

iK = (numPosOr - numStepCount) / numPosOr;

Why does this calculation makeiK = 0?

 
Sysmart:

numPosOr= 4;

numStepCount= 1;

iK = (numPosOr - numStepCount) / numPosOr;

Why does this calculation makeiK = 0?

Please give me the whole code