新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 - 页 222

 

请帮助。我无法理解for()循环,所有的时间都在更新后,因为偏移量(iMA(NULL,PERIOD_M1,1,1,MODE_SMA,PRICE_OPEN,i))指示器重绘!


//+------------------------------------------------------------------+
//|                                                         help.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+

#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property strict
#include <MovingAverages.mqh>
//--- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property   indicator_color1  clrSilver
#property   indicator_color2  clrRed
#property   indicator_width1  2

//--- indicator parameters
input int SignalSMA=8;            // Signal SMA Period
//--- indicator buffers
double    ExtBuffer[];
double    ExtSignalBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   IndicatorDigits(Digits+1);
//--- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_LINE);
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtBuffer);
   SetIndexBuffer(1,ExtSignalBuffer);

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
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[])
  {
   int i,limit;
//--- last counted bar will be recounted
   limit=rates_total-prev_calculated;
   if(prev_calculated>0)
      limit++;
//--- counted in the 1-st buffer
   for(i=0;i<limit;i++)
      ExtBuffer[i]=(
                    iMA(NULL,PERIOD_CURRENT,1,0,MODE_SMA,PRICE_HIGH,i)
                    +iMA(NULL,PERIOD_M1,1,1,MODE_SMA,PRICE_OPEN,i)
                    );
//--- signal line counted in the 2-nd buffer
   SimpleMAOnBuffer(rates_total,prev_calculated,0,SignalSMA,ExtBuffer,ExtSignalBuffer);
//--- done
   return(rates_total);
  }
//+------------------------------------------------------------------+

事先非常感谢。

 
Alexey Viktorov:

在我看来,这种做法根本就不符合逻辑。为什么要定义星期几呢?如果条件是 "今天不要开出超过xxx的订单",那么今天是什么日子有什么区别呢?

对我来说,计算今天开的订单并指定相应的条件似乎更符合逻辑。

条件中没有订单开启的日期。


如果你知道,请写出如何做)
我不明白如何确保在任何给定的一天里,全天没有超过n次的订单 被打开。

 
cripple:

请帮助。我无法理解for()循环,所有的时间都在更新后,因为偏移量(iMA(NULL,PERIOD_M1,1,1,MODE_SMA,PRICE_OPEN,i))指示器重绘!


我预先感谢你。

MAs有不同的TF。 你需要将较高的时间框架融入M1的TF中,也就是说,用不同的点数计算两次MAs。在这种情况下,较早时期的一个相同数值将被添加到较晚时期的不同数值中。

如果你通过i看,你会得到,例如,10个D1期的蜡烛和10个M1期的蜡烛。从逻辑上讲是有问题的....

还有一点,如果指标设置在M1上,很可能不需要重新调整就可以工作。

 
Renat Akhtyamov:

你必须将较高的时间框架与M1 TF相匹配,即用不同的点数计算两次MAs。

通过i,你现在正在采取例如10个D1期的蜡烛和10个M1期的蜡烛。从逻辑上讲是有问题的....

是的,你是对的,但我的思想还不足以理解如何使M1正确计数。
 
cripple:
是的,你是对的,但我的头脑仍然不足以弄清楚如何让M1正确计数。

此外,我需要将M1与更高的时间框架同步,因为M5的1个小节不一定对应于M1的5个蜡烛,可能是4个或1个。

 
cripple:
是的,你是对的,但我的头脑仍然不足以理解如何使M1正确计数。

尝试

int  Bars(
   string           symbol_name,     // имя символа
   ENUM_TIMEFRAMES  timeframe,       // период
   datetime         start_time,      // с какой даты
   datetime         stop_time        // по какую дату
   );

第i条的时间,并把所得的条数代替i。

 
你能不能告诉我,你能不能在mt4终端中使用键盘滚动浏览打开的交易?
 
LRA:
亲爱的novikov433!教你编程,或者给你写一个免费的专家顾问,或者两者都有!!作为交换,教我如何将亏损的订单转化为不亏损 的。你可以用一个简单的例子。我给我妻子下了一个命令(命令):清晨在市场上买一桶土豆,到10点钟(基本面分析)价格上涨--卖出。但有时一车土豆在10:30到达(新闻)。而价格(在新闻上)立即下降,并持续到一天结束,甚至是整个星期。我设置了止损--如果价格下降了10卢布,我就尽快卖出(按市场价格)。如何改变订单,以避免损失。如果对这个变体感兴趣--请将您的电子邮件发给我们。
问题是,市场略微向所需的一面发展,然后又回去了,所以你需要在收支平衡的情况下关闭交易,并打开它进行逆转。我一开始就对它上瘾了。我又一次相信用手交易是胡说八道。我怎么能理解为什么我需要在我的代码中写这么多的组件呢?
 
Alexey Viktorov:

尝试

的时间,并将所得的条形图编号代替i。


你想过这样的事情吗?
//+------------------------------------------------------------------+
//|                                                         help.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+

#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Moving Averages Convergence/Divergence"
#property strict
#include <MovingAverages.mqh>
//--- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property   indicator_color1  clrSilver
#property   indicator_color2  clrRed
#property   indicator_width1  2

//--- indicator parameters
input int SignalSMA=8;            // Signal SMA Period
//--- indicator buffers
double    ExtBuffer[];
double    ExtSignalBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   IndicatorDigits(Digits+1);
//--- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_LINE);
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtBuffer);
   SetIndexBuffer(1,ExtSignalBuffer);

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
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[])
  {
   int i,limit;
//--- last counted bar will be recounted
   limit=rates_total-prev_calculated;
   if(prev_calculated>0)
      limit++;
//--- counted in the 1-st buffer
   for(i=0;i<limit;i++)
     {
      int bars=iBarShift(Symbol(),PERIOD_M1,iTime(Symbol(),PERIOD_CURRENT,i),false);
      ExtBuffer[i]=(
                    iMA(NULL,PERIOD_CURRENT,1,0,MODE_SMA,PRICE_HIGH,i)
                    +iMA(NULL,PERIOD_M1,1,1,MODE_SMA,PRICE_OPEN,bars)
                    );
      Print(bars);
     }
//--- signal line counted in the 2-nd buffer
   SimpleMAOnBuffer(rates_total,prev_calculated,0,SignalSMA,ExtBuffer,ExtSignalBuffer);
//--- done
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
ax00071:
谢谢你的关注 ))我是个傻瓜......在成交时,我的条件是在周五22:00成交,没有任何附加条件来检查交易类型。这笔交易本身在几个小时前就完成了。好了,当晚上22:00到来时,专家顾问开始发送订单,关闭一个已经关闭的订单......。
你几乎不应该称自己为植物人。如果你已经成功地找到、理解并纠正了这样的错误,你就越来越接近程序员的水平了!