How to change the indicator to EA

 

I want to change the indicator to EA model, and then print it out in the EA, how to change?


//+------------------------------------------------------------------+
//|                                                            7.mq4 |
//|                        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 strict

//---- plot TickVolume 
#property indicator_label1  "TickVolume" 
#property indicator_type1   DRAW_HISTOGRAM 
#property indicator_color1  C'143,188,139' 
#property indicator_style1  STYLE_SOLID 
#property indicator_width1  1 
//--- input parameters 
input int      bars=3000; 
//--- indicator buffers 
double         TickVolumeBuffer[]; 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
 { 
//--- indicator buffers mapping 
   SetIndexBuffer(0,TickVolumeBuffer,INDICATOR_DATA); 
   IndicatorSetInteger(INDICATOR_DIGITS,0); 
//--- 
  } 
//+------------------------------------------------------------------+ 
//| 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(prev_calculated==0) 
     { 
      long timeseries[]; 
      ArraySetAsSeries(timeseries,true); 
      int prices=CopyTickVolume(Symbol(),0,0,bars,timeseries); 
      for(int i=0;i<rates_total-prices;i++) TickVolumeBuffer[i]=0.0;  
      for(int i=0;i<prices;i++) TickVolumeBuffer[rates_total-1-i]=timeseries[prices-1-i];  
      Print("We have received the following number of TickVolume values: "+prices); 
     } 
   else 
     { 
      long timeseries[]; 
      int prices=CopyTickVolume(Symbol(),0,0,1,timeseries); 
      TickVolumeBuffer[rates_total-1]=timeseries[0];  
     }   
   return(rates_total); 
  }
 
 

      
      
      
   
 
 
wxn2014: I want to change the indicator to EA model, and then print it out in the EA, how to change?
Don't try do that. There are no buffers, no IndicatorCounted() or prev_calculated. No way to know if older bars have changed or been added (history update.)
Just get the value(s) of the indicator(s) into the EA and do what you want with it.
You should encapsulate your iCustom calls to make your code self-documenting.
          Detailed explanation of iCustom - MQL4 and MetaTrader 4 - MQL4 programming forum
 
whroeder1:

Thank you first! I slowly learning first, then see how to solve this problem