forked from nique_372/MQLArticles
139 lines
4.9 KiB
MQL5
//+------------------------------------------------------------------+
| |||
//| EaCommon.mqh |
| |||
//| Copyright 2026, Niquel Mendoza. |
| |||
//| https://www.mql5.com |
| |||
//+------------------------------------------------------------------+
| |||
#property copyright "Copyright 2026, Niquel Mendoza."
| |||
#property link "https://www.mql5.com"
| |||
#property strict
| |||
| |||
#ifndef MQLARTICLES_OB_INDICATOR_EACOMMON_MQH
| |||
#define MQLARTICLES_OB_INDICATOR_EACOMMON_MQH
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| Recurso (el indicador incrustado en el ex5 del EA) |
| |||
//+------------------------------------------------------------------+
| |||
#resource "OrderBlockIndPart2.ex5"
| |||
#define TSNMQLA_OB_INDICATOR_RESOURCE "::OrderBlockIndPart2.ex5"
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| Enum |
| |||
//+------------------------------------------------------------------+
| |||
enum ENUM_TP_SL_STYLE
| |||
{
| |||
ATR = 0, //Atr
| |||
POINT = 1 //Points
| |||
};
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| Inputs comunes (el orden y el tipo siguen al del indicador, ver |
| |||
//| CreateIndicatorObHandle en los EAs) |
| |||
//+------------------------------------------------------------------+
| |||
sinput group "-------| Ob Indicator settings |-------"
| |||
input ENUM_TIMEFRAMES InpTimeframeOrderBlock = PERIOD_M5; //Order block timeframe
| |||
input int InpRangoUniversalBusqueda = 75; //search range of order blocks
| |||
input int InpWidthOrderBlock = 1; //Width order block
| |||
input bool InpBackOrderBlock = true; //Back order block?
| |||
input bool InpFillOrderBlock = true; //Fill order block?
| |||
input color InpColorOrderBlockBajista = clrRed; //Bearish order block color
| |||
input color InpColorOrderBlockAlcista = clrGreen; //Bullish order block color
| |||
input double InpTransparency = 0.5; // Transparency from 0.0 (invisible) to 1.0 (opaque)
| |||
| |||
sinput group ""
| |||
sinput group "-------| Strategy |-------"
| |||
input ENUM_TP_SL_STYLE InpTpSlStyle = ATR;//Tp and sl style:
| |||
| |||
sinput group "- TP SL by ATR "
| |||
input double InpAtrMultiplier1 = 9.3;//Atr multiplier 1 (SL)
| |||
input double InpAtrMultiplier2 = 24.4;//Atr multiplier 2 (TP)
| |||
| |||
sinput group "- TP SL by POINT "
| |||
input int InpTpPoint = 1000; //TP in Points
| |||
input int InpSlPoint = 1000; //SL in Points
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| Funciones comunes |
| |||
//+------------------------------------------------------------------+
| |||
int GetMovingAverageIndex(long chart_id = 0)
| |||
{
| |||
int total_indicators = ChartIndicatorsTotal(chart_id, 0);
| |||
for(int i = 0; i < total_indicators; i++)
| |||
{
| |||
string indicator_name = ChartIndicatorName(chart_id, 0, i);
| |||
if(StringFind(indicator_name, "MA") >= 0)
| |||
return i;
| |||
}
| |||
return -1;
| |||
}
| |||
| |||
//+------------------------------------------------------------------+
| |||
//| Crea el handle del indicador de order blocks. Solo lo crea: no lo|
| |||
//| agrega al grafico ni elimina el EA, eso lo decide el EA. |
| |||
//+------------------------------------------------------------------+
| |||
int CreateIndicatorObHandle()
| |||
{
| |||
//--- We configure the indicator parameters
| |||
MqlParam param[19];
| |||
| |||
param[0].type = TYPE_STRING;
| |||
param[0].string_value = TSNMQLA_OB_INDICATOR_RESOURCE;
| |||
| |||
param[1].type = TYPE_STRING;
| |||
param[1].string_value = "--- Order Block Indicator settings ---";
| |||
| |||
param[2].type = TYPE_BOOL;
| |||
param[2].integer_value = false;
| |||
| |||
param[3].type = TYPE_STRING;
| |||
param[3].string_value = "-- Order Block --";
| |||
| |||
param[4].type = TYPE_INT;
| |||
param[4].integer_value = InpRangoUniversalBusqueda;
| |||
| |||
param[5].type = TYPE_INT;
| |||
param[5].integer_value = InpWidthOrderBlock;
| |||
| |||
param[6].type = TYPE_BOOL;
| |||
param[6].integer_value = InpBackOrderBlock;
| |||
| |||
param[7].type = TYPE_BOOL;
| |||
param[7].integer_value = InpFillOrderBlock;
| |||
| |||
param[8].type = TYPE_COLOR;
| |||
param[8].integer_value = InpColorOrderBlockBajista;
| |||
| |||
param[9].type = TYPE_COLOR;
| |||
param[9].integer_value = InpColorOrderBlockAlcista;
| |||
| |||
param[10].type = TYPE_DOUBLE;
| |||
param[10].double_value = InpTransparency;
| |||
| |||
param[11].type = TYPE_STRING;
| |||
param[11].string_value = "-- Strategy --";
| |||
| |||
param[12].type = TYPE_INT;
| |||
param[12].integer_value = InpTpSlStyle;
| |||
| |||
param[13].type = TYPE_STRING;
| |||
param[13].string_value = "- ATR";
| |||
| |||
param[14].type = TYPE_DOUBLE;
| |||
param[14].double_value = InpAtrMultiplier1;
| |||
| |||
param[15].type = TYPE_DOUBLE;
| |||
param[15].double_value = InpAtrMultiplier2;
| |||
| |||
param[16].type = TYPE_STRING;
| |||
param[16].string_value = "- POINT";
| |||
| |||
param[17].type = TYPE_INT;
| |||
param[17].integer_value = InpTpPoint;
| |||
| |||
param[18].type = TYPE_INT;
| |||
param[18].integer_value = InpSlPoint;
| |||
| |||
return IndicatorCreate(_Symbol, InpTimeframeOrderBlock, IND_CUSTOM, ArraySize(param), param);
| |||
}
| |||
| |||
#endif // MQLARTICLES_OB_INDICATOR_EACOMMON_MQH
| |||
//+------------------------------------------------------------------+
|