Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 886

 
Vinin:
Check in more often. There will be fewer questions. There will be better knowledge.
Ignore.
 

Good afternoon. Need to somehow close a position at the end of the day (purely Expert Advisor; daily bars). The modelling is either by openings or by ticks. I.e. we either settle for openings or tumble over our heads trying to analyze previous days on some 15 min timeframe and catch the beginning and end of the current one. Are there any solutions to this problem? I see several virtual-hypothetical options:

1) Hacking-closing a position at any price and at any time. Suppose unfair, but we could simply close the position at the required price without perversion.

2) To simulate the opening and closing within one bar. I.e. first a tick open, then a tick close.

3) Setting an order that automatically closes at a certain time (i.e. at the end of the day).

Any help would be appreciated. Thank you.

 

A bug?

int OnInit()
  {
   int subwindow = ChartWindowFind(ChartID(),WindowExpertName());
   Print("Подокно запрашиваемого индикатора: ",subwindow);
   
   return(INIT_SUCCEEDED);
  }

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[])
  {
   return(rates_total);
  }


2015.04.13 20:51:10.710 indi AUDJPY,H1: Requested indicator subframe: -1


 
tuner:

A bug?


2015.04.13 20:51:10.710 indi AUDJPY,H1: Requested indicator subframe: -1


No, not a bug.

Return value.

Subwindow number in case of success. Zero indicates the main chart window. In case of failure it returns -1.

 
AlexeyVik:

No, not a bug.


What is the failure if the function is passed the ID of the current chart where the indicator is running and the name of the current indicator that is running on the current chart?
 
tuner:
What is the failure if the function passes the ID of the current chart, on which the indicator is running, and the name of the current indicator that is running on the current chart?

If I understand you correctly and you need the subwindow number in which your attached indicator test code works, then, based on the description of the function, it's better to apply its second version.

Test code (I have added some lines to yours):

#define  LINE    __LINE__,": "
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   int subwindow=ChartWindowFind(ChartID(),WindowExpertName());
   Print(LINE,"Подокно запрашиваемого индикатора: ",subwindow);
   
   int subwindow1=ChartWindowFind();
   Print(LINE,"Подокно запрашиваемого индикатора: ",subwindow1);

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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[])
  {
   return(rates_total);
  }
//+------------------------------------------------------------------+

The help for ChartWindowFind() function has a good example still on this subject (in terms of comments there as well):

//+------------------------------------------------------------------+
//| Сообщает номер окна графика с указанным индикатором              |
//+------------------------------------------------------------------+
int GetIndicatorSubWindowNumber(long chartID=0,string short_name="")
  {
   int window=-1;
//--- 
   if((ENUM_PROGRAM_TYPE)MQLInfoInteger(MQL_PROGRAM_TYPE)==PROGRAM_INDICATOR)
     {
      //--- функция вызвана из индикатора,имя не требуется
      window=ChartWindowFind();
     }
   else
     {
      //--- функция вызвана из эксперта или скрипта
      window=ChartWindowFind(0,short_name);
      if(window==-1) Print(__FUNCTION__+"(): Error = ",GetLastError());
     }
//---
   return(window);
  }
 
DiPach:

If I understand you correctly and you need the subwindow number in which your attached indicator test code works, then, based on the description of the function, it's better to apply its second version.

Test code (I have added some lines to yours):

The ChartWindowFind() function's help has a good example still on this subject (in terms of comments there as well):

Thanks for the tip, but I have a slightly different task, due to which the use of the 2nd variant of the function does not make sense: I want to count the number of indicators with a specified name in all open terminal charts. The task has already been solved, but I want to simplify the resulting code usingChartWindowFind() of the first variant but it turned out that this function doesn't work not only with other windows but even with the current one.
 

Good evening!

I can't figure it out: In the start function, the compiler requires "return" - the function must return a value".

What value must return in this case?

int start()
{
if (Orders!=0||Ord > 0)
{
CritCloseBuy();
CritCloseSell();
}
else
{
CritOpen();
}
return;
}

Could this be the reason why OrderClose() doesn't see an open position?

 
rapid_minus:

Good evening!

I can't figure it out: In the start function, the compiler requires "return" - the function must return a value".

What value must return in this case?

int start()

Can this be the reason why OrderClose() does not see an open position?

make void start() and there will be no error
 
tuner:
do void start() and there will be no error
Thank you! The error has disappeared, but the position still won't close.