//                                                    RobotTendencia2.0.mq4
//+-------------------------------------------------------------------+
//|                                          Sistemas Inversores      |
//|                                 http://www.sistemasinversores.com |
//|                                                                   |
//|Copyright (c) 2011, Sistemas Inversores                            |
//|All rights reserved.                                               |
//|                                                                   |
//|Redistribution and use in source and binary forms, with or without |
//|modification, are permitted provided that the following conditions !
//|are met:                                                           |
//|                                                                   |  
//|Redistributions of source code must retain the above copyright     |
//|  notice, this list of conditions and the following disclaimer.    |
//|Redistributions in binary form must reproduce the above copyright  |
//|  notice, this list of conditions and the following disclaimer in  |
//|  the documentation and/or other materials provided with the       |
//|  distribution.                                                    |
//|                                                                   |     
//|THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS|
//|"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT  |
//|LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS  |
//|FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE     |
//|COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,         |
//|INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
//|(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
//|SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
//|HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,|
//|STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)      |
//|ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED|
//| OF THE POSSIBILITY OF SUCH DAMAGE.                                |
//+-------------------------------------------------------------------+
#property copyright "Alphadvisor"
#property link      "http://www.alphadvisor.com"

// Globales
string NombreDelEA = "RobotTendencia2.0";
string VersionEA = "v1.0";
extern int Slippage = 1;
extern int MagicNumber = 10009;
int MyPoint=1;
int TiposDeOrden[1];
bool allowDemo = true;
bool allowTesting = true;
bool allowOptimization = true;
int accountId = 0;
string caducity = "";
bool bAllowStrategy=true;

long contA=0;
long contB=0;
long contI=0;

enum CritOptimizacionEnum{
   sin_valor = 0,
   criterio_br = 1,
   criterio_sqn = 2
};

input CritOptimizacionEnum custom = criterio_sqn;


extern int Period_SME = 70;
extern int Period_rapida_compra = 7;
extern int Period_lenta_compra = 35;
extern int Period_rapida_venta = 7;
extern int Period_lenta_venta = 35;
extern int StopLoss = 95;
extern int TakeProfit = 0;




#include <stdlibSIv2.03.mqh>

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if(MagicNumber==0)
	MagicNumber = getMagicNumber(true);	

// D?gitos para brokers con pips fraccionarios.  
   if(Digits==3||Digits==5)MyPoint=10; else MyPoint=1;
   
   
	StopLoss = StopLoss*MyPoint;
	if(!comprobarStopLoss(StopLoss)){
		Alert("StopLoss: Se elimina StopLoss al ser menor que el mínimo para " + Symbol() + ": " + DoubleToStr(MarketInfo(Symbol(), MODE_STOPLEVEL),0));
		StopLoss=0;
	}
	TakeProfit = TakeProfit*MyPoint;
	if(!comprobarTakeProfit(TakeProfit)){
		Alert("TakeProfit: Se elimina TakeProfit al ser menor que el mínimo para " + Symbol() + ": " + DoubleToStr(MarketInfo(Symbol(), MODE_STOPLEVEL),0));
		TakeProfit=0;
	}

//----

   bAllowStrategy = checkStrategy();
   
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
    if(IsTesting()){
        Print("******************************************************");
        Print("*-*-*-*-*- Resumen de Alphadvisor *-*-*-*-*");
        Print("******************************************************");
        Print("Velas alcistas: " + contA);
        Print("Velas bajistas: " + contB);
        Print("Velas planas: " + contI);
        long contTotal=contA+contB;
        Print("Velas totales: " + contTotal);
        Print("******************************************************");   
    }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
      if( bAllowStrategy == false ) return (0);   
   
    //para el resumen
    if(AB_OrdenesAbiertasEA(0, 0) && IsTesting()){
        if(Open[1]<Close[1]) contA++;
        else if(Open[1]>Close[1]) contB++;
        else contI++;         
     }  
      
//----
   if (!AB_NuevaVela("Robot Tendencia 2.0", 1, false, 10009)) return;
if (AB_OrdenesAbiertasEA(3, 0)) {
if (iMA( NULL, 0, 7, 0, 1, 0, 1) < iMA( NULL, 0, 35, 0, 1, 0, 1)) {
AB_CerrarPosicion(AB_GetTicketByName("LARGO"));



}

}
if (AB_OrdenesAbiertasEA(4, 0)) {
if (iMA( NULL, 0, 7, 0, 1, 0, 1) > iMA( NULL, 0, 35, 0, 1, 0, 1)) {
AB_CerrarPosicion(AB_GetTicketByName("CORTO"));



}

}
if (iRSI( NULL, 0, 14, 0, 1) > 50) {
if (iStdDev( NULL, 0, 7, 1, 1, 0, 1) > 0.001) {
if (iMA( NULL, 0, 20, 0, 1, 0, 1) > iMA( NULL, 0, Period_SME, 0, 1, 0, 1)) {
if (iMA( NULL, 0, Period_rapida_compra, 0, 1, 0, 1) > iMA( NULL, 0, Period_lenta_compra, 0, 1, 0, 1)) {
if(AB_Comprar("LARGO", StopLoss, TakeProfit, getFixedLot( 0.1 ), "")){
}


}

}

}

}
if (iRSI( NULL, 0, 14, 0, 1) < 50) {
if (iStdDev( NULL, 0, 7, 1, 1, 0, 1) > 0.001) {
if (iMA( NULL, 0, 20, 0, 1, 0, 1) < iMA( NULL, 0, Period_SME, 0, 1, 0, 1)) {
if (iMA( NULL, 0, Period_rapida_venta, 0, 1, 0, 1) < iMA( NULL, 0, Period_lenta_venta, 0, 1, 0, 1)) {
if(AB_Vender("CORTO", StopLoss, TakeProfit, getFixedLot( 0.1 ), "")){
}


}

}

}

}


//----
   return(0);
  }

//+------------------------------------------------------------------+
//| Tester function                                                  |
//+------------------------------------------------------------------+
double OnTester()
{  
   double ret=0.0;
   
   if(IsOptimization()){ 
        if(custom == criterio_br){
           double  profit = TesterStatistics(STAT_PROFIT);
           double  max_dd = TesterStatistics(STAT_BALANCE_DD);
           if(max_dd != 0.0)
              ret = profit/max_dd;
           else
             ret=-1;
        }else if(custom == criterio_sqn){
            int hstTotal=OrdersHistoryTotal();
            double tradesProfits[];
            ArrayResize(tradesProfits, hstTotal);
            double totalProfit = 0.0;
            for(int i=0;i<hstTotal;i++)
            {                
                OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
                tradesProfits[i]=OrderProfit();
                totalProfit += tradesProfits[i];
            }            

            if(hstTotal != 0)
                double average = totalProfit/hstTotal;

            double stdDev = standardDeviation(tradesProfits, average);
            if(stdDev != 0.0)               
                ret = (average / stdDev) * MathSqrt(hstTotal);
            else
               ret = -1;
        }   
    }
   return (ret);
}
//+------------------------------------------------------------------+

