Questions from Beginners MQL5 MT5 MetaTrader 5 - page 608

 

new-rena:
Ок. В каком месте? В конце месяца? Я по календарику проверял...

//+------------------------------------------------------------------+
//|                                                  WeekOfMonth.mq4 |
//|                                                         new-rena |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "new-rena"
#property link      ""
#property version   "1.00"
#property strict
//--------------------------
double DayOfMonth,WeekOfMonth;
int DayOfWeeks,MonthOfYear,PrevMonth,Delta=0,Show=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//--- 
PrevMonth=TimeMonth(TimeLocal());
DayOfMonth=TimeDay(TimeLocal());
if(DayOfMonth==1)
   {
      Delta=TimeDayOfWeek(TimeLocal());
      Show=1;
   }
//--- init
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//--- deinit
      return(0);   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int start()
  {
//---   
MonthOfYear=TimeMonth(TimeLocal());
DayOfMonth=TimeDay(TimeLocal());
DayOfWeeks=TimeDayOfWeek(TimeLocal());
if(PrevMonth!=MonthOfYear && DayOfMonth==1)
   {
      Delta=DayOfWeeks;
      Show=1;
   }
if(Show==1)
   {
      WeekOfMonth=MathCeil((DayOfMonth+Delta)/7);      
      Print("DayOfMonth N "+DoubleToStr(DayOfMonth,0));
      Print("WeekOfMonth N "+DoubleToStr(WeekOfMonth,0));
   }

PrevMonth=MonthOfYear;
//--- start
      return(0);   
  }
//+------------------------------------------------------------------+

not funny
 
pako:
it's not funny.

Did you think to answer like that for 30 minutes?

That's not an answer. Be more specific, Paco.

You know it's not funny at all, but history is silent on that...

 

Any tester, must include uncertainties.

I don't have to explain it to you. 2 or 3 points to perform. 0.1-1 point commission. And so on.

But, again, there is no point in me explaining to you that there are also other parameters.

For example, let's assume that we have hit a trend. For example, on EURUSD. For the period from January of this year, for example, again! Then how much money have we earned so far? It is easy to calculate. But what? If we invest exactly the same amount of money. We will get exactly the same profit in a couple of days? That's what a trader should dream of!!! Now, let's get to the point. Strategy? If it is possible in machine code? It must do something similar, or close to the strategy of an experienced trader.

In a word, looking at your creation! What can you say? I can't say anything. How bad it is! Everything is so wrong. Everything is so far from the true direction. I'm just watching TV. I'm resting, I'm just resting!!!

But good luck, though.

 
new-rena:

Did you think to answer like that for 30 minutes?

That's not an answer. Be more specific, Paco.

You know it's not funny at all, but history is silent on that...

in the cart counts right :)))
 
pako:
in the cart counts correctly :)))

Still an idea here and I gave it (so....):

if(PrevMonth!=MonthOfYear && DayOfMonth==1)    {       Delta=DayOfWeeks;       Show=1;    }

WeekOfMonth=MathCeil((DayOfMonth+Delta)/7); 

 
new-rena:

We should also put in when the 1st of the month falls on a weekend, as the tester doesn't spin weekends... Didn't see about the excel.

Well, and to roll in initialization from a couple of months ago AND to the current month would not hurt, so as not to wait for the end of the calculation of the number of the week a whole month. But these are all nuances ....

That's what makes MQL4 so attractive - the code is short and clear!

I don't have time right now, but Kim has all the functions to search for dates and times, there's the beginning of the month and the week number, in general I've seen everything, I don't remember where I've seen it, but maybe here: https://forum.mql4.com/ru/38949
 
Dimitri has long ago written everything for you about time, days, weeks, months, years... Are you reinventing the wheel?
 

Ah. Years, months, days of weeks. Hours??? 15 minutes??? Ah. !5 minutes worked and Ah. Ah how much money. Or twenty? And then again. Ah.

 
Karputov Vladimir:

When an indicator is to be added to the main window

int OnInit() 
  { 
   
//--- Создание кнопки 
  if( !ObjectCreate( 0, "Add_Indicator", OBJ_BUTTON, 0, 0, 0 ) )
  {
  
    Print( "Кнопка 'Добавить' не создана!" );
    return( INIT_FAILED );
  }
  else
  {
    ObjectSetInteger( 0, "Add_Indicator", OBJPROP_CORNER, CORNER_RIGHT_LOWER );
    ObjectSetInteger( 0, "Add_Indicator", OBJPROP_XDISTANCE, 200 );             
    ObjectSetInteger( 0, "Add_Indicator", OBJPROP_YDISTANCE, 500 );
    ObjectSetInteger( 0, "Add_Indicator", OBJPROP_XSIZE, 80 );
    ObjectSetInteger( 0, "Add_Indicator", OBJPROP_YSIZE, 20);

      ObjectSetInteger( 0, "Add_Indicator", OBJPROP_BGCOLOR, clrWhite );
      ObjectSetInteger( 0, "Add_Indicator", OBJPROP_STATE, true );
      ObjectSetString( 0, "Add_Indicator", OBJPROP_TEXT, "Добавить" );
     
  }
    
MA_handle=iCustom(NULL,0,"Examples\\Custom Moving Average",MA_Period,MA_Shift,MA_Method,PRICE_CLOSE);
   if(MA_handle==INVALID_HANDLE)
//--- попробуем добавить индикатор на график 
 Print(__FUNCTION__,", first_start = ",first_start);
//return(INIT_FAILED);
   return(INIT_SUCCEEDED);
  } 
//+------------------------------------------------------------------+
//| Обработка события нажатия кнопок                                 |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,         // идентификатор события   
                  const long& lparam,   // параметр события типа long 
                  const double& dparam, // параметр события типа double 
                  const string& sparam  // параметр события типа string 
                  )                
  {
   long b_state;
   //---
   if(id==CHARTEVENT_OBJECT_CLICK) // НАЖАТ ГРАФИЧЕСКИЙ ОБЪЕКТ       
         if ( sparam == "Add_Indicator" )// Нажата кнопка
         {
      if ( ObjectGetInteger( 0, "Add_Indicator", OBJPROP_STATE, 0, b_state ) )
      {
        if ( b_state == 1 )
        {
          first_start=false;
          ObjectSetInteger( 0, "Add_Indicator", OBJPROP_BGCOLOR,clrWhite );
          ObjectSetString( 0, "Add_Indicator", OBJPROP_TEXT, "Добавить" );
        }
   }
}
 return;
}

Also took the code of the button from the examples, .... How to make button's pressing not fixed, i.e. after its function is executed it returns to its initial state ...

 
new-rena:
Do you need a custom control panel that allows you to add any number of indicators from one or more?

I don't know how to make it simpler, if it's necessary or not...

I'll think about that later.