Download MetaTrader 5

Why this EA does not display my "indicator" on the chart?

To add comments, please log in or register
Pierre Rougier
613
Pierre Rougier  

Hello,

It's an Expert.

Why this EA does not display my "indicator" on the chart?

Thanks,

Pierre


//+------------------------------------------------------------------+
//|                                                    eaHighLow.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window

#property indicator_buffers 2
#property indicator_plots   2
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrYellow
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrCrimson

double HighBuffer[];
double LowBuffer[];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//--- indicator buffers mapping
   SetIndexBuffer(0,HighBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,LowBuffer,INDICATOR_DATA);

   int bars=Bars(_Symbol,_Period);
   Print("bars :"+IntegerToString(bars));

   Print("ArraySize(HighBuffer) :"+IntegerToString(ArraySize(HighBuffer)));
   int copied_rates=CopyHigh(_Symbol,_Period,0,bars,HighBuffer);
   Print("ArraySize(HighBuffer) :"+IntegerToString(ArraySize(HighBuffer)));

   Print("ArraySize(LowBuffer) :"+IntegerToString(ArraySize(LowBuffer)));
   copied_rates=CopyLow(_Symbol,_Period,0,bars,LowBuffer);
   Print("ArraySize(LowBuffer) :"+IntegerToString(ArraySize(LowBuffer)));

   Print("HighBuffer[20] :"+DoubleToString(HighBuffer[20]));
   Print("LowBuffer[20] :"+DoubleToString(LowBuffer[20]));
   Print("HighBuffer[102] :"+DoubleToString(HighBuffer[102]));
   Print("LowBuffer[102] :"+DoubleToString(LowBuffer[102]));
   Print("HighBuffer[222] :"+DoubleToString(HighBuffer[222]));
   Print("LowBuffer[222] :"+DoubleToString(LowBuffer[222]));
   Print("HighBuffer[301] :"+DoubleToString(HighBuffer[301]));
   Print("LowBuffer[301] :"+DoubleToString(LowBuffer[301]));


//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+





Anthony Garot
518
Anthony Garot  
Pierre Rougier:

Hello,

It's an Expert.

Why this EA does not display my "indicator" on the chart?

Thanks,

Pierre

You are mixing two different constructs: indicators and EA's.

If you want to see visual data on a chart, create an indicator. MetaTrade created indicators to encapsulate calculations, efficiently, and to visually display the results. You can then have an EA pull data from the indicator's buffers using iCustom().

I think perhaps some of my earlier posts on having an EA calculate data internally may be confusing. Most of the time (99% of the time) I use indicators for my calculations. Only very rarely do I do calculations internally inside an EA. That is only when the visual aspects of the indicator are not needed.

I recommend you keep indicators and EA's separate until you have an overriding reason to not do so.

Pierre Rougier
613
Pierre Rougier  
Thanks Anthony,
Pierre8r
To add comments, please log in or register