void AB_GetTipos(int tipo)
{
	switch(tipo)
	{
		case -1:	// Todos
		case 0:	// Todos
			ArrayResize(TiposDeOrden, 6);
			for (int i=0; i<6; i++)
				TiposDeOrden[i] = i;
			break;
		case 1: 	// Largos
			ArrayResize(TiposDeOrden, 3);
			TiposDeOrden[0] = 0;
			TiposDeOrden[1] = 2;
			TiposDeOrden[2] = 4;
			break;
		case 2: 	// Cortos
			ArrayResize(TiposDeOrden, 3);
			TiposDeOrden[0] = 1;
			TiposDeOrden[1] = 3;
			TiposDeOrden[2] = 5;
			break;
		default: 	// OP_BUY = 3, OP_SELL =4, etc.
			ArrayResize(TiposDeOrden, 1);
			TiposDeOrden[0] = tipo-3;
			break;
	}
}

bool AB_Comprar(string nombre, int SL, int TP, double lots, string symbol = "")
{
   if (symbol=="") symbol = Symbol();
	// Vemos si ya est? la posici?n abierta
	int ticket = AB_GetTicketByName(nombre);
	int resultado = 0;
	bool permitirAbrir = false;
	
	if (ticket<=0)
		permitirAbrir = true;
	else
	{
		OrderSelect(ticket, SELECT_BY_TICKET);
		if (OrderType()==OP_SELL || OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP)
		{
			cerrarPosicion(ticket);
			permitirAbrir = true;
		}
	}

	if (permitirAbrir)
	{
		string comentario = NombreDelEA + " " + getPeriodAsString(Period()) + ";" + nombre;
	
	   double sl = getSL(OP_BUY, SL);
	   
      resultado = abrirPosicion(symbol, OP_BUY, 0, sl, getTP(OP_BUY, TP), NormalizeLots(lots), comentario);
      if (resultado == -1)
	  	return (false);
	  else
	  	return (true);
	}
	return (false);
	
}

bool AB_CompraPendiente(string nombre, int SL, int TP, double precio, double lots, string symbol = "",int velasParaExpirar=0)
{
   if (symbol=="") symbol = Symbol();
	// Vemos si ya est? la posici?n abierta
	int ticket = AB_GetTicketByName(nombre);
	bool permitirAbrir = false;
	
	if (ticket<=0)
		permitirAbrir = true;
	else
	{
		OrderSelect(ticket, SELECT_BY_TICKET);
		if (OrderType()==OP_SELL || OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP)
		{
			cerrarPosicion(ticket);
			permitirAbrir = true;
		}
	}

	if (permitirAbrir)
	{
		string comentario = NombreDelEA + " " + getPeriodAsString(Period()) + ";" + nombre;
	
	   double sl = getSL(OP_BUYSTOP, SL, precio);
	   int et = TimeCurrent()+(Period()*60)*velasParaExpirar;
	   	
      abrirPosicion(symbol, OP_BUYSTOP, precio, getSL(OP_BUYSTOP, SL, precio), getTP(OP_BUYSTOP, TP, precio), NormalizeLots(lots),comentario,et);
	}
}

bool AB_Vender(string nombre, int SL, int TP, double lots, string symbol = "")
{
   if (symbol=="") symbol = Symbol();

	// Vemos si ya est? la posici?n abierta
	int ticket = AB_GetTicketByName(nombre);
	bool permitirAbrir = false;
	
	if (ticket<=0)
		permitirAbrir = true;
	else
	{
		OrderSelect(ticket, SELECT_BY_TICKET);
		if (OrderType()==OP_BUY || OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP)
		{
			cerrarPosicion(ticket);
			permitirAbrir = true;
		}
	}
	
	if (permitirAbrir)
	{
		string comentario = NombreDelEA + " " + getPeriodAsString(Period()) + ";" + nombre;
	
	   double sl = getSL(OP_SELL, SL);
	   	
      abrirPosicion(symbol, OP_SELL, 0, sl, getTP(OP_SELL, TP), NormalizeLots(lots), comentario);
	}
}

bool AB_VendePendiente(string nombre, int SL, int TP, double precio, double lots, string symbol = "", int velasParaExpirar=0)
{
   if (symbol=="") symbol = Symbol();
	// Vemos si ya est? la posici?n abierta
	int ticket = AB_GetTicketByName(nombre);
	bool permitirAbrir = false;
	
	if (ticket<=0)
		permitirAbrir = true;
	else
	{
		OrderSelect(ticket, SELECT_BY_TICKET);
		if (OrderType()==OP_BUY || OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP)
		{
			cerrarPosicion(ticket);
			permitirAbrir = true;
		}
	}
	
	if (permitirAbrir)
	{
		string comentario = NombreDelEA + " " + getPeriodAsString(Period()) + ";" + nombre;
	
	   double sl = getSL(OP_SELLSTOP, SL, precio);
	   
	   int et = TimeCurrent()+(Period()*60)*velasParaExpirar;
	   	
      abrirPosicion(symbol, OP_SELLSTOP, precio, sl, getTP(OP_SELLSTOP, TP, precio), NormalizeLots(lots), comentario, et);
	}
}

bool AB_OrdenesTotalesEA(int tipo, int numero)
{
	int total = 0;
	AB_GetTipos(tipo);
	
	for (int i=0; i<ArraySize(TiposDeOrden); i++)
	{
		total+=ordenesTotalesEA(TiposDeOrden[i]);
	}
	return (total>numero);
}

bool AB_OrdenesAbiertasEA(int tipo, int numero)
{
	int total = 0;
	AB_GetTipos(tipo);
	
	for (int i=0; i<ArraySize(TiposDeOrden); i++)
	{
		if (TiposDeOrden[i]!=OP_BUY && TiposDeOrden[i]!=OP_SELL) continue;
		total+=ordenesTotalesEA(TiposDeOrden[i]);
	}
	return (total>numero);
}

bool AB_OrdenesPendientesEA(int tipo, int numero)
{
	int total = 0;
	AB_GetTipos(tipo);
	
	for (int i=0; i<ArraySize(TiposDeOrden); i++)
	{
		if (TiposDeOrden[i]==OP_BUY || TiposDeOrden[i]==OP_SELL) continue;
		total+=ordenesTotalesEA(TiposDeOrden[i]);
	}
	return (total>numero);
}


bool AB_NuevaVela(string ignore1 = "", int ignore2 = 0, bool ignoreFirstCandle = false, int MN = 0)
{
	static datetime last = 0;
	
	if (ignoreFirstCandle && last==0)
	  last = Time[0];
	
	if (Time[0]!=last)
	{
		last = Time[0];
		return (true);
	}
	
	return (false);
}

void AB_CerrarPosiciones(int tipo)
{
	AB_GetTipos(tipo);

	for (int i=0; i<ArraySize(TiposDeOrden); i++)
	{
		cerrarPosiciones(TiposDeOrden[i]);
	}
}

void AB_CerrarPosicion(int ticket)
{
	if (ticket<1) return;
	
	cerrarPosicion(ticket);
}

void AB_CerrarPendientes(int tipo)
{
	AB_GetTipos(tipo);

	for (int i=0; i<ArraySize(TiposDeOrden); i++)
	{
		if (TiposDeOrden[i]==OP_BUY || TiposDeOrden[i]==OP_SELL) continue;
		cerrarPosiciones(TiposDeOrden[i]);
	}
}

void AB_CerrarAbiertas(int tipo)
{
	AB_GetTipos(tipo);

	for (int i=0; i<ArraySize(TiposDeOrden); i++)
	{
		if (TiposDeOrden[i]!=OP_BUY && TiposDeOrden[i]!=OP_SELL) continue;
		cerrarPosiciones(TiposDeOrden[i]);
	}
}

int AB_GetTicketByName(string nombre)
{
   if (nombre=="") return (0);

	string comentario = NombreDelEA + " " + getPeriodAsString(Period()) + ";" + nombre;

	// El tama?o m?ximo de los comentarios es de 31 caracteres
	if (StringLen(comentario)>31)
	  comentario = StringSubstr(comentario, 0, 31);

   for (int i=0; i<OrdersTotal(); i++)
   {
      if (!(OrderSelect(i, SELECT_BY_POS) && OrderMagicNumber()==MagicNumber)) continue;
   
   	  if (OrderComment()==comentario)
   	  	return (OrderTicket());
   }
   
   return (0);
}

int AB_GetTicketHistoryByName(string nombre)
{
   if (nombre=="") return (0);

	string comentario = NombreDelEA + " " + getPeriodAsString(Period()) + ";" + nombre;

	// El tama?o m?ximo de los comentarios es de 31 caracteres - [sl] or [tp] == 27
	if (StringLen(comentario)>27)
	  comentario = StringSubstr(comentario, 0, 27);
   int commentSize = StringLen(comentario);
   int ticket = 0;
   for (int i=0; i<OrdersHistoryTotal(); i++)
   {
      if (!(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && OrderMagicNumber()==MagicNumber)) continue;
   	  if (StringSubstr(OrderComment(),0,commentSize)==comentario){
   	     ticket = MathMax(ticket, OrderTicket());
   	  }
   }

   return (ticket);
}

void AB_TrailingStop(string nombre, int trigger, int distancia)
{
	if (nombre=="")
	{
		ajustarTrailingStopTodas(trigger, distancia);
	}
	else
	{
		int ticket = AB_GetTicketByName(nombre);

		if (ticket>0)
			ajustarTrailingStop(ticket, trigger, distancia);
	}
}

void AB_MoverPending(string nombre, double precio)
{
	int ticket = AB_GetTicketByName(nombre);
	
	if (ticket>0)
		modificarPendiente(ticket, precio);
}

void AB_BreakEven(string nombre, int puntos)
{
	// Una o todas
	if (nombre=="")
	{
		ajustarBreakEvenTodas(puntos);
	}
	else
	{
		int ticket = AB_GetTicketByName(nombre);

		if (ticket>0)
			ajustarBreakEven(ticket, puntos);
	}
}

void AB_TakeDinamico(string nombre, double precio, int offset)
{
	if (nombre=="")
	{
	   for (int i=0; i<OrdersTotal(); i++)
	   {
	      if (!(OrderSelect(i, SELECT_BY_POS) && OrderMagicNumber()==MagicNumber)) continue;
	   
	      if (OrderType()==OP_BUY || OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP)
	           modificarTakeProfit(OrderTicket(), precio+(offset*Point));
	      else
	           modificarTakeProfit(OrderTicket(), precio-(offset*Point));
	   }
	}
	else
	{
		int ticket = AB_GetTicketByName(nombre);
		
		if (ticket>0)
		{
		    // Selecciono la orden
		    OrderSelect(ticket, SELECT_BY_TICKET);
	      if (OrderType()==OP_BUY || OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP)
	           modificarTakeProfit(ticket, precio+(offset*Point));
	      else
	           modificarTakeProfit(ticket, precio-(offset*Point));
	   }
	}
}

void AB_StopDinamico(string nombre, double precio, int offset)
{
	if (nombre=="")
	{
	   for (int i=0; i<OrdersTotal(); i++)
	   {
	      if (!(OrderSelect(i, SELECT_BY_POS) && OrderMagicNumber()==MagicNumber)) continue;
	   
	      if (OrderType()==OP_BUY || OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP)
	           modificarStopLoss(OrderTicket(), precio-(offset*Point));
	      else
	           modificarStopLoss(OrderTicket(), precio+(offset*Point));
	   }
	}
	else
	{
		int ticket = AB_GetTicketByName(nombre);
		
		if (ticket>0)
		{
		    // Selecciono la orden
		    OrderSelect(ticket, SELECT_BY_TICKET);
	      if (OrderType()==OP_BUY || OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP)
	           modificarStopLoss(ticket, precio-(offset*Point));
	      else
	           modificarStopLoss(ticket, precio+(offset*Point));
	   }
	}
}

bool AB_ExisteOrden(string nombre)
{
	int ticket = AB_GetTicketByName(nombre);
	
	if (ticket<=0) return (false);
	
	if (!(OrderSelect(ticket, SELECT_BY_TICKET) && OrderMagicNumber()==MagicNumber)) return (False);
	
	return (true);
}

bool AB_ExisteOrdenAbierta(string nombre)
{
	int ticket = AB_GetTicketByName(nombre);
	
	if (ticket<=0) return (false);
	
	if (!(OrderSelect(ticket, SELECT_BY_TICKET) && OrderMagicNumber()==MagicNumber)) return (False);
	
	if (OrderType()!=OP_BUY && OrderType()!=OP_SELL) return (false);
	
	return (true);
}

bool AB_ExisteOrdenPendiente(string nombre)
{
	int ticket = AB_GetTicketByName(nombre);
	
	if (ticket<=0) return (false);
	
	if (!(OrderSelect(ticket, SELECT_BY_TICKET) && OrderMagicNumber()==MagicNumber)) return (False);

	if (OrderType()==OP_BUY || OrderType()==OP_SELL) return (false);
	
	return (true);
}


bool AB_BeneficioMayor(string nombre, int pips)
{
   if (nombre!="")
   {
	  int ticket = AB_GetTicketByName(nombre);
	
	  if (ticket<=0) return (false);
	
	  if (!(OrderSelect(ticket, SELECT_BY_TICKET) && OrderMagicNumber()==MagicNumber)) return (False);
	
	  if (OrderProfitPoints(ticket) > pips)
	    return (true);
	}
	else
	{
	  // No se indica operaci?n, se comprueban todas
	  double total = 0;
	  for (int i=0; i<OrdersTotal(); i++)
	  {
	      if (!(OrderSelect(i, SELECT_BY_POS) && OrderMagicNumber()==MagicNumber)) continue;
	   
	      total = total + OrderProfitPoints(OrderTicket());
	  }
	  if (total>pips)
	     return (true);
	}
	return (false);
}

bool AB_VelasAbierta(string nombre, int nVelas)
{
	int ticket = AB_GetTicketByName(nombre);
	
	if (ticket<=0) return (false);
	
	if (!(OrderSelect(ticket, SELECT_BY_TICKET) && OrderMagicNumber()==MagicNumber)) return (False);
	
	// Apertura de la orden
	datetime apertura = OrderOpenTime();
	
	if (iBarShift(Symbol(), 0, apertura)>=nVelas)
	  return (true);
	
	return (false);
}

bool AB_Horario(int horainicio, int minutoinicio, int horafin, int minutofin)
{
	if (horainicio<horafin)																// Las 00:00 no est?n incluidas
	{
		if (TimeHour(TimeCurrent()) > horainicio && TimeHour(TimeCurrent())<horafin)	// No estamos en hora de inicio ni de fin
			return (true);
		if (TimeHour(TimeCurrent()) == horainicio)										// En hora de inicio
		{
			if (TimeMinute(TimeCurrent()) >= minutoinicio)								// Comprobamos minuto inicio
				return (true);
		}
		if (TimeHour(TimeCurrent()) == horafin)										// En hora de fin
		{
			if (TimeMinute(TimeCurrent()) < minutofin)									// Comprobamos minuto fin
				return (true);
		}
	}
	if (horainicio>horafin)																// Las 00:00 est?n incluidas
	{
		if (TimeHour(TimeCurrent()) > horainicio || TimeHour(TimeCurrent())<horafin)
			return (true);
		if (TimeHour(TimeCurrent()) == horainicio)
		{
			if (TimeMinute(TimeCurrent()) >= minutoinicio)
				return (true);
		}
		if (TimeHour(TimeCurrent())==horafin)
		{
			if (TimeMinute(TimeCurrent()) < minutofin)
				return (true);
		}
	}
	if (horainicio==horafin)															// Misma hora de inicio que de fin
	{
		if (TimeHour(TimeCurrent()) == horainicio && TimeHour(TimeCurrent()) == horafin)	// Si estamos en la hora
		{
			if (minutoinicio<minutofin)														
			{
				if (TimeMinute(TimeCurrent()) >= minutoinicio && TimeMinute(TimeCurrent()) < minutofin)
					return (true);
			}
			if (minutoinicio>minutofin)
			{
				if (TimeMinute(TimeCurrent()) >= minutoinicio || TimeMinute(TimeCurrent()) < minutofin)
					return (true);
			}
			if (minutoinicio==minutofin)
			{
				if (TimeMinute(TimeCurrent()) == minutoinicio)
					return (true);
			}
		}
		else																		// Si no estamos en la hora, ser?
		{																			// true si inicio>fin (23 horas y pico true)
			if (minutoinicio>minutofin) return(true);
		}
	}
	
	return (false);
}

bool AB_DiaSemana(bool lunes, bool martes, bool miercoles, bool jueves, bool viernes, bool sabado, bool domingo)
{
	switch(TimeDayOfWeek(TimeCurrent()))
	{
		case 0:
			return (domingo);
			break;
		case 1:
			return (lunes);
			break;
		case 2:
			return (martes);
			break;
		case 3:
			return (miercoles);
			break;
		case 4:
			return (jueves);
			break;
		case 5:
			return (viernes);
			break;
		case 6:
			return (sabado);
			break;
	}
	
	return (false);
}

bool AB_Subiendo(double val1, double val2)
{
   return (val1>val2);
}

bool AB_Bajando(double val1, double val2)
{
   return (val1<val2);
}

bool AB_CruceAlcista(double rapido1, double rapido2, double rapido3, double rapido4, double rapido5, double rapido6, double rapido7,
   double lento1, double lento2, double lento3, double lento4, double lento5, double lento6, double lento7)
{
   // Compruebo hacia atr?s si los cruces son iguales
   if (rapido1>lento1 && rapido2<lento2)
      return (True);
   if (rapido1>lento1 && rapido2==lento2 && rapido3<lento3)
      return (true);
   if (rapido1>lento1 && rapido2==lento2 && rapido3==lento3 && rapido4<lento4)
      return (true);
   if (rapido1>lento1 && rapido2==lento2 && rapido3==lento3 && rapido4==lento4 && rapido5<lento5)
      return (true);
   if (rapido1>lento1 && rapido2==lento2 && rapido3==lento3 && rapido4==lento4 && rapido5==lento5 && rapido6<lento6)
      return (true);
   if (rapido1>lento1 && rapido2==lento2 && rapido3==lento3 && rapido4==lento4 && rapido5==lento5 && rapido6==lento6 && rapido7<lento7)
      return (true);
   
   return (false);
}

bool AB_CruceBajista(double rapido1, double rapido2, double rapido3, double rapido4, double rapido5, double rapido6, double rapido7,
   double lento1, double lento2, double lento3, double lento4, double lento5, double lento6, double lento7)
{
   if (rapido1<lento1 && rapido2>lento2)
      return (True);
   if (rapido1<lento1 && rapido2==lento2 && rapido3>lento3)
      return (true);
   if (rapido1<lento1 && rapido2==lento2 && rapido3==lento3 && rapido4>lento4)
      return (true);
   if (rapido1<lento1 && rapido2==lento2 && rapido3==lento3 && rapido4==lento4 && rapido5>lento5)
      return (true);
   if (rapido1<lento1 && rapido2==lento2 && rapido3==lento3 && rapido4==lento4 && rapido5==lento5 && rapido6>lento6)
      return (true);
   if (rapido1<lento1 && rapido2==lento2 && rapido3==lento3 && rapido4==lento4 && rapido5==lento5 && rapido6==lento6 && rapido7>lento7)
      return (true);
   
   return (false);
}

