Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1302

 
User_mt5:

Vladimir Karputov, and me?)

I can't say for sure, but try 0.0


Added: It seems that you cannot cancel 'INDICATOR_MINIMUM' and 'INDICATOR_MAXIMUM' with MQL5.

 
Vladimir Karputov:

I can't say for sure, but try 0.0


Added: It seems that 'INDICATOR_MINIMUM' and 'INDICATOR_MAXIMUM' cannot be cancelled by MQL5.

Alas...

Thank you for your reply.

(same problem with levels, actually; but solved by setting the number of levels)

 
User_mt5:

Alas...

Thanks for the reply.

(The problem with levels is actually the same; but solved by setting the number of levels)

Experiment and everything will work out.

 
User_mt5:


I compared the properties that the chart saves (using'Stochastic Oscillator' indicator as an example)



<indicator>
name=Stochastic Oscillator
path=
apply=0
show_data=1
scale_inherit=0
scale_line=0
scale_line_percent=50
scale_line_value=0.000000
scale_fix_min=1
scale_fix_min_val=0.000000
scale_fix_max=1
scale_fix_max_val=100.000000
expertmode=0
fixed_height=-1


<indicator>
name=Stochastic Oscillator
path=
apply=0
show_data=1
scale_inherit=0
scale_line=0
scale_line_percent=50
scale_line_value=0.000000
scale_fix_min=0
scale_fix_min_val=-10.500000
scale_fix_max=0
scale_fix_max_val=110.500000
expertmode=0
fixed_height=-1


This is clearly a 'bool' type property, but there is no access to this property from MQL5 language.

 
Vladimir Karputov:

I compared the properties that the chart saves (using'Stochastic Oscillator' indicator as an example)

It is clearly a 'bool' type property but there is no access to this property from MQL5.

Yes, alas.

Thanks again)

 

There is a problem. Using the function (see below), we can obtain TakeProfit and StopLoss values by position ID from the history (i.e. when the position is already closed), this function works in real time, but in the strategy tester, it cannot find TakeProfit and StopLoss, because it does not see historical orders that set stops (importantly, the stops are set after the position opening)

Question: How can I use the Strategy Tester to find out the TP/Loss for a closed position based on a ticket?

#include <Trade\DealInfo.mqh>
#include <Trade\HistoryOrderInfo.mqh>

CDealInfo deal;
CHistoryOrderInfo ord;


void GetPosStops(ulong ticket, int& tp, int& sl, double& lot){
   HistorySelectByPosition(ticket);
   tp=0;sl=0;
   double open=0, tp_=0, sl_=0;
   string symbol="";
   ENUM_DEAL_TYPE type=-1;
   for(int i=0; i<HistoryDealsTotal(); i++){
      if(!deal.SelectByIndex(i))continue;
      if(deal.Entry() ==DEAL_ENTRY_IN){
         open=deal.Price();
         symbol=deal.Symbol();
         type=deal.DealType();
         lot=deal.Volume();
         break;
      }
   }
   for(int i=0; i<HistoryOrdersTotal(); i++){
      if(!ord.SelectByIndex(i))continue;
      if(tp_==0)tp_=ord.TakeProfit();
      if(sl_==0)sl_=ord.StopLoss();
      if(tp_>0 && sl_>0)break;
   }
   if(symbol !=""){
      double coef=type==DEAL_TYPE_BUY ? 1:-1;
      double point=SymbolInfoDouble(symbol,SYMBOL_POINT);
      if(tp_>0 && coef*tp_>coef*open)
         tp=(int)(MathAbs(tp_-open)/point);
      if(sl_>0 && coef*sl_<coef*open)
         sl=(int)(MathAbs(sl_-open)/point);   
   }
}
 
Hello all !
I'm just trying to program EAs, and I want to start by writing a statistical spread collector.
I mean, what would I like it to do? In the tester, an EA starts and collects data on tick history for a certain period of time, e.g. ten days.
And then it generates the following data in csv or xlsx file:
Average spread for a period of time: 00:00 - 09:00 on the server, 09:00 - 18:00, 18:00 - 00:00 (for all ten days), maximum spread for this time, minimum spread and average spread of currency pair for the entire period of ten days.
I am really tired of collecting it by hand.

I know that there are programs, which kind of do it themselves... But I want my own, as a workout.
Maybe respected connoisseurs can tell me where to start? And is it even possible to write such a program?

Thanks in advance to all who replied and were sympathetic to a newcomer.
 

Hi all. Maybe someone has a ready piece of code. There are 2 parameters, deposit=3000 and lot 0.01 i.e. with deposit 3000 lot will be 0.01, now strictly at doubling i.e. when depo will be 6000 lot will be 0.02 at 9000 will be 0.03 how to do it?

 
Pavel Komarovsky:

Hi all. Maybe someone has a ready piece of code. There are 2 parameters, deposit=3000 and lot 0.01 i.e. with deposit 3000 lot will be 0.01, now strictly at doubling i.e. when depo will be 6000 lot will be 0.02 at 9000 will be 0.03 how to do it?

It is roughly like this:

//+------------------------------------------------------------------+
//|                                                     Script 1.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//---
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   double start_deposit=3000;
   double start_lot=0.01;
   double deposit=start_deposit;
   for(int i=0; i<10; i++)
     {
      
      double d=MathFloor(deposit/start_deposit);
      Print(i,"#: ,deposit ",DoubleToString(deposit,2),", d ",DoubleToString(d*start_lot,2));
      //---
      deposit=deposit+start_deposit*0.55;
     }
  }
//+------------------------------------------------------------------+

Result:

2021.05.04 09:03:15.246 Script 1 (EURUSD,H1)    0#: ,deposit 3000.00, d 0.01
2021.05.04 09:03:15.246 Script 1 (EURUSD,H1)    1#: ,deposit 4650.00, d 0.01
2021.05.04 09:03:15.246 Script 1 (EURUSD,H1)    2#: ,deposit 6300.00, d 0.02
2021.05.04 09:03:15.246 Script 1 (EURUSD,H1)    3#: ,deposit 7950.00, d 0.02
2021.05.04 09:03:15.246 Script 1 (EURUSD,H1)    4#: ,deposit 9600.00, d 0.03
2021.05.04 09:03:15.246 Script 1 (EURUSD,H1)    5#: ,deposit 11250.00, d 0.03
2021.05.04 09:03:15.246 Script 1 (EURUSD,H1)    6#: ,deposit 12900.00, d 0.04
2021.05.04 09:03:15.246 Script 1 (EURUSD,H1)    7#: ,deposit 14550.00, d 0.04
2021.05.04 09:03:15.246 Script 1 (EURUSD,H1)    8#: ,deposit 16200.00, d 0.05
2021.05.04 09:03:15.246 Script 1 (EURUSD,H1)    9#: ,deposit 17850.00, d 0.05
Files:
Script_1.mq5  3 kb
 

Good time,

Please help me to find a bug... I copy bar values (BarsCount) from the indicator buffer in the script, then I loop around values, detect a signal and print them to Print(); it seems to be simple, but it's not so easy... I get all signals as I wanted except for crossing zero line.

CROSSOVER_OR_REVERSE

Maybe the script shouldn't do it that way? I attached the code and a screenshot of the log... Thanks a lot!

//+------------------------------------------------------------------+
//|                                                B_O_P_Signals.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
enum enMaTypes
  {
   ma_sma,    // Simple moving average
   ma_ema,    // Exponential moving average
   ma_smma,   // Smoothed MA
   ma_lwma    // Linear weighted MA
  };
  
input int       inpSmoothPeriod = 14;       // Result smoothing period
input enMaTypes inpSmoothMethod =  ma_sma;  // Result smoothing type
input double    inpLevelUp      =  0.2;     // Level up
input double    inpLevelDown    = -0.2;     // Level down
input int       BarsCount       = 100;

double Mid_line[1] = {0.0};
int handle=0;
double TREND_VAL[];

void OnStart()
  {
      handle = iCustom(_Symbol,PERIOD_CURRENT,"Balance of Market Power",inpSmoothPeriod,inpSmoothMethod,inpLevelUp,inpLevelDown);
      
      CopyBuffer(handle,2,0,BarsCount,TREND_VAL);
      
      ArraySetAsSeries(TREND_VAL,true);
      
      string Signal ="";
      
        for (int i=ArraySize(TREND_VAL)-1; i>=0; i--)
        {
           int k=1;
            if(TREND_VAL[i] != EMPTY_VALUE && TREND_VAL[i] > Mid_line[0] && TREND_VAL[i] > inpLevelUp)
            
               Signal = "TREND_UP";
            else if (TREND_VAL[i] != EMPTY_VALUE && TREND_VAL[i] > Mid_line[0] && TREND_VAL[i] < inpLevelUp)
            
               Signal = "TREND_UP_ROLLBACK_OR_FLAT";
            else if(TREND_VAL[i] >= Mid_line[0] && TREND_VAL[i+k] <= Mid_line[0])
            
               Signal ="CROSSOVER_OR_REVERSE_UP";
            
            else if (TREND_VAL[i] != EMPTY_VALUE && TREND_VAL[i] < Mid_line[0] && TREND_VAL[i] < inpLevelDown)
            
               Signal = "TREND_DN";
            else if (TREND_VAL[i] != EMPTY_VALUE && TREND_VAL[i] < Mid_line[0] && TREND_VAL[i] > inpLevelDown)
            
               Signal = "TREND_DN_ROLLBACK_OR_FLAT";
            else if(TREND_VAL[i] < Mid_line[0] && TREND_VAL[i+k] > Mid_line[0])
            
               Signal = "CROSSOVER_OR_REVERSE_DN";
            else Signal = "UNKNOWN_SIGNAL";
            
            Print(string(i),"_", Signal);
        }
      
   
  }
//+------------------------------------------------------------------+
Files:
Question.png  150 kb
Reason: