Download MetaTrader 5

Help with Indicator . . .

To add comments, please log in or register
Does your signal already have a lot of of subscribers? It's time to think about the paid subscription!
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.01.07 14:19 
Comments that do not relate to the "Using Technical indicator in an EA", have been moved into this topic.
amin_mohammadi
88
amin_mohammadi 2014.01.07 13:46  

Hello everyone,

I'm using a custom indicator in my EA. the custom indicator's file is attached to this comment.

when I use this indicator in my EA it uses much more memory than other indicators such as Ichimoku.

the code in EA is as follow. AnalyzeDemandLine method gets called in OnTick() event.


//+------------------------------------------------------------------+
//|                                                TradeAnalyzer.mqh |
//|                                                   Amin Mohammadi |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Amin Mohammadi"
#property link      "http://www.mql5.com"
#property version   "1.00"
#include "CurrencySymbols.mqh";
#include "OrderManagement.mqh";
#include "FractalIndicator.mqh";
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
struct returnedValue
  {
   double            LowTP;
   double            HighTP;
   double            HighDemandLine;
   double            LowDemandLine;
   double            open;
   int               result;

  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class TradeAnalyzer : public CurrencySymbols
  {
private:
   double            Open[];
   double            MoutekiBuffer[];
   double            Ups[];
   double            Downs[];
   double            DemandLineHigh[];
   double            DemandLineLow[];
   double            TakeProfitHigh[];
   double            TakeProfitLow[];

   //   Creation          type;
   string            short_name;
   int               MoutekiHandle;
   int               amount;
   returnedValue value;

public:
   returnedValue     FillArraysFromBuffers(string symbol,ENUM_TIMEFRAMES tf);
   returnedValue     AnalyzeDemandLine(string symbol,ENUM_TIMEFRAMES tf);
                     TradeAnalyzer();
                    ~TradeAnalyzer();
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
TradeAnalyzer::TradeAnalyzer()
  {
  

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
returnedValue TradeAnalyzer::FillArraysFromBuffers(string symbol,ENUM_TIMEFRAMES tf)
  {
   returnedValue value;
   MoutekiHandle=iCustom(symbol,tf,"Examples\AminNonGraphicMouteki");

//
   amount=Bars(symbol,tf);
   if(MoutekiHandle==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code
      PrintFormat(symbol,EnumToString(tf),GetLastError());
      //--- the indicator is stopped early
      //return(INIT_FAILED);
     }

////--- normal initialization of the indicator 
   if(CopyBuffer(MoutekiHandle,0,0,amount,Ups)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("1.Failed to copy data from the Mouteki indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      //return(false);
     }
   ArraySetAsSeries(Ups,true);
   if(CopyBuffer(MoutekiHandle,1,0,amount,Downs)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("1.Failed to copy data from the Mouteki indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      //return(false);
     }
   ArraySetAsSeries(Downs,true);
   if(CopyBuffer(MoutekiHandle,4,0,amount,TakeProfitHigh)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("1.Failed to copy data from the Mouteki indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      //return(false);
     }
   ArraySetAsSeries(TakeProfitHigh,true);
   if(CopyBuffer(MoutekiHandle,5,0,amount,TakeProfitLow)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("1.Failed to copy data from the Mouteki indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      //return(false);
     }
   ArraySetAsSeries(TakeProfitLow,true);
   if(CopyBuffer(MoutekiHandle,3,0,amount,DemandLineHigh)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("1.Failed to copy data from the Mouteki indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      //return(false);
     }
   ArraySetAsSeries(DemandLineHigh,true);
   if(CopyBuffer(MoutekiHandle,2,0,amount,DemandLineLow)<0)
     {
      //--- if the copying fails, tell the error code
      PrintFormat("1.Failed to copy data from the Mouteki indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated
      //return(false);
     }
   ArraySetAsSeries(DemandLineLow,true);
   ArraySetAsSeries(Open,true);
   CopyOpen(symbol,tf,0,Bars(symbol,tf),Open);
   value.HighDemandLine= DemandLineHigh[0];
   value.LowDemandLine = DemandLineLow[0];
   value.HighTP= TakeProfitHigh[0];
   value.LowTP = TakeProfitLow[0];
   value.open=Open[0];
   ArrayFree(Ups);
   ArrayFree(Downs);
   ArrayFree(DemandLineHigh);
   ArrayFree(DemandLineLow);
   ArrayFree(TakeProfitHigh);
   ArrayFree(TakeProfitLow);
   MoutekiHandle = 0;
   
   return value;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
returnedValue TradeAnalyzer::AnalyzeDemandLine(string symbol,ENUM_TIMEFRAMES tf)
  {
   
   value=FillArraysFromBuffers(symbol,tf);
   double openValue=value.open;
   double LowTD=value.LowDemandLine;
   double HighTD=value.HighDemandLine;
   if(openValue>LowTD)
     {
     value.result = 1;
      return value;
     }
   else if(openValue<HighTD)
     {
     value.result = 2;
      return value;
     }
     value.result = 0;
   return value;

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
TradeAnalyzer::~TradeAnalyzer()
  {
  }
//+------------------------------------------------------------------+
Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5
  • 2009.11.23
  • Андрей
  • www.mql5.com
I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
Alain Verleyen
Moderator
30743
Alain Verleyen 2014.01.07 16:04  
So what ?
To add comments, please log in or register