bool AB_EncimaNivel ( double indicador, double nivel )
{
   return (indicador>nivel);
}

bool AB_DebajoNivel ( double indicador, double nivel )
{
   return (indicador<nivel);
}

bool AB_CruzaAlzaNivel ( double indicador1, double indicador2, double indicador3, double indicador4, double indicador5, double indicador6, double indicador7, 
                           double nivel1, double nivel2, double nivel3, double nivel4, double nivel5, double nivel6, double nivel7 )
{
   // nivel2 y siguientes no sirven para nada
   if (indicador1>nivel1 && indicador2<nivel1)
      return (true);
   if (indicador1>nivel1 && indicador2==nivel1 && indicador3<nivel1)
      return (true);
   if (indicador1>nivel1 && indicador2==nivel1 && indicador3==nivel1 && indicador4<nivel1)
      return (true);
   if (indicador1>nivel1 && indicador2==nivel1 && indicador3==nivel1 && indicador4==nivel1 && indicador5<nivel1)
      return (true);
   if (indicador1>nivel1 && indicador2==nivel1 && indicador3==nivel1 && indicador4==nivel1 && indicador5==nivel1 && indicador6<nivel1)
      return (true);
   if (indicador1>nivel1 && indicador2==nivel1 && indicador3==nivel1 && indicador4==nivel1 && indicador5==nivel1 && indicador6==nivel1 && indicador7<nivel1)
      return (true);
   
   return (false);
}

bool AB_CruzaBajaNivel ( double indicador1, double indicador2, double indicador3, double indicador4, double indicador5, double indicador6, double indicador7, 
                           double nivel1, double nivel2, double nivel3, double nivel4, double nivel5, double nivel6, double nivel7 )
{
   // nivel2 no sirve y siguientes no sirven para nada
   if (indicador1<nivel1 && indicador2>nivel1)
      return (true);
   if (indicador1<nivel1 && indicador2==nivel1 && indicador3>nivel1)
      return (true);
   if (indicador1<nivel1 && indicador2==nivel1 && indicador3==nivel1 && indicador4>nivel1)
      return (true);
   if (indicador1<nivel1 && indicador2==nivel1 && indicador3==nivel1 && indicador4==nivel1 && indicador5>nivel1)
      return (true);
   if (indicador1<nivel1 && indicador2==nivel1 && indicador3==nivel1 && indicador4==nivel1 && indicador5==nivel1 && indicador6>nivel1)
      return (true);
   if (indicador1<nivel1 && indicador2==nivel1 && indicador3==nivel1 && indicador4==nivel1 && indicador5==nivel1 && indicador6==nivel1 && indicador7>nivel1)
      return (true);

   return (false);
}
double AB_GetSpreadInPoints(string symbol){
   return (MarketInfo(symbol,MODE_SPREAD)*Point);
}

double AB_GetSpread(string symbol){
   return (MarketInfo(symbol,MODE_SPREAD));
}

double AB_PrecioAperturaOrden(string nombre){

   int ticket = AB_GetTicketByName(nombre);
  
   // ordenes abiertos   
   if( ticket > 0 ){
      OrderSelect(ticket, SELECT_BY_TICKET);
      return (OrderOpenPrice());
   }

   // ordenes cerrados
   ticket = AB_GetTicketHistoryByName(nombre);
   if( ticket > 0 ){
      OrderSelect(ticket, SELECT_BY_TICKET);
      return (OrderOpenPrice());
   }

   return (0);
}

double AB_PrecioCierreOrden(string nombre){

   int ticket = AB_GetTicketByName(nombre);
  
   // ordenes abiertos   
   if( ticket > 0 ){
      OrderSelect(ticket, SELECT_BY_TICKET);
      return (OrderClosePrice());
   }
   ticket = AB_GetTicketHistoryByName(nombre);
   
   if( ticket > 0 ){
      OrderSelect(ticket, SELECT_BY_TICKET);
      return (OrderClosePrice());
   }
   return (0);
}

int AB_PipsBeneficioOrden(string nombre){

   int ticket = AB_GetTicketByName(nombre);
   int profit=0;
   
   // miramos primero en los ordenes abiertos
   
   // ordenes abiertos   
   if( ticket > 0 ) {
      OrderSelect(ticket, SELECT_BY_TICKET);
      
      profit = OrderProfitPoints(ticket)/MyPoint;
      
      return (MathMax(0, profit));
   }
   
   // ordenes cerrados
   ticket = AB_GetTicketHistoryByName(nombre);
   if( ticket > 0 ) {
      OrderSelect(ticket, SELECT_BY_TICKET);
      
      profit = OrderProfitPoints(ticket)/MyPoint;
      
      return (MathMax(0, profit));
   }
   
   return (0);
}

int AB_PipsPerdidaOrden(string nombre){

   int ticket = AB_GetTicketByName(nombre);
   int profit=0.0;
   // miramos primero en los ordenes abiertos
   
   // ordenes abiertos   
   if( ticket > 0 ) {
      OrderSelect(ticket, SELECT_BY_TICKET);
      
      profit = OrderProfitPoints(ticket)/MyPoint;
      
      return (MathAbs(MathMin(0, profit)));
   }
   
   // ordenes cerrados
   ticket = AB_GetTicketHistoryByName(nombre);
   if( ticket > 0 ) {
      OrderSelect(ticket, SELECT_BY_TICKET);
      
      profit = OrderProfitPoints(ticket)/MyPoint;
      
      return (MathAbs(MathMin(0, profit)));
   }
   return (0);
}

double AB_BeneficioOrden(string nombre){

   int ticket = AB_GetTicketByName(nombre);
   
   // miramos primero en los ordenes abiertos
   if( ticket > 0 ) {
      OrderSelect(ticket, SELECT_BY_TICKET);
      
      return (MathMax(0, OrderProfit()));
   }
   
   // ordenes cerrados
   ticket = AB_GetTicketHistoryByName(nombre);
   if( ticket > 0 ) {
      OrderSelect(ticket, SELECT_BY_TICKET);
      
      return (MathMax(0, OrderProfit()));
   }
   
   return (0);
}
double AB_PerdidaOrden(string nombre){

   int ticket = AB_GetTicketByName(nombre);
   
   // miramos primero en los ordenes abiertos
   if( ticket > 0 ) {
      OrderSelect(ticket, SELECT_BY_TICKET);
      
      return (MathAbs(MathMin(0, OrderProfit())));
   }
   
   // ordenes cerrados
   ticket = AB_GetTicketHistoryByName(nombre);
   if( ticket > 0 ) {
      OrderSelect(ticket, SELECT_BY_TICKET);
      
      return (MathAbs(MathMin(0, OrderProfit())));
   }
   
   return (0);
}

int AB_VelasAbiertaOrden(string nombre)
{
	int ticket = AB_GetTicketByName(nombre);

   // ordenes abiertos	
	if( ticket > 0 ) {
	  OrderSelect(ticket, SELECT_BY_TICKET);
	  return (iBarShift(Symbol(), 0, OrderOpenTime()));
	}
	
	// ordenes cerrados
   ticket = AB_GetTicketHistoryByName(nombre);
	if( ticket > 0 ) {
      OrderSelect(ticket, SELECT_BY_TICKET);
	   return (iBarShift(Symbol(), 0, OrderOpenTime())-iBarShift(Symbol(), 0, OrderCloseTime()));
	}

	return (0);
}
bool AB_CierrePorStopLossOrden(string nombre){

   int ticket = AB_GetTicketByName(nombre);
  
   // ordenes abiertos   
   if( ticket > 0 ){
      return (false);
   }
   // ordenes cerrados
   ticket = AB_GetTicketHistoryByName(nombre);
   
   if( ticket > 0 ) {
      OrderSelect(ticket, SELECT_BY_TICKET);
      return (OrderClosePrice() == OrderStopLoss());
   }
   return (false);
}
bool AB_CierrePorTakeProfitOrden(string nombre){

   int ticket = AB_GetTicketByName(nombre);
  
   // ordenes abiertos   
   if( ticket > 0 ){
      return (false);
   }
   // ordenes cerrados
   ticket = AB_GetTicketHistoryByName(nombre);
   
   if( ticket > 0 ) {
      OrderSelect(ticket, SELECT_BY_TICKET);
      return (OrderClosePrice() == OrderTakeProfit());
   }
   return (false);
}

bool AB_UltimoValorMasReciente(string indicator1, string parametros1, string indicator2, string parametros2){
   string params[];
   double values[];
   int nbValues = 0;
   int period;
   string customIndicatorName;
   int start=2;
   
   // indicador 1
   stringSplit(params, parametros1, "|");
   
   period = StrToInteger(params[1]);
   if( indicator1 == "iCustom"){
      start=3;
      customIndicatorName = params[2];
      nbValues= ArraySize(params)-4; //quitamos el symbol, period, customIndicatorName y shift
   }else{
      start=2;
      nbValues= ArraySize(params)-3; //quitamos el symbol, period y shift
   }
   
   ArrayResize(values, nbValues); 
   for (int i = 0; i < nbValues; i++){
      values[i] = StrToDouble(stringTrim(params[i+start]));
      
   }

   int shift1 = StrToInteger(params[ArraySize(params)-1]);
   double val=0;
   while((val == 0 || val==EMPTY_VALUE) && (shift1<Bars)){
      if( (params[0] == "NULL") || (params[0] == "Symbol()")){
         val = getValue1( indicator1, period, customIndicatorName, nbValues, values, shift1);  
      } else {
         val = getValue2( indicator1, params[0], period, customIndicatorName, nbValues, values, shift1);  
      }
       shift1++;
   } 

   // indicador 2
   stringSplit(params, parametros2, "|");
   period = StrToInteger(params[1]);
   if( indicator2 == "iCustom"){
      start=3;
      customIndicatorName = params[2];
      nbValues= ArraySize(params)-4; //quitamos el symbol, period, customIndicatorName y shift
   }else{
      start=2;
      nbValues= ArraySize(params)-3; //quitamos el symbol, period y shift
   }
   
   ArrayResize(values, nbValues); 
   for (i = 0; i < nbValues; i++){
      values[i] = StrToDouble(stringTrim(params[i+start]));
   }

   int shift2 = StrToInteger(params[ArraySize(params)-1]);
   val=0;
   while((val == 0 || val==EMPTY_VALUE) && (shift2<Bars)){
      if( (params[0] == "NULL") || (params[0] == "Symbol()")){
         val = getValue1( indicator2, period, customIndicatorName, nbValues, values, shift2);  
      } else {
         val = getValue2( indicator2, params[0], period, customIndicatorName, nbValues, values, shift2);  
      } 
      shift2++;
   } 
   
   if( shift1<shift2){
      return (true);
   }
   return (false);
}

bool AB_VelasUltimoValorMasReciente(string indicator, string parametros, int nVelas){
   string params[];
   double values[];
   int nbValues = 0;
   int period;
   string customIndicatorName;
   int start=2;
   
   // indicador 1
   stringSplit(params, parametros, "|");
   
   period = StrToInteger(params[1]);
   if( indicator == "iCustom"){
      start=3;
      customIndicatorName = params[2];
      nbValues= ArraySize(params)-4; //quitamos el symbol, period, customIndicatorName y shift
   }else{
      start=2;
      nbValues= ArraySize(params)-3; //quitamos el symbol, period y shift
   }
   
   ArrayResize(values, nbValues); 
   for (int i = 0; i < nbValues; i++){
      values[i] = StrToDouble(stringTrim(params[i+start]));
      
   }

   int shift1 = StrToInteger(params[ArraySize(params)-1]);
   double val=0;
   while((val == 0 || val==EMPTY_VALUE) && (shift1<Bars)){
      if( (params[0] == "NULL") || (params[0] == "Symbol()")){
         val = getValue1( indicator, period, customIndicatorName, nbValues, values, shift1);  
      } else {
         val = getValue2( indicator, params[0], period, customIndicatorName, nbValues, values, shift1);  
      }
      shift1++;
   } 
   
   return (shift1<=nVelas);
}

double AB_UltimoValorIndicador(string indicator, string parametros){
  string params[];
   double values[];
   int nbValues = 0;
   int period;
   string customIndicatorName;
   int start=2;
   
   stringSplit(params, parametros, "|");
   
   period = StrToInteger(params[1]);
   if( indicator == "iCustom"){
      start=3;
      customIndicatorName = params[2];
      nbValues= ArraySize(params)-4; //quitamos el symbol, period, customIndicatorName y shift
   }else{
      start=2;
      nbValues= ArraySize(params)-3; //quitamos el symbol, period y shift
   }
   
   ArrayResize(values, nbValues); 
   for (int i = 0; i < nbValues; i++){
      values[i] = StrToDouble(stringTrim(params[i+start]));
      
   }

   int shift = StrToInteger(params[ArraySize(params)-1]);
   double val=0;
   while((val == 0 || val==EMPTY_VALUE) && (shift<Bars)){
      if( (params[0] == "NULL") || (params[0] == "Symbol()") || (params[0] == "0")){
         val = getValue1( indicator, period, customIndicatorName, nbValues, values, shift);  
      } else {
         val = getValue2( indicator, params[0], period, customIndicatorName, nbValues, values, shift);  
      }
      shift++;
   } 
   
   val = NormalizeDouble(val,Digits);
   
   return (val);
}
bool AB_UltimoValorMayorQueHigh(string indicator, string parametros){
   string params[];
   double values[];
   int nbValues = 0;
   int period;
   string customIndicatorName;
   int start=2;
   
   stringSplit(params, parametros, "|");
   
   period = StrToInteger(params[1]);
   if( indicator == "iCustom"){
      start=3;
      customIndicatorName = params[2];
      nbValues= ArraySize(params)-4; //quitamos el symbol, period, customIndicatorName y shift
   }else{
      start=2;
      nbValues= ArraySize(params)-3; //quitamos el symbol, period y shift
   }
   
   ArrayResize(values, nbValues); 
   for (int i = 0; i < nbValues; i++){
      values[i] = StrToDouble(stringTrim(params[i+start]));
      
   }

   int shift = StrToInteger(params[ArraySize(params)-1]);
   double val=0;
   double high = 0;
   while((val == 0 || val==EMPTY_VALUE) && (shift<Bars)){
      if( (params[0] == "NULL") || (params[0] == "Symbol()")){
         val = getValue1( indicator, period, customIndicatorName, nbValues, values, shift);  
         high = High[shift];
      } else {
         val = getValue2( indicator, params[0], period, customIndicatorName, nbValues, values, shift);  
         high = iHigh(params[0],period,shift); 
      }
       shift++;
   } 
   
   val = NormalizeDouble(val,Digits);
   
   if( val >= high){
      return (true);
   }
   return (false);
}

bool AB_UltimoValorMenorQueLow(string indicator, string parametros){
   string params[];
   double values[];
   int nbValues = 0;
   int period;
   string customIndicatorName;
   int start=2;
   
   stringSplit(params, parametros, "|");
   
   period = StrToInteger(params[1]);
   if( indicator == "iCustom"){
      start=3;
      customIndicatorName = params[2];
      nbValues= ArraySize(params)-4; //quitamos el symbol, period, customIndicatorName y shift
   }else{
      start=2;
      nbValues= ArraySize(params)-3; //quitamos el symbol, period y shift
   }
   
   ArrayResize(values, nbValues); 
   for (int i = 0; i < nbValues; i++){
      values[i] = StrToDouble(stringTrim(params[i+start]));
      
   }

   int shift = StrToInteger(params[ArraySize(params)-1]);
   double val=0;
   double low = 0;
   while((val == 0 || val==EMPTY_VALUE) && (shift<Bars)){
      if( (params[0] == "NULL") || (params[0] == "Symbol()")){
         val = getValue1( indicator, period, customIndicatorName, nbValues, values, shift);  
         low = Low[shift];
      } else {
         val = getValue2( indicator, params[0], period, customIndicatorName, nbValues, values, shift);  
         low = iLow(params[0],period,shift); 
      }
       shift++;
   } 
   
   val = NormalizeDouble(val,Digits);
   
   if( val <= low){
      return (true);
   }
   return (false);
}

//En ventana de 100
double AB_PorcentajeGanadorasRobot(int numeroMinimo)
{
   
   int count = 0;
   int countProfit = 0;
   int countProfit100 = 0;

   for (int i=OrdersHistoryTotal()-1; i>=0; i--)
   {
      if ((OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && OrderMagicNumber()==MagicNumber)){
         count++;
         if(OrderProfit()>0)
            countProfit++;
         if(OrderProfit()>0 && count<=100)
            countProfit100++;
            
      }
   }
   
   
   if(count < numeroMinimo){   
      return 0.0;      
   }else if(count >= numeroMinimo && count < 100){   
      return ( (countProfit*100)/count );   
   }else{
      return (countProfit100);
   }


}

//En ventana de 100
double AB_FatorBeneficioRobot(int numeroMinimo)
{

   int count = 0;
   int countProfit = 0;
   int countProfit100 = 0;
   
   double ganancia = 0;
   double perdida = 1;

   for (int i=OrdersHistoryTotal()-1; i>=0; i--)
   {
      if ((OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && OrderMagicNumber()==MagicNumber)){
         count++;
         if(OrderProfit()>0)
            ganancia += OrderProfit();
         else
            perdida += OrderProfit();
         
         if(count == 100)
            break;   
            
      }
   }
   
   if(count < numeroMinimo)
      return 0.0;
   else         
      return MathAbs(ganancia/perdida);

}

int AB_NumeroOperacionesRobot()
{
   int count = 0;

   for (int i=0; i<OrdersHistoryTotal(); i++)
   {
      if ((OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && OrderMagicNumber()==MagicNumber)){
         count++;
      }
   }

   return (count);   
}

void stringSplit(string &results[], string parameters, string separationString) {
   int i;
   int bufferSize;
   ArrayResize(results, 0);
   if (parameters != "") {
      while (true) {
         i = StringFind(parameters, separationString);
         bufferSize = ArraySize(results);
         ArrayResize(results, bufferSize + 1);
         if (i == -1) break;
         if (i > 0) results[bufferSize] = StringSubstr(parameters, 0, i);
         else results[bufferSize] = "";
         parameters = StringSubstr(parameters, i + 1);
      }
      results[bufferSize] = parameters;
   }
}

