Questions from Beginners MQL5 MT5 MetaTrader 5 - page 752

 
Sorry for the very simple question, how do I close an open position? mql4 had the OrderClose() function, but how?
 
RogozaIV:
Excuse me for a very simple question, how do I close an open position? mql4 has the OrderClose() function, but how?

In mql5, you have to open an opposite position. It can be clearly seen in the tab of the terminal History. The easiest way is to use the CTrade class from the standard library.
 
Thank youAlexey Volchanskiy!
 
Can you tell me where to trade cryptocurrencies through MT5? Brokers, exchanges? I found MT4, but MT5 doesn't seem to be available.
 

Gentlemen, please tell me where the error is.

I am preparing an indicator to be called in the EA.

I want to send a buffer from the indicator.

The result is the int value attached to the bar.

The task is to pass a two-dimensional array from the indicator to an Expert Advisor, I can't figure out how to do it.

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2

int per[];

int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,per,INDICATOR_CALCULATIONS); //также пробовал INDICATOR_DATA и INDICATOR_COLOR_INDEX
...

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
{
      for(int b=1; b<Bmax; b++) //отбор по x
        {
         for(int p=1; p<Pmax; p++) // отбор по y
           {
            if(arrayZ[6][p][b]>0||arrayZ[6][p][b]<0)
            {
             per[b]=p;
            }
           }
        }
 }

So I call it in the EA

int OnInit()
  {
//--- create timer
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA); 
   ResetLastError(); 
   MA_handle=iCustom(NULL,0,"Topqw",0,1); 

   Print("MA_handle = ",MA_handle,"  error = ",GetLastError()); 
...

void OnTick()
//void OnTimer()
  {
//--- 
int copy=CopyBuffer(MA_handle,0,0,1000,Label1Buffer); 
   Print("copy =",copy," ",Label1Buffer[999]);//

 
Top2n:

Gentlemen, please tell me where the error is.

I am preparing an indicator to be called in the EA.

I want to send a buffer from the indicator.

The result is the int value bound to the bar.

The task is to pass a two-dimensional array from the indicator to an Expert Advisor, I can't figure out how to do it.

I call it in the EA



1. Remember that in the INDICATOR the default indicator buffer with index "0" corresponds to the leftmost bar on the chart.

2. The Expert Advisor has no "SetIndexBuffer" command.

3. iCustom is creating a custom indicator, not a buffer request (therefore, everything should be written explicitly, not ",0,1"). In your case, you can use this form

//--- create handle of the indicator Topqw
   ResetLastError();
   handle_Topqw=iCustom(Symbol(),Period(),"Topqw",PRICE_CLOSE);
//--- if the handle is not created 
   if(handle_Topqw==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code 
      PrintFormat("Failed to create handle of the Topqw indicator for the symbol %s/%s, error code %d",
                  Symbol(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early 
      return(INIT_FAILED);
     }

4. CopyBuffer seems to be written correctly.

5. Two-dimensional array can't be passed - make two array-indicator buffers.

 
Vladimir Karputov:


1. Remember that in the INDICATOR, by default, the indicator buffer with index "0" corresponds to the leftmost bar on the chart.

2. There is no "SetIndexBuffer" command in the EA.

3. iCustom is creating a custom indicator, not a buffer request (therefore everything should be written explicitly, not ",0,1"). In your case, you can use this form

4. CopyBuffer seems to be written correctly.

5. You can't pass a two-dimensional array - make two array-indicator buffers.


Thanks for the correction, but I do not understand, if I set explicitly to transfer arrays, how is it formalized? Where do I specify that I need to extract two arrays?

MA_handle=iCustom(Symbol(),Period(),"TopFidCounselor",per,bar); per,bar - же массивы, а данные должны быть imput,
в индикаторе записываю в массивы
   SetIndexBuffer(0,per,INDICATOR_CALCULATIONS);
   SetIndexBuffer(1,bar,INDICATOR_CALCULATIONS);

если я сделаю такую запись
int OnCalculate(
...
  {
//--------------------------------------------------------------
  for ( int i = 0; i < rates_total; i ++ ) per[i] = price[i];  -
//--------------------------------------------------------------
ТО СОВЕТНИК РАБОТАЕТ БЕЗ ОШИБКИ
а если такую
//----------------------------------------------------------------
      for(int b=1; b<200; b++) //отбор по х			-
        {							-
         for(int p=1; p<200; p++) // отбор по у			-
           {							-
            if(arrayZ[6][p][b]>0||arrayZ[6][p][b]<0)		-
            {							-
             per[b]=p;						-
             bar[b]=b;						-
            }							-
           }							-
        }							-
//----------------------------------------------------------------
ТО ОШИБКА код 4002

I've looked throughIndicatorCreate(), could you please tell me how, otherwise it will take me weeks to figure it out, and I've got so little left to finish the thought block. I have to go to taiga soon to spend the summer with bees foraging, so I want to check the idea before departure, so I won't have any illusions.
 

Is what I use in theINDICATOR_CALCULATIONS indicator correct?

   SetIndexBuffer(0,per,INDICATOR_CALCULATIONS);
 

Error 4002 is resolved.

only it is not clear where to write the array to be extracted?

   int copy=CopyBuffer(MA_handle,0,0,bars,per); //per?
 
Top2n:

Error 4002 is resolved.

only it is not clear where to write the array to be extracted?


The arrayper is declared in the EA, in the procedure in which you do the copying. It must be a dynamic array (declared as [] - without dimensionality).
Reason: