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

 
kopeyka2:

暂时

其他(非本地)时间框架


而在一般情况下,你是无视帮助的。我已经不在对话范围内了。我已经给了你所有的数据来使代码正常工作,但你不想听,所以你用自己的方式做事。遗憾的是时间问题。
 
Artyom Trishkin:
总之,你忽略了帮助。我已经不在对话中了。我已经给了你所有的数据,让代码正常工作,但你不想听,用自己的方式做事。遗憾的是时间问题。

感谢您的关注和时间....我想我还没有搞清楚......关于车轮和马达,我同意。

我可能会放弃掌上电脑,计算iClose 平均值的平均期。

 
kopeyka2:

感谢您的关注和时间....我想我还没有搞清楚......关于车轮和马达,我同意。

我可能会放弃掌上电脑,计算iClose平均值的平均期。

//+------------------------------------------------------------------+
//|                                                       TestMA.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                                 https://mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://mql5.com"
#property version   "1.00"
#property description "Выводит данные скользящей средней с заданного таймфрейма на любом текущем"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot LWMA
#property indicator_label1  "MA"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input uint                 InpPeriod         =  14;            // MA period
input int                  InpShift          =  0;             // MA shift
input ENUM_MA_METHOD       InpMethod         =  MODE_SMA;      // MA method
input ENUM_APPLIED_PRICE   InpApplierPrice   =  PRICE_CLOSE;   // MA applied price
input ENUM_TIMEFRAMES      InpTimeframe      =  PERIOD_H1;     // LRMA timeframe
//--- indicator buffers
double         BufferMA[];
//--- global variables
//ENUM_TIMEFRAMES   timeframe1;
int            period_ma;
int            shift_ma;
int            handle_ma;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- timer
   EventSetTimer(90);
//--- set global variables
   period_ma=int(InpPeriod<1 ? 1 : InpPeriod);
   shift_ma=InpShift;
   //timeframe1=(InpTimeframe>Period() ? InpTimeframe : Period());
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferMA,INDICATOR_DATA);
//--- setting indicator parameters
   IndicatorSetString(INDICATOR_SHORTNAME,"Any TF MA on current");
   IndicatorSetInteger(INDICATOR_DIGITS,Digits());
//--- setting plot buffer parameters
   string label=TimeframeToString(InpTimeframe)+" "+MethodToString(InpMethod)+"("+(string)period_ma+")";
   PlotIndexSetString(0,PLOT_LABEL,label);
//--- setting buffer arrays as timeseries
   ArraySetAsSeries(BufferMA,true);
//--- create handles
   ResetLastError();
   handle_ma=iMA(NULL,InpTimeframe,period_ma,shift_ma,InpMethod,InpApplierPrice);
   if(handle_ma==INVALID_HANDLE)
     {
      Print("The ",TimeframeToString(InpTimeframe)," iMA(",(string)period_ma,") object was not created: Error ",GetLastError());
      return INIT_FAILED;
     }
//--- get timeframe
   Time(NULL,InpTimeframe,1);
//---
   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[])
  {
//--- Проверка количества доступных баров
   if(rates_total<fmax(period_ma,4)) return 0;
//--- Проверка и расчёт количества просчитываемых баров
   int limit=rates_total-prev_calculated;
   if(limit>1)
     {
      limit=rates_total-1;
      ArrayInitialize(BufferMA,EMPTY_VALUE);
     }
//--- Подготовка данных
   if(Time(NULL,InpTimeframe,1)==0)
      return 0;
   int bars=(InpTimeframe==PERIOD_CURRENT ? rates_total : Bars(NULL,InpTimeframe));
   int count=(limit>1 ? fmin(bars,rates_total) : 1),copied=0;
   copied=CopyBuffer(handle_ma,0,0,count,BufferMA);
   Comment(TimeframeToString(InpTimeframe)," ",MethodToString(InpMethod),": copied=",copied,", count=",count,", bars=",bars,", rates_total=",rates_total);
   if(copied!=count) return 0;
      
//--- Расчёт индикатора
   //for(int i=limit; i>=0 && !IsStopped(); i--)
   //  {
   //   
   //  }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Custom indicator timer function                                  |
//+------------------------------------------------------------------+
void OnTimer()
  {
   Time(NULL,InpTimeframe,1);
  }
//+------------------------------------------------------------------+
//| Возвращает Time                                                  |
//+------------------------------------------------------------------+
datetime Time(const string symbol_name,const ENUM_TIMEFRAMES timeframe,const int shift)
  {
   datetime array[];
   ArraySetAsSeries(array,true);
   return(CopyTime(symbol_name,timeframe,shift,1,array)==1 ? array[0] : 0);
  }
//+------------------------------------------------------------------+
//| Возвращает наименование таймфрейма                               |
//+------------------------------------------------------------------+
string TimeframeToString(const ENUM_TIMEFRAMES timeframe)
  {
   return StringSubstr(EnumToString(timeframe),7);
  }
//+------------------------------------------------------------------+
//| Возвращает наименование метода МА                                |
//+------------------------------------------------------------------+
string MethodToString(ENUM_MA_METHOD method)
  {
   return StringSubstr(EnumToString(method),5);
  }
//+------------------------------------------------------------------+

删除了一切不必要的东西。

不要忘了,在周末是没有刻度线的,线只在相同的时间段输出--工作的那个和设置中的那个。

如果你在设置中指定的时间框架以外的时间框架上运行,那么在周末没有刻度,你需要用鼠标右键强行刷新图表:刷新,这样线就会被画出来。

 
Artyom Trishkin:

删除了一切不必要的东西。

不要忘了,在周末是没有刻度线的,线将只显示在匹配的时间段--工作时间段和设置中的时间段。

如果你在设置中指定的时间框架以外的时间框架上运行,那么在周末没有刻度,你需要用鼠标右键强行刷新图表:刷新,这样线就会被画出来。

感谢多次!!1我整天都在瞎折腾....,我的眼睛被缝起来了。再次感谢
 

大家下午好。

 
明白了,谢谢你。
 
大家下午好。
面临着时间不匹配的问题,请帮助解决。
试图弄清楚为什么订单会晚点,我在我的EA中记录调试信息,它是绝对正确的,你可以在截图中看到它。我注意到,信息的时间比条形图的开始时间(TF=M30)多出4.5小时,正是这个滞后导致了订单的延迟。也就是说,根据调试信息,我看到进入市场的条件已经得到满足,例如,条形图上的时间是10:00,但订单放在时间为14:30的条形图上。这是我第一次遇到这种情况。该怎么做?
附加的文件:
MT5dataerror.jpg  724 kb
 

在Youtube上发现了追踪止损的代码,如何使用它?

#include <Trade\Trade.mqh> 
CTrade trade;

void OnTick()
  {
    double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
    
         if(PositionsTotal()<2)
    
    trade.Buy(0.10,NULL,Ask,(Ask-1000 * _Point),(Ask+500 * _Point),NULL);
    
    CheckTrailingStop(Ask);
   
  }
void   CheckTrailingStop(double Ask)
  {
     double SL = NormalizeDouble(Ask - 150 * _Point,_Digits);
     
     for (int i=PositionsTotal()-1; i>=0; i--)
     {
     string symbol=PositionGetSymbol(i);
     if (_Symbol==symbol)
     {
     ulong PositionTicket=PositionGetInteger(POSITION_TICKET);
     
     double CurrentStopLoss=PositionGetDouble(POSITION_SL);
     if (CurrentStopLoss<SL)
     {
       trade.PositionModify(PositionTicket,(CurrentStopLoss + 10*_Point),0);
     }
   }
  }   
}
 
Vladimir Baskakov:

在Youtube上发现了追踪止损的代码,如何使用它?

这种拖网只用于购买,而且实施得很差,不能使用。

 
Nikolay Khrushchev:

这个拖网只用于购买,而且执行得很差,不能使用。

好的,谢谢你。
原因: