Indicator not showing on the charts. What is wrong in the code? Thank You!

 

Indicator not showing on the charts. What is wrong in the code? Thank You!

//

+------------------------------------------------------------------+

//|                                                 UpWorkArshak.mq5 |
//|                                                      SchelasCorp |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "SchelasCorp"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Upper
#property indicator_label1  "Upper"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrNavy
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Lower
#property indicator_label2  "Lower"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |

//dipness = input(title="Dipness", defval=0.5);
//smoothness = input(title="Smoothing", defval=85, minval=0);
input double dipness = 2; // Dipness
input int smoothness = 10; // Smoothing
bool buyCondition = false;
bool sellCondition = false;

int   atr_period=20;
double iATRBuffer[];
int    handle;
int handleDip;
int handleRip;
double dipBuffer[];
double ripBuffer[];
double highBuffer[];
double lowBuffer[];
//+------------------------------------------------------------------+
int OnInit()
  {
  
   ObjectCreate(0,"High",OBJ_HLINE,0,0,highBuffer[0]);
   ObjectCreate(0,"Low",OBJ_HLINE,0,0,lowBuffer[0]);
  
  
//--- indicator buffers mapping
   buyCondition = false;
   sellCondition = false;
   
   handle=iATR(_Symbol,PERIOD_CURRENT,atr_period);
   handleDip=iMA(_Symbol,_Period,smoothness,0,MODE_SMMA,PRICE_LOW);
   handleRip=iMA(_Symbol,_Period,smoothness,0,MODE_SMMA,PRICE_HIGH);
//---

   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(!isNewBar()){return 0;}
   
   
   if(CopyBuffer(handle,0,0,20,iATRBuffer)!=20)
      return 0;
   
   double thedip = low[0] - iATRBuffer[20] * dipness;
   double therip = high[0] + iATRBuffer[20] * dipness;
   
   
   //thedipsma = sma(thedip, smoothness)
   
   CopyBuffer(handleDip,0,0,1,dipBuffer);
   double thedipsma = dipBuffer[0];
   //theripsma = sma(therip, smoothness)
   CopyBuffer(handleRip,0,0,1,ripBuffer);
   double theripsma = ripBuffer[0];
   
   CopyHigh(_Symbol,_Period,0,1,highBuffer);
   CopyLow(_Symbol,_Period,0,1,lowBuffer);
   
   
   //buyCondition = crossunder(low, thedipsma)   
      
   if(!buyCondition && highBuffer[0] > theripsma){
      buyCondition = true;
      sellCondition = false;
      Print("Buy condition on "+_Symbol +"!");
      SendNotification("Buy condition on "+_Symbol +"!");
   }
   
   //sellCondition = crossover(high, theripsma)
   
   if(!sellCondition && lowBuffer[0] < thedipsma){
      sellCondition = true;
      buyCondition = false;
      Print("Sell condition on "+_Symbol +"!");
      SendNotification("Sell condition on "+_Symbol +"!");
   }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

double atr(int Count){
   int      MA_Period = 20;
   int      ATRHandle;
   double   ATRValue[];
   ATRHandle = iATR(_Symbol,0,MA_Period);
   ArraySetAsSeries( ATRValue,true );
   if( CopyBuffer( ATRHandle,0,0,Count+1,ATRValue ) > 0 )
      {
         return ATRValue[Count];
      }
      return 0;
}

bool isNewBar(){
    static datetime last_time=0;
    datetime lastbar_time=(datetime)SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);

    if(last_time==0){
        last_time=lastbar_time;
        return(false);
    }

    if(last_time!=lastbar_time){
        last_time=lastbar_time;
        return(true);
    }
    return(false);
}
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • 2022.02.06
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
 
Arshak Ghazarian: Indicator not showing on the charts. What is wrong in the code? Thank You!

Having some populated buffers to show your lines will help.

 
William Roeder #:

Having some populated buffers to show your lines will help.

Excuse me William. What's that? I don't understand MQL5. I just hired someone on upwork. He created the indicator, but didn't make it show on the charts.
 
Arshak Ghazarian #: Excuse me William. What's that? I don't understand MQL5. I just hired someone on upwork. He created the indicator, but didn't make it show on the charts.

Then maybe you should confront that someone and discuss the issue! Anything we tell you, you will not understand since you don't understand MQL or coding. So, it will be pointless for us to discuss it with you!

 
Fernando Carreiro #:

Then maybe you should confront that someone and discuss the issue! Anything we tell you, you will not understand since you don't understand MQL or coding. So, it will be pointless for us to discuss it with you!

Thank You for your response Fernando. I understand a little. If possible, tell me what should I change in the code. 
 
Arshak Ghazarian #: Thank You for your response Fernando. I understand a little. If possible, tell me what should I change in the code. 

We did! Or rather, William did! He told you that in order to show "something", you actually have to put "something" into the buffers that are plotted on the chart.

However, you don't know what buffers are, so there is no common language to explain it any further. You said that you understand a little, but that little you know is not enough. In fact, there are many other problems with the code, not just the buffers. So how do you want us to explain it if you don't even know the basics?

You did not even explain what it is the Indicator is supposed to achieve in the first place, so we can't even speak to any of the logic problems that may exist based on the expected functionality.

All we can say, is that whomever coded it for you, is an absolute noob. Best to hire someone else more experienced.

Reason: