Scriverò un consulente gratuito per mql4 - pagina 13

 
oleg3791: il consulente disegnava quattro linee su cinque clic del mouse sul grafico

Linee richieste in giallo

#property strict

int      Количество;
datetime старый, новый=0;
double   старая, новая=0;

void OnInit()
{
  Количество=0;
  ObjectsDeleteAll(0, "Линия");
}

void OnChartEvent(const int     id,  // идентификатор события   
                  const long &x, const double &yy,
                  const string& s)
{
  if(id!=CHARTEVENT_CLICK) return;
  if(Количество>4){OnInit();return;}
  string name[5]={"","Линия_1","Линия_2","Линия_3","Линия_4"};
  int y=int(yy);
  int O;
  старый=новый; старая=новая;
  ChartXYToTimePrice(0,int(x),y,O,новый,новая); // xy ---> время,цену
  if(Количество>0)
  ObjectCreate(name[Количество],OBJ_TREND,0,старый,старая,новый,новая);
  ObjectSet(name[Количество],OBJPROP_RAY,false);
  ObjectSet(name[Количество],OBJPROP_COLOR,Gold);
  ObjectSet(name[Количество],OBJPROP_WIDTH,2);
  Количество++; 
}

void OnDeinit(const int причина)
{
  OnInit();
}
 
STARIJ:

Linee gialle richieste

Grazie!!!
 
oleg3791:   Grazie!!!

Ora ditemi come si fa a guadagnare qui... O è per costruire un gioco?

 

Ciao a tutti, potete per favore aiutarmi a trovare un errore nel codice dell'EA, penso di aver controllato tutto, sembra essere tutto scritto correttamente nel codice, ma il programma non fa trading correttamente per qualche motivo! L'idea è questa: il consulente deve cercare due candele lunghe della stessa direzione (la lunghezza tra le candele è regolabile nel consulente, cioè tra le due candele minime o massime, a seconda della direzione), se il prezzo nella direzione opposta rompe il minimo o il massimo dell'ultima candela, si dovrebbe aprire un'operazione (esempio situazioni immagine sul grafico allegato al file). Il consulente dovrebbe aprire accordi in ogni situazione adatta, ma per qualche motivo apre accordi solo nelle finestre di trading tra i giorni. Ecco la situazione, che non è difficile da programmatori, si prega di aiutare, risolvere l'errore. Codice EA vedi sotto e nel file allegato.

//+-----------------------------------------------------------------------------------------------+
//|                                                                           Spacing_Candles.mq4 |
//|                                                                        Copyright 2017, Vladim |
//|                                                                            vk.com/id229534564 |
//|                                                                  Mail: Vladim120385@yandex.ru |
//+-----------------------------------------------------------------------------------------------+
#property copyright "Copyright 2017, Vladim"
#property link      "vk.com/id229534564"
#property version   "1.00"
#property strict

//--- параметры советника
extern string paramEA    = "";     // Parameters EA
extern double volume     = 0.01;   // Volume
extern double stopLoss   = 5;     // StopLoss
extern double takeProfit = 1.5;    // TakeProfit
extern double maxSpacing = 150;   // MaxSpacing
extern double minSpacing = 30;    // MinSpacing
extern double TrailingStop  = 0;   // TrailingStop
extern int    magic      = 127;    // Magic

//--- глобальные переменные
datetime newCandle;
int tip;

//+-----------------------------------------------------------------------------------------------+
int OnInit()
{
   
   return(INIT_SUCCEEDED);
}
//+-----------------------------------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   
}
//+-----------------------------------------------------------------------------------------------+
void OnTick()
{
   if(newCandle != Time[0]) FindPattern();
   newCandle = Time[0];
}
//+-----------------------------------------------------------------------------------------------+
void OpenOrder(int type)   // Откроем рыночный ордер
{
   if(type == OP_BUY)  if(OrderSend(_Symbol, OP_BUY,  volume, Ask, 0, 0, 0, "", magic, 0)) SetSLTP(OP_BUY);
   if(type == OP_SELL) if(OrderSend(_Symbol, OP_SELL, volume, Bid, 0, 0, 0, "", magic, 0)) SetSLTP(OP_SELL);
}
//+-----------------------------------------------------------------------------------------------+
void SetSLTP(int type)   // Установим стоп приказы
{
   double sl = 0;
   double tp = 0;
   
   if(type == OP_BUY)
      for(int i = 0; i < OrdersTotal(); i++)
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
            if(OrderSymbol() == _Symbol && OrderMagicNumber() == magic && OrderType() == OP_BUY && OrderStopLoss() == 0)
            {
               sl = NormalizeDouble(Low[1] - stopLoss * _Point, _Digits);
               tp = NormalizeDouble(OrderOpenPrice() + (OrderOpenPrice() - Low[1]) * takeProfit, Digits);
               if(OrderModify(OrderTicket(), OrderOpenPrice(), sl, tp, 0)) return;
            }
   if(type == OP_SELL)
      for(int i = 0; i < OrdersTotal(); i++)
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
            if(OrderSymbol() == _Symbol && OrderMagicNumber() == magic && OrderType() == OP_SELL && OrderStopLoss() == 0)
            {
               sl = NormalizeDouble(High[1] + stopLoss * _Point, _Digits);
               tp = NormalizeDouble(OrderOpenPrice() - (High[1] - OrderOpenPrice()) * takeProfit, Digits);
               if(OrderModify(OrderTicket(), OrderOpenPrice(), sl, tp, 0)) return;
            }
}
//+-----------------------------------------------------------------------------------------------+
void FindPattern()   // Ищем большое расстояние между свечами
{
   if(High[1] < High[2] && Bid > High[1] && Low[1] < Low[2])
   {
      double spacing = NormalizeDouble((High[2] - High[1]) / _Point, 0);
            
      if(maxSpacing >= spacing && minSpacing <= spacing)
         OpenOrder(OP_BUY);
   }
   if(Low[1] > Low[2] && Bid < Low[1] && High[1] > High[2])
   {
      double spacing = NormalizeDouble((Low[1] - Low[2]) / _Point, 0);
            
      if(maxSpacing >= spacing && minSpacing <= spacing)
         OpenOrder(OP_SELL);
   }   
   {
      if (TrailingStop!=0) TrailingStop();      
   }
}
//+-----------------------------------------------------------------------------------------------+
void TrailingStop()
{
   double StLo,OSL,OOP;
   bool error=true;   
   for (int i=0; i<OrdersTotal(); i++) 
   {
      if (OrderSelect(i, SELECT_BY_POS))
      {
         tip = OrderType();
         if (tip<2 && OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
         {
            OSL   = NormalizeDouble(OrderStopLoss(),Digits);
            OOP   = NormalizeDouble(OrderOpenPrice(),Digits);
            if (tip==0)        
            {  
               StLo = NormalizeDouble(Bid - TrailingStop*Point,Digits);
               if (StLo < OOP) continue;
               if (StLo > OSL)
                  error=OrderModify(OrderTicket(),OrderOpenPrice(),StLo,OrderTakeProfit(),0,White);

            }                                         
            if (tip==1)    
            {                                         
               StLo = NormalizeDouble(Ask + TrailingStop*Point,Digits);           
               if (StLo > OOP) continue;
               if (StLo < OSL || OSL==0 )
                  error=OrderModify(OrderTicket(),OrderOpenPrice(),StLo,OrderTakeProfit(),0,White);
            } 
            if (!error) Alert("Error TrailingStop ",GetLastError(),"   ",Symbol(),"   SL ",StLo);
         }
      }
   }
}
//+-----------------------------------------------------------------------------------------------+


Foto del grafico "Come un EA dovrebbe scommettere

File:
 
Vladim1203:

Ciao a tutti, potete per favore aiutarmi a trovare un errore nel codice dell'EA, penso di aver controllato tutto, sembra essere stato scritto correttamente nel codice, ma il programma non fa trading correttamente per qualche motivo! L'idea è questa: il consulente deve cercare due candele lunghe della stessa direzione (la lunghezza tra le candele è regolabile nel consulente, cioè tra le due candele minime o massime, a seconda della direzione), se il prezzo nella direzione opposta rompe il minimo o il massimo dell'ultima candela, si dovrebbe aprire un'operazione (esempio situazioni immagine sul grafico allegato al file). Il consulente dovrebbe aprire accordi in ogni situazione adatta, ma per qualche motivo apre accordi solo nelle finestre di trading tra i giorni. Ecco la situazione, che non è difficile da programmatori, si prega di aiutare, risolvere l'errore. Vedi il codice EA qui sotto e nel file allegato.

È meglio scrivere prima la parte dell'EA che segnerebbe sul grafico le candele trovate, in modo che tutto diventi chiaro. E le linee seguenti non sono necessarie nel vostro caso:

extern string paramEA    = "";     // Parameters EA

и

//+-----------------------------------------------------------------------------------------------+
int OnInit()
{
   
   return(INIT_SUCCEEDED);
}
//+-----------------------------------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   
}
//+-----------------------------------------------------------------------------------------------+
 
STARIJ:

Ora dimmi come si fa a guadagnare qui... O ne hai bisogno per costruire un gioco?


Non c'è ancora modo di ottenere un profitto. C'è un algoritmo per il calcolo di due probabili obiettivi di prezzo, lungo la tendenza, da cinque punti principali, ma è calcolato su un server speciale con un abbonamento a pagamento. Voglio calcolare io stesso gli obiettivi, il lavoro sull'algoritmo non è ancora finito.

Come sarà il vostro programma in MQL4?

 
Anton Yakovlev:
Se hai una buona strategia e sei disposto a condividerla, posso scrivere un EA. ti invito a discuterne pubblicamente o in un messaggio privato.

Anton, aiutami, ho aggiunto la funzione trailing stop all'EA, l'ho compilato e mostra due errori. - Mi hanno fatto il lavaggio del cervello, non riesco a capire come fissarli per ottenere un gufo. Tuttavia i trade sono chiusi secondo la vecchia strategia dopo che il prezzo ha toccato il limite superiore del canale e quello inferiore, rispettivamente. Credo che qualcosa debba essere cambiato anche qui. - Richiamo ai ragazzi dell'esercito del Dnr.

#property copyright "Copyright 2017, MetaQuotes Software Corp."

#proprietà link "https://www.mql5.com"

#proprietà versione "1.00"

#proprietà rigorosa


//---------------------------------------------------------

extern double Lots = 0,01;

extern int TakeProfit = 600;

extern int StopLoss = 25;

extern int Magic = 0001;

extern int Slippage = 3;

extern int TralType = 0; // 0-SAR, 1-ATR, 2-HMA.

extern double SAR_Step = 0.02;

extern double SAR_Max = 0,2;

extern int ATR_Period = 14;

extern double ATR_K = 2.0;

extern inttern HMA_Period = 16;

extern intern HMA_Method = 3;

extern inttern HMA_Shift = 0;

datetime LBT;

//---------------------------------------------------------

extern string TMA = "Parametri dell'indicatore TMA";

extern string TimeFrame = "time frame corrente";

extern int HalfLength = 56;

extern int Price = "PRICE_CLOSE;

extern double ATRMultiplier = 2.0;

extern inttern ATRPeriod = 100;

extern bool Interpolate = true;

//---------------------------------------------------------

doppio PriceHigh, PriceLow, SL, TP;

biglietto int;


//+------------------------------------------------------------------+

//| Funzione di inizializzazione dell'esperto |

//+------------------------------------------------------------------+

int OnInit()

{

se (cifre == 3 || cifre == 5)

{

TakeProfit *= 10;

StopLoss *= 10;

Scivolamento *= 10;

}

return(INIT_SUCCEED);

}

//+------------------------------------------------------------------+

//| Funzione di deinizializzazione esperto |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{


}

//+------------------------------------------------------------------+

//| funzione tick esperto |

//+------------------------------------------------------------------+

void OnTick()

{

PriceHigh = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1, 0);

PriceLow = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2, 0);

if(CountSell() == 0 && Bid >= PriceHigh)

{

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "TMA robot", Magic, 0, Red);

se (biglietto > 0)

{

SL = NormalizeDouble(Bid + StopLoss*Point, Digits);

TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);

se (OrderSelect(ticket, SELECT_BY_TICKET))

se (!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Stampa("Errore di modifica dell' ordine!)

}

}

if (CountBuy() == 0 && Ask <= PriceLow)

{

ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "TMA robot", Magic, 0, Blue);

se (biglietto > 0)

{

TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);

SL = NormalizeDouble(Ask - StopLoss*Point, Digits);

se (OrderSelect(ticket, SELECT_BY_TICKET))

if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Stampa("Errore nella modifica dell'ordine di acquisto!)

} else Print("Error opening the Buy order");

}

//+------------------------------------------------------------------+

//| Funzione di inizializzazione dell'esperto |

//+------------------------------------------------------------------+

int init()

{

//--------


//--------

ritorno (0);

}

//+------------------------------------------------------------------+

//| funzione tick esperto |

//+------------------------------------------------------------------+

void OnTick()

{

PriceHigh = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1, 0);

PriceLow = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2, 0);

if(CountSell() == 0 && Bid >= PriceHigh)

{

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "TMA robot", Magic, 0, Red);

se (biglietto > 0)

{

SL = NormalizeDouble(Bid + StopLoss*Point, Digits);

TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);

se (OrderSelect(ticket, SELECT_BY_TICKET))

se (!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Stampa("Errore nella modifica dell'ordine di vendita!)

} else Print("Errore nell'apertura dell'ordine di vendita!)

}

if (CountBuy() == 0 && Ask <= PriceLow)

{

ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "TMA robot", Magic, 0, Blue);

se (biglietto > 0)

{

TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);

SL = NormalizeDouble(Ask - StopLoss*Point, Digits);

se (OrderSelect(ticket, SELECT_BY_TICKET))

if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Stampa("Errore nella modifica dell'ordine di acquisto!)

} else Print("Error opening the Buy order");

}

se (Ask <= PriceLow && CountSell() > 0)

{

per (int i = OrdiniTotali() -1; i>0; i--)

{

se (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

se (OrderMagicNumber() == Magic && OrderType() == OP_SELL)

if (!OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Black))

Stampa("Errore di chiusura dell'ordine di vendita!)

}

}

}

se (Bid >= PriceHigh && CountBuy() > 0)

{

per (int i = OrdiniTotali() -1; i>0; i--)

{

se (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

se (OrderMagicNumber() == Magic && OrderType() == OP_BUY)

if(!OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Black))

Stampa("Errore di acquisto OrderClose!)

}

}

}

}

//+------------------------------------------------------------------+

int CountSell()

{

int count = 0;

per (int trade = OrdersTotal()-1; trade>=0; trade--)

{

if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))

{

if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)

count++;

}

}

return(count);

}//+------------------------------------------------------------------+

int CountBuy()

{

int count = 0;

per (int trade = OrdersTotal()-1; trade>=0; trade--)

{

if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))

{

if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)

count++;

}

}

return(count);

}

//+------------------------------------------------------------------+

//| Funzione di deinizializzazione esperto |

//+------------------------------------------------------------------+

int deinit()

{

//+-------


//+-------

ritorno (0)

}

//+------------------------------------------------------------------+

//| funzione di inizio esperto |

//+------------------------------------------------------------------+

int Inizio()

{

//-----

bool error = fals;

se (LBT!=Time[0]) {

se (OrdiniTotali()!=0) {

per (int i=0; i<OrdersTotal(); i++) {

if (OrderSelect(i,SELECT_BY_POS)&&OrderSymbol()==Symbol()&&OrderType()<2) {

doppio SL = OrderStopLoss();

se OrderType()==0) {

interruttore (TralType) {

caso 0: SL = iSAR(NULL,0,SAR_Step,SAR_Max,0);

pausa;

caso 1: SL = High[1] - iATR(NULL,0,ATR,Period,1)*ATR_K;

pausa;

caso 2: SL = iCustom(NULL,0, "VininI_HMAsound&amp",HMA_Period,HMA_Method,3,HMA_Shift, fals,fals,",1,0,0);

pausa;

}

se (SL<OrderStopLoss())

SL = OrderStopLoss();

}

se (OrderType()==1) {

interruttore (TralType) {

caso 0: SL = iSAR(NULL,0,SAR_Step,SAR_Max,0);

pausa;

caso 1: SL = Low[1] + iATR(NULL,0,ATR,Period,1)*ATR_K;

pausa;

caso 2: SL = iCustom(NULL,0, "VininI_HMAsound&amp",HMA_Period,HMA_Method,3,HMA_Shift, fals,fals,",1,0,0);

pausa;

}

se (SL>OrderStopLoss())

SL = OrderStopLoss();

}

se (SL!=OrderStopLoss()) {

if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0))

errore = vero;

}

}

}

}

se (!errore)

LBT = Tempo[0];

}

ritorno (0);

}

//+------------------------------------------------------------------+

Автоматический трейдинг и тестирование торговых стратегий
Автоматический трейдинг и тестирование торговых стратегий
  • www.mql5.com
Выберите подходящую торговую стратегию и оформите подписку на нее в пару кликов. Все Сигналы сопровождаются подробной статистикой и графиками. Станьте Поставщиком торговых сигналов и продавайте подписку тысячам трейдеров по всему миру. Наш сервис позволит вам хорошо зарабатывать на прибыльной стратегии даже при небольшом стартовом капитале...
 
Andrey Luxe:

Per acquisire esperienza in questo settore, scriverò 25 EAs gratuitamente per le vostre idee e strategie interessanti

Rimangono solo 19 EAs


Hoaggiunto la funzione trailing stop all'EA e l'ho commentata e produce due errori. - Potrei avere degli errori, ma non so come correggerli. Tuttavia i trade sono chiusi secondo la vecchia strategia dopo che il prezzo ha toccato il limite superiore del canale e quello inferiore, rispettivamente. Credo che qualcosa debba essere cambiato anche qui. - Richiamo ai ragazzi dell'esercito del Dnr.

#property copyright "Copyright 2017, MetaQuotes Software Corp."

#proprietà link "https://www.mql5.com"

#proprietà versione "1.00"

#proprietà rigorosa


//---------------------------------------------------------

extern double Lots = 0,01;

extern int TakeProfit = 600;

extern int StopLoss = 25;

extern int Magic = 0001;

extern int Slippage = 3;

extern int TralType = 0; // 0-SAR, 1-ATR, 2-HMA.

extern double SAR_Step = 0.02;

extern double SAR_Max = 0,2;

extern int ATR_Period = 14;

extern double ATR_K = 2.0;

extern inttern HMA_Period = 16;

extern intern HMA_Method = 3;

extern inttern HMA_Shift = 0;

datetime LBT;

//---------------------------------------------------------

extern string TMA = "Parametri dell'indicatore TMA";

extern string TimeFrame = "time frame corrente";

extern int HalfLength = 56;

extern int Price = "PRICE_CLOSE;

extern double ATRMultiplier = 2.0;

extern inttern ATRPeriod = 100;

extern bool Interpolate = true;

//---------------------------------------------------------

doppio PriceHigh, PriceLow, SL, TP;

biglietto int;


//+------------------------------------------------------------------+

//| Funzione di inizializzazione dell'esperto |

//+------------------------------------------------------------------+

int OnInit()

{

se (cifre == 3 || cifre == 5)

{

TakeProfit *= 10;

StopLoss *= 10;

Scivolamento *= 10;

}

return(INIT_SUCCEED);

}

//+------------------------------------------------------------------+

//| Funzione di deinizializzazione esperto |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{


}

//+------------------------------------------------------------------+

//| funzione tick esperto |

//+------------------------------------------------------------------+

void OnTick()

{

PriceHigh = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1, 0);

PriceLow = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2, 0);

if(CountSell() == 0 && Bid >= PriceHigh)

{

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "TMA robot", Magic, 0, Red);

se (biglietto > 0)

{

SL = NormalizeDouble(Bid + StopLoss*Point, Digits);

TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);

se (OrderSelect(ticket, SELECT_BY_TICKET))

se (!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Stampa("Errore di modifica dell' ordine!)

}

}

if (CountBuy() == 0 && Ask <= PriceLow)

{

ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "TMA robot", Magic, 0, Blue);

se (biglietto > 0)

{

TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);

SL = NormalizeDouble(Ask - StopLoss*Point, Digits);

se (OrderSelect(ticket, SELECT_BY_TICKET))

if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Stampa("Errore nella modifica dell'ordine di acquisto!)

} else Print("Error opening the Buy order");

}

//+------------------------------------------------------------------+

//| Funzione di inizializzazione dell'esperto |

//+------------------------------------------------------------------+

int init()

{

//--------


//--------

ritorno (0);

}

//+------------------------------------------------------------------+

//| funzione tick esperto |

//+------------------------------------------------------------------+

void OnTick()

{

PriceHigh = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 1, 0);

PriceLow = iCustom(NULL, 0, "TMA_Fair", TimeFrame, HalfLength, Price, ATRMultiplier, ATRPeriod, Interpolate, 2, 0);

if(CountSell() == 0 && Bid >= PriceHigh)

{

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, "TMA robot", Magic, 0, Red);

se (biglietto > 0)

