//+------------------------------------------------------------------+ //| MedieMobili.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 input int PeriodoKama1 = 10; input double PeriodoEMA_Fast1 = 2; input double PeriodoEMA_Slow1 = 30; double fastest_SC1; double slowest_SC1; double KamaSellBuffer[]; input int PeriodoKama2 = 10; input double PeriodoEMA_Fast2 = 5; input double PeriodoEMA_Slow2 = 30; double fastest_SC2; double slowest_SC2; double KamaBuyBuffer[]; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int Ticket=0; int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { if(NewBar()){ EseguiOrdineLong(); EseguiOrdineShort(); } } //+------------------------------------------------------------------+ void EseguiOrdineLong(){ if(KamaSellBuffer[0]KamaBuyBuffer[0]){ OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES); if(OrderCloseTime()==0 && OrderType()==OP_SELL){ OrderClose(Ticket,OrderLots(),Ask,0,0); Ticket=OrderSend(Symbol(),OP_BUY,1,Ask,0,Ask-0.003,Ask+0.003,0,0,0,0); } else if (OrderCloseTime()!=0){ Ticket=OrderSend(Symbol(),OP_BUY,1,Ask,0,Ask-0.003,Ask+0.003,0,0,0,0); } } } void EseguiOrdineShort(){ if(KamaSellBuffer[0]>KamaBuyBuffer[0] && KamaSellBuffer[0]=0; i--) { //Change = MathAbs(iClose(Symbol(), 0, i) - iClose(Symbol(), 0, i + PeriodoKama)); double Change=MathAbs(close[i]-close[i+PeriodoKama1]); double Volatility=0; double ER=1; for(int x=0; x0) ER=Change/Volatility; //Comment("l'indice ER è= ",ER); //SC = MathPow(ER * (fastest_SC - slowest_SC) + slowest_SC, 2); double SC=MathPow((ER *(fastest_SC1-slowest_SC1)+slowest_SC1),2); //double Kama = iClose(Symbol(), 0, i) + SC * (iClose(Symbol(), 0, i) - Kama); KamaSellBuffer[i]=KamaSellBuffer[i+1]+SC *(close[i]-KamaSellBuffer[i+1]); } } int CalcoloKama2(const int rates_total2, 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[]) { int i,limit; if(prev_calculated==0) limit=rates_total2-(PeriodoKama2+1); else limit=rates_total2-prev_calculated; //for (int i=limit-1; i>0; i--) //for (int i = 30 - 1; i > 0; i--) for(i=limit; i>=0; i--) { //Change = MathAbs(iClose(Symbol(), 0, i) - iClose(Symbol(), 0, i + PeriodoKama)); double Change=MathAbs(close[i]-close[i+PeriodoKama2]); double Volatility=0; double ER=1; for(int x=0; x0) ER=Change/Volatility; //Comment("l'indice ER è= ",ER); //SC = MathPow(ER * (fastest_SC - slowest_SC) + slowest_SC, 2); double SC=MathPow((ER *(fastest_SC2-slowest_SC2)+slowest_SC2),2); //double Kama = iClose(Symbol(), 0, i) + SC * (iClose(Symbol(), 0, i) - Kama); KamaBuyBuffer[i]=KamaBuyBuffer[i+1]+SC *(close[i]-KamaBuyBuffer[i+1]); } return(rates_total2); }