初学者的问题 MQL5 MT5 MetaTrader 5 - 页 168

 
TheXpert:
终端中没有 "平仓 "事件。你应该使用一个脚本或一个专家顾问。如上图所示。

嗯,当你按下 "十字 "来关闭一个未平仓的订单时,事件被称为什么?

这就是你需要 "分配 "一个声音的原因

 
paladin800:

非常感谢您!

我也发现了我的错误。重点是,"Buy_close "条件,给了程序一个执行交易的任务,而对该位置的检查是 "Buy_opened"。

交易结束后与 "Buy_close "条件重合,因此产生了一个错误。

做了如下的条件。

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

这是一个 "分配 "声音的动作。

好运 :)
 

我无法得到偏移量为-+0.30%的MA线。

调用将发生偏移 移动平均线没有问题的。 但是,没有办法获得偏移线

基本代码。

#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
哪里是第二个倒置的逗号。
 
CopyBuffer(ma1Handle,0,0,2,ma1Val);
这个字符串必须是在一个循环中,并有索引。
 
sandex:
这个字符串应该是在一个循环中,并且有索引。

如何对一个字符串进行索引? 试着这样做,错误就出来了

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);//ЗДЕСЬ НЕ ПОЛУЧАЕТСЯ ПОЛУЧИТЬ ЛИНИЮ
    }
 

索引应该这样做。

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

这一行应该看起来像这样。

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

声明该数组为静态,大小为1。

double ma1Val[1];