{

SL = NormalizeDouble(Bid + StopLoss*Point, Digits);

TP = NormalizeDouble(Bid - TakeProfit*Point, Digits);

se (OrderSelect(ticket, SELECT_BY_TICKET))

se (!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Stampa("Errore nella modifica dell'ordine di vendita!)

} else Print("Errore nell'apertura dell'ordine di vendita!)

}

if (CountBuy() == 0 && Ask <= PriceLow)

{

ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, "TMA robot", Magic, 0, Blue);

se (biglietto > 0)

{

TP = NormalizeDouble(Ask + TakeProfit*Point, Digits);

SL = NormalizeDouble(Ask - StopLoss*Point, Digits);

se (OrderSelect(ticket, SELECT_BY_TICKET))

if(!OrderModify(ticket, OrderOpenPrice(), SL, TP, 0))

Stampa("Errore nella modifica dell'ordine di acquisto!)

} else Print("Error opening the Buy order");

}

se (Ask <= PriceLow && CountSell() > 0)

{

per (int i = OrdiniTotali() -1; i>0; i--)

{

se (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

se (OrderMagicNumber() == Magic && OrderType() == OP_SELL)

if (!OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Black))

Stampa("Errore ordine di vendita OrderClose!)

}

}

}

se (Bid >= PriceHigh && CountBuy() > 0)

{

per (int i = OrdiniTotali() -1; i>0; i--)

{

se (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

se (OrderMagicNumber() == Magic && OrderType() == OP_BUY)

if(!OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Black))

Stampa("Errore di acquisto OrderClose!)

}

}

}

}

//+------------------------------------------------------------------+

int CountSell()

{

int count = 0;

per (int trade = OrdersTotal()-1; trade>=0; trade--)

{

if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))

{

if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)

count++;

}

}

return(count);

}//+------------------------------------------------------------------+

int CountBuy()

{

int count = 0;

per (int trade = OrdersTotal()-1; trade>=0; trade--)

{

if(OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))

{

if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY)

count++;

}

}

return(count);

}

//+------------------------------------------------------------------+

//| Funzione di deinizializzazione esperto |

//+------------------------------------------------------------------+

int deinit()

{

//+-------


//+-------

ritorno (0)

}

//+------------------------------------------------------------------+

//| funzione di inizio esperto |

//+------------------------------------------------------------------+

int Inizio()

{

//-----

bool error = fals;

se (LBT!=Time[0]) {

se (OrdiniTotali()!=0) {

per (int i=0; i<OrdersTotal(); i++) {

if (OrderSelect(i,SELECT_BY_POS)&&OrderSymbol()==Symbol()&&OrderType()<2) {

doppio SL = OrderStopLoss();

se OrderType()==0) {

interruttore (TralType) {

caso 0: SL = iSAR(NULL,0,SAR_Step,SAR_Max,0);

pausa;

caso 1: SL = High[1] - iATR(NULL,0,ATR,Period,1)*ATR_K;

pausa;

caso 2: SL = iCustom(NULL,0, "VininI_HMAsound&amp",HMA_Period,HMA_Method,3,HMA_Shift, fals,fals,",1,0,0);

pausa;

}

se (SL<OrderStopLoss())

SL = OrderStopLoss();

}

se (OrderType()==1) {

interruttore (TralType) {

caso 0: SL = iSAR(NULL,0,SAR_Step,SAR_Max,0);

pausa;

caso 1: SL = Low[1] + iATR(NULL,0,ATR,Period,1)*ATR_K;

pausa;

caso 2: SL = iCustom(NULL,0, "VininI_HMAsound&amp",HMA_Period,HMA_Method,3,HMA_Shift, fals,fals,",1,0,0);

pausa;

}

se (SL>OrderStopLoss())

SL = OrderStopLoss();

}

se (SL!=OrderStopLoss()) {

if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0))

errore = vero;

}

}

}

}

se (!errore)

LBT = Tempo[0];

}

ritorno (0);

}

//+------------------------------------------------------------------+

Автоматический трейдинг и тестирование торговых стратегий
Автоматический трейдинг и тестирование торговых стратегий
  • www.mql5.com
Выберите подходящую торговую стратегию и оформите подписку на нее в пару кликов. Все Сигналы сопровождаются подробной статистикой и графиками. Станьте Поставщиком торговых сигналов и продавайте подписку тысячам трейдеров по всему миру. Наш сервис позволит вам хорошо зарабатывать на прибыльной стратегии даже при небольшом стартовом капитале...
 
vkravtzov:

Hoaggiunto la funzione trailing stop all'Expert Advisor, l'ho compilato e ho ottenuto due errori. - Ho perso la testa, non riesco a capire come fissarli per ottenere un gufo. Tuttavia i trade sono chiusi secondo la vecchia strategia dopo che il prezzo ha toccato il limite superiore del canale e quello inferiore, rispettivamente. Credo che qualcosa debba essere cambiato anche qui. - Restituiscilo ai ragazzi dell'esercito della DPR.


Non c'è bisogno di spammare.
 
Victor Nikolaev:
Non dovresti spammare.

Mi scuso se ho fatto qualcosa di sbagliato. Ancora non capisco come ho fatto a spammare... Credo di aver indirizzato due messaggi a due compagni. O non è permesso? - Colpa mia.