Custom Plug

Custom Plugin

  This post I will describe how to create custom plugin for develop your own strategy to open initial trade. Our some EA has this function so user can add his custom strategy as initial trade. For do that you have to develop custom indicator (we call it custom plugin) so our EA can get initial trade signal from your custom plugin. Actually custom plugin is just a indicator, EA use iCustom function to get signal from your custom indicator to open initial trade. To active Custom Plugin into EA
  • Active Plug In: To active Custom plugin you have to set On
  • PluginName: Put your custom indicator name.
  • PluginInputSetting: You can send data to your custom indicator. Basically, you can send indicator settings separate by ";".
Below code are demonstrated how code work into our EA when you active plug id -  
void Custom_Signal()
{

int Signal =0;

Signal     = (int)iCustom(_symbol,PERIOD_CURRENT,PluginName,PluginInputSetting,0,0);

if(Signal==1)
{
if(!ReverseSignals){
BuyCondition = true;
}else{
SellCondition = true;
}
}

if(Signal==2)
{
if(!ReverseSignals){
SellCondition = true;
}else{
BuyCondition = true;
}
}
}
  IMPORTANT
  • Your custom indicator must have one Input that inputs you set data to your custom indicator. iCustom only uses [0] buffer to get the signal. So your custom indicator [0] buffer consider a signal buffer.
  • iCustom only uses the only current bar to get the signal.
 

How to Develop Indicator (Custom Plugin)

Here I will give you an example of how to develop a custom indicator. In this example, we develop an RSI indicator to develop a custom strategy. You can use any indicator to build your custom strategy. Download Example File from Attachment below. I will try to explain every code from the example file, you can modify the code by yourself as per your requirement or you can full code by yourself. Just keep in mean you have to follow four rule -
  • You have to send signal only BUFFER [0] Zero.
  • Value 1 consider as BUY Signal
  • Value 2 consider as SELL Signal
  • The indicator must have a minimum of one string type input. You have set your custom indicator setting with this input.
In the example code, I use RSI indicator for a custom strategy to open initial trade. For example I want CAP Zone Recovery EA will open initial trade like below - Strategy is
  • To open  Buy trade when RSI Value < 30
  • To open  Sell trade when RSI Value > 70
 
//+------------------------------------------------------------------------+
//|                                      CAP_ZoneRecovery_Plugin.mq4       |
//|                               Copyright © 2010-2014, Capilta.com       |
//|                                          https://www.Capilta.com       |
//|                                                                        |
//|  This custom indicator is template of Custom plugin    |
//|  It is a sample code to make entry logic for initial open trade.       |
//|                                                                        |
//+------------------------------------------------------------------------+

#property copyright   "Copyright © 2010-2015, Capilta Business Solutions"
#property link        "http://www.capilta.com"
#property version     "1.00"
#property strict
    Write your file name, copyright, like and file version.    
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   0
  --> In this example i use indicator buffer 1 only. you can create several  buffer as per your requirements. but keep in mind in CAP Zone Recovery EA only get signal from buffer - 0. So have to send signal to CAP Zone Recovery EA only buffer [0] --> "PluginInputSetting" is a input this is the input you can get data from CAP Zone Recovery EA.      
//+------------------------------------------------------------------+
//|   Buffer for send signal to main EA
//|   ExtEntryBuffer -
//                     1 - Value for BUY Signal
//|                    2 - Value for SELL Signal
//+------------------------------------------------------------------+
double ExtEntryBuffer[];
  --> Create Variable from Indicator Buffer.  So when Buffer value 1 then CAP Zone Recovery EA will open BUY Trade and when Buffer Value 2 Then CAP Zone Recovery will SELL Signal.    
//+------------------------------------------------------------------+
//| Variable for Indicator                                           |
//+------------------------------------------------------------------+
int                  RSIPeriod     = 14;
ENUM_APPLIED_PRICE   RSIPrice      = PRICE_CLOSE;
int                  RSISellLevel  = 70;
int                  RSIBuyLevel   = 30;
    --> Set of variable for RSI.      
/+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ExtEntryBuffer,INDICATOR_CALCULATIONS);

//--- change the order of accessing elements of the indicator buffer
ArraySetAsSeries(ExtEntryBuffer,true);

//--- get indicator setting data from EA by input  "PluginInputSetting"
//--- split data and separate value by ";"

if(PluginInputSetting!="")
{
string value[];
StringSplit(PluginInputSetting,StringGetCharacter(";",0),value);

if(ArraySize(value)>0)
{
if(value[0]!="")                     RSIPeriod = (int)value[0];
}

if(ArraySize(value)>1)
{
if(value[1]=="PRICE_CLOSE")          RSIPrice  = PRICE_CLOSE;
else if(value[1]=="PRICE_HIGH")      RSIPrice  = PRICE_HIGH;
else if(value[1]=="PRICE_LOW")       RSIPrice  = PRICE_LOW;
else if(value[1]=="PRICE_MEDIAN")    RSIPrice  = PRICE_MEDIAN;
else if(value[1]=="PRICE_OPEN")      RSIPrice  = PRICE_OPEN;
else if(value[1]=="PRICE_TYPICAL")   RSIPrice  = PRICE_TYPICAL;
else if(value[1]=="PRICE_WEIGHTED")  RSIPrice  = PRICE_WEIGHTED;
}

if(ArraySize(value)>2)
{
if(value[2]!="")                     RSISellLevel = (int)value[2];
}

if(ArraySize(value)>3)
{
if(value[3]!="")                     RSIBuyLevel  = (int)value[3];
}
}
//---
return(INIT_SUCCEEDED);
}
    --> In OnInit() function i set Indicator buffers mapping. --> Split and separate data that come from CAP Zone Recovery EA's input.
//+------------------------------------------------------------------+
//| 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[])
{

ExtEntryBuffer[0] = 0;

ExtEntryBuffer[0] = Signal_Entry(Symbol(),PERIOD_CURRENT);

return(rates_total);
}

</code>

--> In OnCalculate I set ExtEntryBuffer[0] = 0;
--> Then i set signal value to  ExtEntryBuffer[0] with function Signal_Entry();

<code>

//+------------------------------------------------------------------+
int Signal_Entry(string Sym,ENUM_TIMEFRAMES TF)
{

double RSI_Value=iRSI(Sym,TF,RSIPeriod,RSIPrice,0);

if( RSI_Value < RSIBuyLevel )  return(1);
if( RSI_Value > RSISellLevel ) return(2);

return(0);

}
//+------------------------------------------------------------------+       --> When RSI value below RSIBuyLevel will return 1. Because value 1 for BUY Signal --> When RSI value above RSISellLevel will return 2. Because value 2 for SELL Signal   IMPORTANT
  • Try to understand code by yourself. Keep in Mind you will give any support to education to understand MQL coding. Coding related any question will be ignore.
 

Download Example source code

Mt4 version -  https://goo.gl/X10Ajd

MT5 version -  https://goo.gl/nISxEg