kindly add buffer in this indicator

 
//+------------------------------------------------------------------+
//|                                          CandleTimeStationary.mq4|
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window
//---- input parameters

extern color  Clock_Color = Red;
extern string Corner_Placement = "1 is top right 3 is bottom right";
extern int    Corner = 2;


string objname="Spread&Bar";
double s1[];

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init(){

  ObjectCreate(objname, OBJ_LABEL,0, 0, 0);
  ObjectSet(objname, OBJPROP_CORNER, Corner);
  ObjectSet(objname, OBJPROP_XDISTANCE, 20);
  ObjectSet(objname, OBJPROP_YDISTANCE, 230);     
   
   //----
   return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit(){

  ObjectDelete(objname);

  //----
  return(0);
} 


//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{

   //Time to bar expiry
  int m,s;

  m=Time[0]+Period()*60-CurTime();
  s=m%60;
  m=(m-s)/60;
  int spread=MarketInfo(Symbol(), MODE_SPREAD);

  string _sp="",_m="",_s="";
  if (spread<10) _sp="..";
  else if (spread<100) _sp=".";
  if (m<10) _m="0";
  if (s<10) _s="0";
  
   ObjectSetText(objname,"-----------------------------------------" , 13, "Courier", Clock_Color); //***add buffer for this because i want set alert when candle crosses above or bellow
  return(0);
}
//+---------------------------------------------------------
 
A buffer for what ?  the spread ?
 
Lorentzos Roussos #:
A buffer for what ?  the spread ?

is it possible to set buffer for ObjectSetText , because i want to use this buffer for alert , when candle crosses above or below (---------------------------------) this text area . 


or can you share fixed horizontal level at virtually midpoint chart, same as subwindow 50 level

 
maxtitu835 #:

is it possible to set buffer for ObjectSetText , because i want to use this buffer for alert , when candle crosses above or below (---------------------------------) this text area . 


or can you share fixed horizontal level at virtually midpoint chart, same as subwindow 50 level

Ow so you want the alert, not to display the history , you want one price .

Which price though ? the user adds it ?

 
Lorentzos Roussos #:
Ow so you want the alert

actually i want this type fixed level indicator,  see screenshot , this level same as subwindow 20, 50, 80 level, this levels doesn't  move by chart shift, i added this by stochastic indicator modified by seperate window to chart window, but i want to add arrow or alert when candle cross this level, do you have this type idea indicator? 

Files:
 
maxtitu835 #:

actually i want this type fixed level indicator,  see screenshot , this level same as subwindow 20, 50, 80 level, this levels doesn't  move by chart shift, i added this by stochastic indicator modified by seperate window to chart window, but i want to add arrow or alert when candle cross this level, do you have this type idea indicator? 

or i have also a indicator , is it possible fixed level at vertically midpoint on chart

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 clrRed

input double levelPrice = 1.2000; // Set the desired level price here

double buffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   // Indicator buffer
   SetIndexBuffer(0, buffer);
   
   // Set the buffer values to the desired level
   for (int i = 0; i < ArraySize(buffer); i++)
   {
      buffer[i] = levelPrice;
   }
   
   IndicatorShortName("Horizontal Level");
   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[])
  {
   // Just refresh the buffer values on each tick
   for (int i = 0; i < rates_total; i++)
   {
      buffer[i] = levelPrice;
   }
   
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
maxtitu835 #:

actually i want this type fixed level indicator,  see screenshot , this level same as subwindow 20, 50, 80 level, this levels doesn't  move by chart shift, i added this by stochastic indicator modified by seperate window to chart window, but i want to add arrow or alert when candle cross this level, do you have this type idea indicator? 

Ow so you want 3 % (levels) of the active viewport visible as the viewport changes ? 

Or based on the previous "OtherTimeframe" close (or OHLC)? 

 
Lorentzos Roussos #:

Ow so you want 3 % (levels) of the active viewport visible as the viewport changes ? 

Or based on the previous "OtherTimeframe" close (or OHLC)? 

yes,  is it possible to fixed the levelprice auto adjust vertically middle point on the chart



#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 clrRed

input double levelPrice = 1.2000; // want to auto adjust vertically middle point on the chart

double buffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   // Indicator buffer
   SetIndexBuffer(0, buffer);
   
   // Set the buffer values to the desired level
   for (int i = 0; i < ArraySize(buffer); i++)
   {
      buffer[i] = levelPrice;
   }
   
   IndicatorShortName("Horizontal Level");
   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[])
  {
   // Just refresh the buffer values on each tick
   for (int i = 0; i < rates_total; i++)
   {
      buffer[i] = levelPrice;
   }
   
   return(rates_total);
  }
//+------------------------------------------------------------------+

 
maxtitu835 #:

yes,  is it possible to fixed the levelprice auto adjust vertically middle point on the chart



i see , try this 

//+------------------------------------------------------------------+
//|                                            chartVisualLevels.mq4 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#define LINE_TAG "VisualLevels_"
input double Level1=0.80;//Level 1 %
input double Level2=0.50;//Level 2 %
input double Level3=0.20;//Level 3 %
bool Ready=false;
double Levels[];
int OnInit()
  {
  Ready=false;
  ArrayFree(Levels);
  ArrayResize(Levels,3,0);
  Levels[0]=Level1;
  Levels[1]=Level2;
  Levels[2]=Level3;
  ObjectsDeleteAll(ChartID(),LINE_TAG);
  //create lines 
    create_lines(Levels,Ready);
  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[])
  {
  //--- 
  //--- return value of prev_calculated for next call
  return(rates_total);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
  if(id==CHARTEVENT_CHART_CHANGE){
    create_lines(Levels,Ready);
    } 
  }
//+------------------------------------------------------------------+
//create lines 
  void create_lines(double &levels[],
                    bool &ready){
  int errors=0;ResetLastError();
  double max=(double)ChartGetDouble(ChartID(),CHART_PRICE_MAX,0);errors+=GetLastError();ResetLastError();
  double min=(double)ChartGetDouble(ChartID(),CHART_PRICE_MIN,0);errors+=GetLastError();ResetLastError();
  if(errors==0){
    for(int i=0;i<ArraySize(levels);i++){
       double price=NormalizeDouble((min+(max-min)*levels[i]),_Digits);
       if(!ready){
         createHLine(LINE_TAG+IntegerToString(i),price);
         }
       else{
         updateHLine(LINE_TAG+IntegerToString(i),price);
         }
       }
    ready=true;
    }
  }
//create line
  void createHLine(string name,
                   double price){
  ObjectCreate(ChartID(),name,OBJ_HLINE,0,0,price);
  }
//update line
  void updateHLine(string name,
                   double price){
  ObjectSetDouble(ChartID(),name,OBJPROP_PRICE,price);
  }
 
Lorentzos Roussos #:

i see , try this 

it works fine, but if possible to add buffer for each level,

 
maxtitu835 #:

it works fine, but if possible to add buffer for each level,

You don't need a buffer for that , if you want to use them in an EA -not recommended- just port the mechanism in the EA and store the prices .