string stringTrim(string indicator) {
   return (StringTrimRight(StringTrimLeft(indicator)));
}
double getValue1(string indicator, int period, string customIndicatorName, int nbParametros, double Parametros[], int shift) {
     
   if (indicator == "iAlligator") {
      return (iAlligator(NULL, period, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], shift));
   }
   if (indicator == "iADX") {
      return (iADX(NULL, period, Parametros[0], Parametros[1], Parametros[2], shift));
   }
   if (indicator == "iBands") {
      return (iBands(NULL, period, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], shift));
   }
   if (indicator == "iEnvelopes") {
      return (iEnvelopes(NULL, period, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], shift));
   }
   if (indicator == "iGator") {
      return (iGator(NULL, period, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], shift));
   }
   if (indicator == "iIchimoku") {
      return (iIchimoku(NULL, period, Parametros[0], Parametros[1], Parametros[2], Parametros[3], shift));
   }
   if (indicator == "iMACD") {
      return (iMACD(NULL, period, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], shift));
   }
   if (indicator == "iRVI") {
      return (iRVI(NULL, period, Parametros[0], Parametros[1], shift));
   }
   if (indicator == "iStochastic") {
      return (iStochastic(NULL, period, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], shift));
   }
   if (indicator == "iFractals") {
      return (iFractals(NULL, period, Parametros[0], shift));
   }

   switch (nbParametros) {
   case 1:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], shift));
   case 2:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], shift));
   case 3:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], shift));
   case 4:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], shift));
   case 5:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], shift));
   case 6:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], shift));
   case 7:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], shift));
   case 8:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], shift));
   case 9:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], shift));
   case 10:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], shift));
   case 11:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], shift));
   case 12:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], shift));
   case 13:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], shift));
   case 14:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], shift));
   case 15:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], shift));
   case 16:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], shift));
   case 17:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], shift));
   case 18:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], shift));
   case 19:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], shift));
   case 20:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], shift));
   case 21:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], shift));
   case 22:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], shift));
   case 23:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], shift));
   case 24:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], shift));
   case 25:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], shift));
   case 26:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], shift));
   case 27:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], Parametros[26], shift));
   case 28:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], Parametros[26], Parametros[27], shift));
   case 29:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], Parametros[26], Parametros[27], Parametros[28], shift));
   case 30:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], Parametros[26], Parametros[27], Parametros[28], Parametros[29], shift));
   case 31:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], Parametros[26], Parametros[27], Parametros[28], Parametros[29], Parametros[30], shift));
   case 32:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], Parametros[26], Parametros[27], Parametros[28], Parametros[29], Parametros[30], Parametros[31], shift));
   case 33:
      return (iCustom(NULL, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], Parametros[26], Parametros[27], Parametros[28], Parametros[29], Parametros[30], Parametros[31], Parametros[32], shift));
   }
   return (0);
}
double getValue2(string indicator, string symbol, int period, string customIndicatorName, int nbParametros, double Parametros[], int shift) {
     
   if (indicator == "iAlligator") {
      return (iAlligator(symbol, period, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], shift));
   }
   if (indicator == "iADX") {
      return (iADX(symbol, period, Parametros[0], Parametros[1], Parametros[2], shift));
   }
   if (indicator == "iBands") {
      return (iBands(symbol, period, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], shift));
   }
   if (indicator == "iEnvelopes") {
      return (iEnvelopes(symbol, period, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], shift));
   }
   if (indicator == "iGator") {
      return (iGator(symbol, period, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], shift));
   }
   if (indicator == "iIchimoku") {
      return (iIchimoku(symbol, period, Parametros[0], Parametros[1], Parametros[2], Parametros[3], shift));
   }
   if (indicator == "iMACD") {
      return (iMACD(symbol, period, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], shift));
   }
   if (indicator == "iRVI") {
      return (iRVI(symbol, period, Parametros[0], Parametros[1], shift));
   }
   if (indicator == "iStochastic") {
      return (iStochastic(symbol, period, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], shift));
   }
   if (indicator == "iFractals") {
      return (iFractals(symbol, period, Parametros[0], shift));
   }
   switch (nbParametros) {
   case 1:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], shift));
   case 2:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], shift));
   case 3:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], shift));
   case 4:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], shift));
   case 5:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], shift));
   case 6:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], shift));
   case 7:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], shift));
   case 8:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], shift));
   case 9:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], shift));
   case 10:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], shift));
   case 11:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], shift));
   case 12:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], shift));
   case 13:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], shift));
   case 14:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], shift));
   case 15:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], shift));
   case 16:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], shift));
   case 17:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], shift));
   case 18:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], shift));
   case 19:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], shift));
   case 20:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], shift));
   case 21:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], shift));
   case 22:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], shift));
   case 23:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], shift));
   case 24:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], shift));
   case 25:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], shift));
   case 26:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], shift));
   case 27:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], Parametros[26], shift));
   case 28:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], Parametros[26], Parametros[27], shift));
   case 29:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], Parametros[26], Parametros[27], Parametros[28], shift));
   case 30:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], Parametros[26], Parametros[27], Parametros[28], Parametros[29], shift));
   case 31:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], Parametros[26], Parametros[27], Parametros[28], Parametros[29], Parametros[30], shift));
   case 32:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], Parametros[26], Parametros[27], Parametros[28], Parametros[29], Parametros[30], Parametros[31], shift));
   case 33:
      return (iCustom(symbol, period, customIndicatorName, Parametros[0], Parametros[1], Parametros[2], Parametros[3], Parametros[4], Parametros[5], Parametros[6], Parametros[7], Parametros[8], Parametros[9], Parametros[10], Parametros[11], Parametros[12], Parametros[13], Parametros[14], Parametros[15], Parametros[16], Parametros[17], Parametros[18], Parametros[19], Parametros[20], Parametros[21], Parametros[22], Parametros[23], Parametros[24], Parametros[25], Parametros[26], Parametros[27], Parametros[28], Parametros[29], Parametros[30], Parametros[31], Parametros[32], shift));
   }
   return (0);
}

bool checkStrategy(){
      if( IsDemo() && (allowDemo == false)){
         Print("Not allowed to run this strategy in demo.");
         return (false);
      }
      if( IsTesting() && (allowTesting == false)){
         Print("Not allowed to backtest this strategy.");
         return (false);
      }
      if( IsOptimization() && (allowOptimization == false)){
         Print("Not allowed to optimize this strategy.");
         return (false);
      }
      if( accountId>0 ){
         if( AccountNumber() != accountId){
            Print("Invalid account to run this strategy.");
            return (false);
         }
      }
      if( StringLen(caducity)>0){
         datetime cdate = StrToTime(caducity);
         if( cdate - TimeCurrent() < 0 ) {
            Print("This strategy has caducated.");
            return (false);
         }
      }
   return (true);
}

int getPipsFromPrice(int tipo, double priceRef){

   if(tipo == OP_BUY || tipo == OP_BUYLIMIT || tipo == OP_BUYSTOP){ //COMPRA
   
      return ( MathAbs(Ask-priceRef)/Point );

   }else if(tipo == OP_SELL || tipo == OP_SELLLIMIT || tipo == OP_SELLSTOP){ //VENTA
      
      return ( MathAbs(Bid-priceRef)/Point );
   
   }
   
}

double variance(double &arr[],double mx)
  {
   int size=ArraySize(arr);
//--- check  
   if(size<=1)
     {
      Print(__FUNCTION__+": array size error");
      return(EMPTY_VALUE);
     }
//--- calculation
   double sum=0.0;
   for(int i=0;i<size;i++)
      sum+=MathPow(arr[i]-mx,2);
//---
   return(sum/(size-1));
  }
double standardDeviation(double &arr[],double mx){
    return MathSqrt(variance(arr,mx));
}