Questions from a "dummy" - page 78

 
Interesting:

I think it would be easier to re-do the Expert Advisor or work on it with a file.

I think it would be easier to describe in full what you want from the Expert Advisor and provide all code created by VISARD.

For example, I need an Expert Advisor that opens trades by crossing the price of an Envelopes indicator. This is what I got:

//+------------------------------------------------------------------+
//|                                                    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();
  }
//+------------------------------------------------------------------+
 
Comrades developers, please explain what I should change in the code, so that after a buy/sell signal a position is opened and closed once and that's it, the Expert Advisor does not open positions until the next signal. Especially it happens when the system consists of multiple indicators. The Expert Advisor is always in position. It closes one on take or stop, and immediately opens another one.
 

Question about indicators.

There is such a construction of input parameters in 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[])
  {
     ...
  }

All this fun is tied strictly to the current timeframe, therefore to get to the similar data of another timeframe, you can, for example, call the handle of the required built-in standard indicator on the desired timeframe:

handle=iGator(_Symbol, PERIOD_W1);

and then copy the necessary data into the buffers through the Copy-functions variations.

Everything would be fine, but there is a need to use rates_total and prev_calculated on different from current timeframes. And there are none of them, as far as I understand. Where and how can we get them if they obviously do not correspond to the current timeframe?

Of course, there is a clear explanation in the help:

"We need to note the relation between the value returned by OnCalculate() and the second input parameter prev_calculated. The parameter prev_calculated, when the function is called, contains the valuereturned by OnCalculate() on the previous call. This allows for economical algorithms for calculating the custom indicator in order to avoid repeated calculations for those bars that haven't changed since the previous call of this function.

For this, it is usually enough to return the value of the rates_total parameter, which contains the number of bars in the current function call. If since the last call of OnCalculate() price data were changed (a deeper history was pumped or history blanks were filled), then the value of the input parameter prev_calculated will be set to zero by the terminal."

So, do we really have to manually implement our own analogues of rates_total and prev_calculated for other timeframes using the principle described above? Or is there something ready to be used? Well, for example, like this:

rates_total = BarsCalculated(handle);
or take the returned value of the Copy-function. But with prev_calculated there would be, to put it mildly, not so easy... How to implement it correctly?
 

I read Rosh's article about the mathsat https://www.mql5.com/ru/articles/1492.

There is a possibility to connect such analysis for example in OnTester() ?

Are there any ready-made solutions freely available?

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

I read Rosh's article about the mathsat https://www.mql5.com/ru/articles/1492.

There is a possibility to connect such analysis for example in OnTester() ?

Are there any ready-made solutions freely available?

Yes - Testing statistics
 
Rosh:
Yes - Testing Statistics
Thank you.
 

Can you advise?

I selected a deal from the history,the direction of the deal is "pivot" (in/out), then I determine the volume of the deal HistoryDealGetDouble(ticket,DEAL_VOLUME).
I get the total volume, but how to know which volume I closed and which opened? I want to know what volume I closed and what volume I opened. Thank you.

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

I've written a linear regression. Are you planning to add such a thing to the terminal, and even to display it on the chart in the tester?

And as understood to calculate the Z-count is required to independently calculate the total number of positive and negative series?

 
Can MetaTrader 5 be attached to this exchangehttps://mtgox.com/ ?
 
Karlson:

And I also understand that calculating the Z-count requires calculating the total number of positive and negative series by yourself?

Yes, by myself. Basically, I can post the code in MQL5 to calculate it.