来自一个 "傻瓜 "的问题 - 页 78

 
Interesting:

我认为重新做专家顾问或用文件来处理会更容易。

我认为全面描述你对专家顾问的要求并提供由VISARD创建的所有代码会更容易。

例如,我需要一个专家顾问,通过跨越信封指标的价格来开启交易。这就是我得到的东西。

//+------------------------------------------------------------------+
//|                                                    envelopes.mq5 |
//|                        Copyright 2011, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Include                                                          |
//+------------------------------------------------------------------+
#include <Expert\Expert.mqh>
//--- available signals
#include <Expert\Signal\SignalEnvelopes.mqh>
//--- available trailing
#include <Expert\Trailing\TrailingNone.mqh>
//--- available money management
#include <Expert\Money\MoneyFixedLot.mqh>
//+------------------------------------------------------------------+
//| Inputs                                                           |
//+------------------------------------------------------------------+
//--- inputs for expert
input string             Expert_Title              ="envelopes"; // Document name
ulong                    Expert_MagicNumber        =28572;       // 
bool                     Expert_EveryTick          =false;       // 
//--- inputs for main signal
input int                Signal_ThresholdOpen      =10;          // Signal threshold value to open [0...100]
input int                Signal_ThresholdClose     =10;          // Signal threshold value to close [0...100]
input double             Signal_PriceLevel         =0.0;         // Price level to execute a deal
input double             Signal_StopLevel          =50.0;        // Stop Loss level (in points)
input double             Signal_TakeLevel          =50.0;        // Take Profit level (in points)
input int                Signal_Expiration         =4;           // Expiration of pending orders (in bars)
input int                Signal_Envelopes_PeriodMA =240;         // Envelopes(240,0,MODE_LWMA,...) Period of averaging
input int                Signal_Envelopes_Shift    =0;           // Envelopes(240,0,MODE_LWMA,...) Time shift
input ENUM_MA_METHOD     Signal_Envelopes_Method   =MODE_LWMA;   // Envelopes(240,0,MODE_LWMA,...) Method of averaging
input ENUM_APPLIED_PRICE Signal_Envelopes_Applied  =PRICE_CLOSE; // Envelopes(240,0,MODE_LWMA,...) Prices series
input double             Signal_Envelopes_Deviation=0.15;        // Envelopes(240,0,MODE_LWMA,...) Deviation
input double             Signal_Envelopes_Weight   =1.0;         // Envelopes(240,0,MODE_LWMA,...) Weight [0...1.0]
//--- inputs for money
input double             Money_FixLot_Percent      =10.0;        // Percent
input double             Money_FixLot_Lots         =0.01;        // Fixed volume
//+------------------------------------------------------------------+
//| Global expert object                                             |
//+------------------------------------------------------------------+
CExpert ExtExpert;
//+------------------------------------------------------------------+
//| Initialization function of the expert                            |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Initializing expert
   if(!ExtExpert.Init(Symbol(),PERIOD_H4,Expert_EveryTick,Expert_MagicNumber))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing expert");
      ExtExpert.Deinit();
      return(-1);
     }
//--- Creating signal
   CExpertSignal *signal=new CExpertSignal;
   if(signal==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating signal");
      ExtExpert.Deinit();
      return(-2);
     }
//---
   ExtExpert.InitSignal(signal);
   signal.ThresholdOpen(Signal_ThresholdOpen);
   signal.ThresholdClose(Signal_ThresholdClose);
   signal.PriceLevel(Signal_PriceLevel);
   signal.StopLevel(Signal_StopLevel);
   signal.TakeLevel(Signal_TakeLevel);
   signal.Expiration(Signal_Expiration);
//--- Creating filter CSignalEnvelopes
   CSignalEnvelopes *filter0=new CSignalEnvelopes;
   if(filter0==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating filter0");
      ExtExpert.Deinit();
      return(-3);
     }
   signal.AddFilter(filter0);
   filter0.PatternsUsage(2);
//--- Set filter parameters
   filter0.PeriodMA(Signal_Envelopes_PeriodMA);
   filter0.Shift(Signal_Envelopes_Shift);
   filter0.Method(Signal_Envelopes_Method);
   filter0.Applied(Signal_Envelopes_Applied);
   filter0.Deviation(Signal_Envelopes_Deviation);
   filter0.Weight(Signal_Envelopes_Weight);
//--- Creation of trailing object
   CTrailingNone *trailing=new CTrailingNone;
   if(trailing==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating trailing");
      ExtExpert.Deinit();
      return(-4);
     }
//--- Add trailing to expert (will be deleted automatically))
   if(!ExtExpert.InitTrailing(trailing))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing trailing");
      ExtExpert.Deinit();
      return(-5);
     }
//--- Set trailing parameters
//--- Creation of money object
   CMoneyFixedLot *money=new CMoneyFixedLot;
   if(money==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating money");
      ExtExpert.Deinit();
      return(-6);
     }
//--- Add money to expert (will be deleted automatically))
   if(!ExtExpert.InitMoney(money))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing money");
      ExtExpert.Deinit();
      return(-7);
     }
//--- Set money parameters
   money.Percent(Money_FixLot_Percent);
   money.Lots(Money_FixLot_Lots);
//--- Check all trading objects parameters
   if(!ExtExpert.ValidationSettings())
     {
      //--- failed
      ExtExpert.Deinit();
      return(-8);
     }
//--- Tuning of all necessary indicators
   if(!ExtExpert.InitIndicators())
     {
      //--- failed
      printf(__FUNCTION__+": error initializing indicators");
      ExtExpert.Deinit();
      return(-9);
     }
//--- ok
   return(0);
  }
//+------------------------------------------------------------------+
//| Deinitialization function of the expert                          |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ExtExpert.Deinit();
  }
//+------------------------------------------------------------------+
//| "Tick" event handler function                                    |
//+------------------------------------------------------------------+
void OnTick()
  {
   ExtExpert.OnTick();
  }
//+------------------------------------------------------------------+
//| "Trade" event handler function                                   |
//+------------------------------------------------------------------+
void OnTrade()
  {
   ExtExpert.OnTrade();
  }
//+------------------------------------------------------------------+
//| "Timer" event handler function                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
   ExtExpert.OnTimer();
  }
//+------------------------------------------------------------------+
 
开发人员同志们,请解释一下我应该在代码中做些什么,以便在买入/卖出信号后,开仓和平仓一次,仅此而已,专家顾问在下一个信号前不会开仓。特别是当系统由多个指标组成时,这种情况会发生。专家顾问始终处于位置。它在采取或停止时关闭一个,并立即打开另一个。
 

关于指标的问题。

OnCalculate 中有这样一种输入参数的构造。

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[])
  {
     ...
  }

所有这些乐趣都与当前的时间框架严格相关,因此要获得另一个时间框架的类似数据,你可以,例如,在所需的时间框架上调用所需的内置标准指标的手柄。

handle=iGator(_Symbol, PERIOD_W1);

然后通过Copy-functions的变化将必要的数据复制到缓冲区。

所有这些都很好,但有必要在与当前不同的时间框架上使用 rates_total 和 prev_calculated。而据我所知,没有一个人是这样的。如果它们显然不符合当前的时间框架,我们在哪里以及如何才能得到它们?

当然,在帮助中也有明确的解释。

"我们需要注意OnCalculate()返回的值和第二个输入参数prev_calculated之间的关系。 当函数被调用时,参数prev_calculated包含了 OnCalculate()在 上一次 调用 返回的 值。 这允许在计算自定义指标 时采用经济的算法,以避免对那些自上次调用此函数以来没有变化的条形图进行重复计算。

为此,通常只需返回rate_total参数的值即可,该参数包含当前函数调用中的条数。如果自上次调用OnCalculate()后,价格数据发生了变化(抽出了更深的历史数据或填补了历史空白),那么输入参数prev_calculated的值将被终端设置为零。"

那么,我们是否真的要根据上述原则,为其他时间段手动实现我们自己的 rates_total 和 prev_calculated 类似物?还是有现成的东西可供使用?嗯,比如说,像这样。

rates_total = BarsCalculated(handle);
或采取复制函数的返回值。但用prev_calculated的话,说得不好听一点,就不那么容易了。如何正确地实施它?
 

我读了Rosh关于数学的文章,https://www.mql5.com/ru/articles/1492。

是否有可能在OnTester()中连接这样的分析?

是否有任何现成的解决方案可以免费使用?

Математика в трейдинге. Оценка результатов торговых сделок - Статьи по MQL4
  • www.mql5.com
Математика в трейдинге. Оценка результатов торговых сделок - Статьи по MQL4: автоматическая торговля
 
Karlson:

我读了Rosh关于数学的文章,https://www.mql5.com/ru/articles/1492。

是否有可能在OnTester()中连接这样的分析?

是否有任何现成的解决方案可以免费使用?

是--测试统计
 
Rosh:
是--测试统计
谢谢你。
 

你能提供建议吗?

我从历史上选择了一个交易,交易的方向是"枢轴"(进/出),然后我确定了交易的数量 HistoryDealGetDouble(ticket,Deal_VOLUME)。
我得到了总的交易量,但如何知道我关闭了哪些交易量,打开了哪些交易量?我想知道我关闭的是什么量,我打开的是什么量。 谢谢你。

Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства сделок
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства сделок
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Свойства сделок - Документация по MQL5
 
Rosh:
是--测试统计

我已经写了一个线性回归。 你是否打算把这样的东西添加到终端,甚至在测试器的图表上显示出来?

而据了解,计算Z数是需要独立计算正负数列的总数的?

 
MetaTrader 5可以连接到这个交易所吗https://mtgox.com/ ?
 
Karlson:

而且我还了解到,计算Z数需要自己计算正数和负数的总数?

是的,由我自己来。基本上,我可以在MQL5中发布代码来进行计算。