Questions from Beginners MQL5 MT5 MetaTrader 5 - page 168

 
TheXpert:
There is no "close order" event in the terminal. You should use a script or an Expert Advisor. As shown above.

Hmm. what is the event called when you press the "cross" to close an open order?

That's what you need to "assign" a sound to

 
paladin800:

Thank you very much!

I also found my mistake. The point is that the "Buy_close" condition, gives the program a task to execute the deal, and the check for the position is "Buy_opened".

The deal is closed and the "Buy_close" condition coincides, therefore an error is generated.

Made the condition as follows:

if(Buy_close && Buy_opened==true)
 
trora:

this is the action to "assign" the sound to

Good luck :)
 

I can't get MA lines with an offset of -+0.30%.

There isno problem with calling the moving average from which the offset will occur. But, there is no way to get offset lines.

Basic code:

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
#property  indicator_type1   DRAW_LINE
#property  indicator_color1  clrMediumVioletRed
#property  indicator_style1  STYLE_SOLID
#property  indicator_label1  ""
#property  indicator_type2   DRAW_LINE
#property  indicator_color2  clrRed
#property  indicator_style2  STYLE_SOLID
#property  indicator_label2  "Sell TP
input int Period_ = 34;         //Период
int ma1Handle;
double ma1Val[]; 
double ExtMapBuffer1[];
double ExtMapBuffer2[]
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
SetIndexBuffer(0,ExtMapBuffer1,INDICATOR_DATA);
SetIndexBuffer(1,ExtMapBuffer2,INDICATOR_DATA)
ma1Handle=iMA(_Symbol,_Period,Period_,0,MODE_EMA,PRICE_CLOSE); 
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 &spread[])
  {
CopyBuffer(ma1Handle,0,0,2,ma1Val);
ArraySetAsSeries(ma1Val,true);
int bars=Bars(_Symbol,_Period);
for(int i=0;i<bars;i++)
{
ExtMapBuffer2[i]=ma1Val[0] - ((ma1Val[0]/100)*0.3);//ЗДЕСЬ НЕ ПОЛУЧАЕТСЯ ПОЛУЧИТЬ ЛИНИЮ
}
//---   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
#property indicator_label2  "Sell TP
Where is the second inverted comma.
 
CopyBuffer(ma1Handle,0,0,2,ma1Val);
This string must be in a loop and indexed.
 
sandex:
This string should be in a loop and indexed.

How do I index a string? Trying this, the error comes out

ArraySetAsSeries(ma1Val,true);
int bars=Bars(_Symbol,_Period);
for(int i=0;i<bars;i++)
    {
    CopyBuffer(ma1Handle,0,0,2,ma1Val[i]);
    ExtMapBuffer2[i]=ma1Val[i] - ((ma1Val[i]/100)*0.3);//ЗДЕСЬ НЕ ПОЛУЧАЕТСЯ ПОЛУЧИТЬ ЛИНИЮ
    }
 

Indexing should be done like this:

CopyBuffer(ma1Handle,0,i,1,ma1Val);
 

This line should look like this:

ExtMapBuffer2[i]=ma1Val[0] - ((ma1Val[0]/100)*0.3);
 

Declare the array to be static, of size 1:

double ma1Val[1];
Reason: