Update or delete line - page 2

 
Fabio Cavalloni:
With you suggestion for each new tick the indicator recalculates all candles.
This is not a solution, this is the beginning of a lots of other issues, like the indicator calculation speed

You need to read through all the posts.

 
Seng Joo Thio:

You need to read through all the posts.

I read again and found that your solution is working in this case.
Sorry for my distraction.
 

Hello guys

I have found one more problem on this indicator. Everytime I start MT5 I can't see the indicator on the chart. But if I switch to an other timeframe and then switching back, the indicator is visible. How can I make it to draw at startup of MT5? (there is no problem if I simpy add the indicator to the chart)

Code attached in file:
Files:
 
marketcycle17:

Hello guys

I have found one more problem on this indicator. Everytime I start MT5 I can't see the indicator on the chart. But if I switch to an other timeframe and then switching back, the indicator is visible. How can I make it to draw at startup of MT5? (there is no problem if I simpy add the indicator to the chart)

Code attached in file:

Use this code: (based on DRAW_ARROW drawing style)

//+------------------------------------------------------------------+
//|                                                   Open Level.mq5 |
//|                              Copyright © 2020, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2020, Vladimir Karputov"
#property version   "1.000"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Open
#property indicator_label1  "Open"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrFuchsia
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input ENUM_TIMEFRAMES   Inp_period  = PERIOD_H1;   // Timeframe
//--- indicator buffer
double   OpenBuffer[];
//---
bool     m_global_error=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   if(Inp_period<Period())
     {
      string err_text=(TerminalInfoString(TERMINAL_LANGUAGE)=="Russian")?
                      "Входной параметр \"Timeframe\" не может быть МЕНЬШЕ текущего таймфрейма!":
                      "Input parameter \"Timeframe\" cannot be LESS than the current timeframe!";
      Alert(__FILE__," ",__FUNCTION__,", ERROR: ",err_text);
      m_global_error=true;
      return(INIT_SUCCEEDED);
     }
   double price_open=iOpen(Symbol(),Inp_period,0);
//--- indicator buffers mapping
   SetIndexBuffer(0,OpenBuffer,INDICATOR_DATA);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger(0,PLOT_ARROW,159);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---
   if(m_global_error)
      return(0);
//--- main loop
   int limit=prev_calculated-1;
   if(prev_calculated==0)
      limit=0;
   for(int i=limit; i<rates_total; i++)
     {
      if(Inp_period==Period())
        {
         OpenBuffer[i]=open[i];
        }
      else
        {
         int bars_shift=iBarShift(Symbol(),Inp_period,time[i],false);
         if(bars_shift<0)
            return(0);
         double price_open=iOpen(Symbol(),Inp_period,bars_shift);
         if(price_open==0.0)
            return(0);
         OpenBuffer[i]=price_open;
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


Result:


Files:
 

Hi, I tested your code but still the same problem. I looked into the log files and here is what I found when I have been using my indicator:

"OpenPriceLine (XAUUSD,M1)    array out of range in 'OpenPriceLine.mq5' (59,24)"


What can I do?

 
marketcycle17 :

Hi, I tested your code but still the same problem. I looked into the log files and here is what I found when I have been using my indicator:

"OpenPriceLine (XAUUSD,M1)    array out of range in 'OpenPriceLine.mq5' (59,24)"


What can I do?

You can use my code ( Open Level )

 
Vladimir Karputov:

You can use my code ( Open Level )

I tried to change my code more or less according to your code. Lines are not on chart at startup. When the new candlestick of 1min-tf has opened then the lines are painted (so it works only after 1 minute).

I also tried to use the limit variable in the for-loop as in your code but then I get the same problem as I have described in my first post.


Can anyone check what needs to be changed? Would appreciate it.

Files:
 
marketcycle17 :

I tried to change my code more or less according to your code. Lines are not on chart at startup. When the new candlestick of 1min-tf has opened then the lines are painted (so it works only after 1 minute).

I also tried to use the limit variable in the for-loop as in your code but then I get the same problem as I have described in my first post.


Can anyone check what needs to be changed? Would appreciate it.

Sorry, but you answer once a month - apparently you don't need a code at all. I am unable to remember what happened a month ago.

Turn to Freelance - paying with money usually disciplines a person and forces you to communicate more often than once a month.

Reason: