Logica di apprendimento - pagina 11

 
OK, qual è l'opzione corretta che proponi - con tutti gli errori gestiti?
 
gip:

Io, d'altra parte, l'ho preso da un mucchio di codice:

Una domanda: perché scivola? E 10 (numero di ripetizioni) dovrebbe essere spostato nelle variabili globali.

lea:

Che ne dite di questo?

Punteggio.
 

Ci sono diversi slittamenti. Quelli nel circuito sono... Quando hai una ragazza seduta lì, devi ripeterlo dieci volte e aspettare che si metta il rossetto. Quando una ragazza è seduta, deve ripeterlo dieci volte e aspettare che si trucchi. E a volte il server rallenta. Questo è tutto per la "vera DC".

Scivola dopo PlaySound, in modo che altri suoni non mettano in ombra, PlaySound interrompe il suono del precedente.

Levariabili globali sono abilmente ponderate dal terminale. E non ce n'è bisogno, l'algoritmo esterno dovrebbe funzionare normalmente con ordini che non sono chiusi.

 
gip:

Le variabili globali sono abilmente ponderate dal terminale.

Non di terminale. Programmi. Cioè nell'ambito globale.

Oh, dimenticavo -- RefreshRates all'inizio del ciclo dopo la cattura del contesto, allora non avrete bisogno di armeggiare con Ask e Bid. E anche altri valori.

 

RefreshRates non è lì per altro. Questo è il modo in cui ho cercato di gestire le situazioni in cui OrderClose restituisce false, ma l'ordine si chiude effettivamente. Dopo la pausa e RefreshRates arriva OrderSelect(). Non so come sia lì, ma sembra funzionare.

Ask e Bid sono una vera meraviglia, a volte hanno bisogno di essere normalizzati :)

---

Circa dieci ripetizioni e per cosa nelle variabili globali, non capisco. Ce ne sono dieci, con un margine sufficiente. È esterno?

 

E se l'ordine si chiude tra un minuto? Non si può battere con un codice. Questo è un errore di comunicazione del terminale.

gip:

Non capisco circa dieci ripetizioni e per cosa nelle variabili globali.

Beh, dobbiamo evitare i numeri magici ed è facile da configurare.
 

Riduce semplicemente il numero di fallimenti di un fattore due. Naturalmente, non tutte le situazioni sono gestite esattamente in questo blocco. Se un ordine è chiuso per un minuto, il programma deve aspettare tutto questo tempo. Queste attese, anche se interrotte, ritardano il ciclo e alla fine tutto funziona come dovrebbe.

---

> Per evitare i numeri magici e la sintonizzazione facile.

Regolare questo dieci? Sì, è con un tale margine che è più facile cambiare il DC :) E per il bene di megalot, se così ha dovuto, e può essere nel codice per correggere.

 

C'è un consigliere. Dobbiamo farlo sembrare decente.

//+------------------------------------------------------------------+
// открытие доп ордеров
// OrderTip - тип ордер который нужно открыть, imagic - маджик 
// с которым надо октрыть, exp - экспонент (на что умножать объем), 
//+------------------------------------------------------------------+
bool OpenDopOrder(int OrderTip, int imagic, double exp){
double iLots = NormalizeDouble((FindLastLot(imagic) * exp), Digits);

int ticket = 0;
int i = 0;
int KolvoPopitok = 10;
int err = 0;
if (OrderTip==OP_BUY) {
   color CL_Close=OrderColorBuy;
   string cmd = "BUY";
   //double Price = NormalizeDouble(Ask, Digits); 
   double Price = Ask; 
   } else {
   CL_Close=OrderColorSell;
   cmd = "SELL";
   //Price=NormalizeDouble(Bid, Digits);
   Price=Bid;
   }
   
         for (i = 0; i < KolvoPopitok; i++) {
         ticket = OrderSend(Symbol(), OrderTip, iLots, Price, M1_Slippage, 0, 0, M1_EaComment, imagic, 0, CL_Close);
         err = GetLastError();
         if(err>0){
         Comment("Ошибка открытия дополнительного ордера " + ErrorDescription(err));
         timeprev = Time[1];
         return(false);
         }
         if (err == 0){
         Comment("Дополнительный ордер " + cmd+" # " + ticket+ " создан"); 
         return(true);
         break;}
         if (!(err == 4 || err == 137 || err == 146 || err == 136)) break;
         Sleep(3000);
         }
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
// функция определения тренда
//+------------------------------------------------------------------+
int SignalRegr(){

   int x=0;
   
   string indicator_name = "i-Regr";
   
   double ma = iCustom(NULL, Mas_TF_Regr[TF_Regr], indicator_name, Regr.degree1, Regr.kstd1, SPer, Regr.shift1, 0, 0);
   double ma1 = iCustom(NULL, Mas_TF_Regr[TF_Regr], indicator_name, Regr.degree1, Regr.kstd1, SPer, Regr.shift1, 0, 1);   
   
   if (kanal==1){
   double m_up = iCustom(NULL, Mas_TF_Regr[TF_Regr], indicator_name, Regr.degree1, Regr.kstd1, SPer, Regr.shift1, 1, 0);
   double m_d = iCustom(NULL, Mas_TF_Regr[TF_Regr], indicator_name, Regr.degree1, Regr.kstd1, SPer, Regr.shift1, 2, 0);      
   if (ma>ma1 && Bid>m_d) x=1;
   if (ma<ma1  && Ask<m_up) x=-1;
   }
   
   if (kanal==0){
   if (ma>ma1) x=1;
   if (ma<ma1) x=-1;
   }   
   
   if (kanal==2){
   m_up = iCustom(NULL, Mas_TF_Regr[TF_Regr], indicator_name, Regr.degree1, Regr.kstd1, SPer, Regr.shift1, 1, 0);
   m_d = iCustom(NULL, Mas_TF_Regr[TF_Regr], indicator_name,    Regr.degree1, Regr.kstd1, SPer, Regr.shift1, 2, 0);      
   if (ma>ma1 && Bid>m_d && Ask<m_up && forSignalRegr()==1) x=1;
   if (ma<ma1  && Ask<m_up && Bid>m_d && forSignalRegr()==-1) x=-1;
   }   
return(x);
}
//+------------------------------------------------------------------+
int forSignalRegr(){
int x=0;
   string indicator_name = "i-Regr";
   double ma = iCustom(NULL, Mas_TF_Regr[TFSmall], indicator_name, Regr.degree1mall, Regr.kstd1mall, SPermall, Regr.shift1mall, 0, 0);
   double ma1 = iCustom(NULL, Mas_TF_Regr[TFSmall], indicator_name, Regr.degree1mall, Regr.kstd1mall, SPermall, Regr.shift1mall, 0, 1); 
   double m_up = iCustom(NULL, Mas_TF_Regr[TFSmall], indicator_name, Regr.degree1mall, Regr.kstd1mall, SPermall, Regr.shift1mall, 1, 0);
   double m_d = iCustom(NULL, Mas_TF_Regr[TFSmall], indicator_name, Regr.degree1mall, Regr.kstd1mall, SPermall, Regr.shift1mall, 2, 0);      
   if (ma>ma1 && Bid>m_d && Ask<m_up ) x=1;
   if (ma<ma1  && Ask<m_up && Bid>m_d ) x=-1;
return(x);
}

//+------------------------------------------------------------------+
//динамичный лот
//+------------------------------------------------------------------+
double GetLot(double iLots, double iRisk){
   double Lots_New;
   string Symb   =Symbol();                    
   double One_Lot=NormalizeDouble(MarketInfo(Symb,MODE_MARGINREQUIRED), Digits);
   double Min_Lot=NormalizeDouble(MarketInfo(Symb,MODE_MINLOT), Digits);
   double Step   =NormalizeDouble(MarketInfo(Symb,MODE_LOTSTEP), Digits);
   double Free   =AccountFreeMargin();        

   if (iLots>0){                                       
   double Money=iLots*One_Lot;              
   if(Money<=AccountFreeMargin())         
   Lots_New=iLots;                      
   else                                   
   Lots_New=MathFloor(Free/One_Lot/Step)*Step;
   }

   else{                                       
   if (iRisk > 100)                     
   iRisk=100;                       
   if (iRisk==0)                       
   Lots_New=Min_Lot;                   
   else                                   
   Lots_New=MathFloor(Free*iRisk/100/One_Lot/Step)*Step;
   }

   if (Lots_New < Min_Lot)                    
   Lots_New=Min_Lot;                       
   if (Lots_New*One_Lot > AccountFreeMargin()){                                         
}

return(Lots_New);                             
}

//+----------------------------------------------------------------------------+
//|функция модификация ордера                                                  |
//|PriceOpen - цена открытия позиции, установки ордера                         |
//|SL - ценовой уровень стопа                                                  |
//|TP - ценовой уровень тейка                                                  |
//+----------------------------------------------------------------------------+
bool ModifyOrder(double PriceOpen=-1, double SL=0, double TP=0) {
  string Symb=Symbol();
  bool   Rez_Modify;
  int NumberOfTry=3;
  int PauseAfterError=10;

  int err, kolvo;

  if (PriceOpen<=0) PriceOpen=OrderOpenPrice();
  if (SL<0) SL=OrderStopLoss();
  if (TP<0) TP=OrderTakeProfit();
  
  PriceOpen=RoundToTickSize(PriceOpen);
  SL=RoundToTickSize(SL);
  TP=RoundToTickSize(TP);

  if (PriceOpen!=OrderOpenPrice() || SL!=OrderStopLoss() || TP!=OrderTakeProfit()) {
    for (kolvo=1; kolvo<=NumberOfTry; kolvo++) {
      if (!IsTesting() && (!IsExpertEnabled() || IsStopped())) break;
      while (!IsTradeAllowed()) Sleep(5000);
      RefreshRates();
      if (NormalizeDouble(TP,Digits)!=OrderTakeProfit()) 
      Rez_Modify=OrderModify(OrderTicket(), NormalizeDouble(PriceOpen,Digits), NormalizeDouble(SL,Digits), NormalizeDouble(TP,Digits), 0, OrderColorModify);
      if (Rez_Modify) {
      Comment("Ордер # " + OrderTicket()+ " успешно модифицирован : TP "+DoubleToStr(TP, Digits));
      break;
      } else {
        err=GetLastError();
        Comment("Ошибка модификации ордера # " + OrderTicket()+ " : " +ErrorDescription(err)+" ("+err+"), попытка: "+kolvo);
        timeprev = Time[1];
        Sleep(1000*PauseAfterError);
      }
    }
  }
  return(Rez_Modify);
}
//+----------------------------------------------------------------------------+
//|для функция модификация ордера                                              |
//+----------------------------------------------------------------------------+
double RoundToTickSize(double price){
return(NormalizeDouble(MathRound(price/MarketInfo(Symbol(), 
MODE_TICKSIZE))*MarketInfo(Symbol(), 
MODE_TICKSIZE), MarketInfo(Symbol(), MODE_DIGITS)));
}
//+----------------------------------------------------------------------------+
Queste sono le funzioni di esso. C'è un modo per farlo sembrare decente
File:
prosto_m.mq4  21 kb
 

Ho aggiunto due funzioni per semplificare il lavoro

Uno controlla il tipo di ordine e il secondo cerca l'ultimo ordine aperto

//+------------------------------------------------------------------+
//|                                     Функция контроля типа ордера |
//|                                Copyright © 2010, Victor Nicolaev |
//|                                            e-mail: vinin@mail.ru |
//| isOrderType(type);                                               |
//+------------------------------------------------------------------+
//| Параметер - проверяемый тип                                      |
//+------------------------------------------------------------------+
bool isOrderType(int type){
   int gOrderType[]={OP_BUY, OP_SELL, OP_BUYLIMIT, OP_SELLLIMIT, OP_BUYSTOP, OP_SELLSTOP};
   bool Res=false;
   for (int i=0;i<ArraySize(gOrderType);i++) {
      if (gOrderType[i]==type){
         Res=true;
         break;
      }
   }
   return(Res);
}

//+------------------------------------------------------------------+
//|                       Функция поиска последнего открытого ордера |
//|                               (поиск только по открытым ордерам) |
//|                                          Возвращает номер тикета |
//|                                Copyright © 2010, Victor Nicolaev |
//|                                            e-mail: vinin@mail.ru |
//| FindLastOpenTime(tip, imagic);                                   |
//+------------------------------------------------------------------+
//| Параметер - тип позиции и магик                                  |
//+------------------------------------------------------------------+

int FindLastOpenTime(int tip, int imagic) {
   int Res=-1;
   int lOrderOpenTime=-1;
   
   for (int i=OrdersTotal()-1; i>=0; i--) {
      if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))   continue;
      if (OrderSymbol() != Symbol())                     continue;
      if (OrderMagicNumber() != imagic)                  continue;
      if (!(tip==-1 || isOrderType(tip)))                continue;

      if (lOrderOpenTime==-1) { 
         lOrderOpenTime=OrderOpenTime(); 
         Res=OrderTicket();
      } else if (lOrderOpenTime<OrderOpenTime()) {
         lOrderOpenTime=OrderOpenTime(); 
         Res=OrderTicket();
      }
   }
   return (Res);
}
//+------------------------------------------------------------------+
 

Parte delle funzioni rielaborate dall'autore


//+------------------------------------------------------------------+
//функция подсчета открытых ордеров по типу и маджику
//tip - тип ордера БАЙ или СЕЛЛ, imagic - маджик номер
//возвращает кол-во открытых оредров
//+------------------------------------------------------------------+
int CountTrades(int tip, int imagic) {
   int count = 0;
   for (int trade = OrdersTotal() - 1; trade >= 0; trade--) {
      if (!OrderSelect(trade, SELECT_BY_POS, MODE_TRADES))  continue;
      if (OrderSymbol() != Symbol())                        continue;
      if (OrderMagicNumber() != imagic)                     continue;
      if (!(tip==-1 || isOrderType(tip)))                   continue;
      
      count ++;

   }
   return (count);
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//поиск последней цены
//tip - тип ордера БАЙ или СЕЛЛ, imagic - маджик номер
//возвращает цену открытия последнего открытого ордера
//+------------------------------------------------------------------+
double FindLastPrice(int tip, int imagic) {

   int ticket=FindLastOpenTime(tip, imagic);
   if (ticket==-1) return(-1);
   OrderSelect(ticket, SELECT_BY_TICKET);
   double order_price = OrderOpenPrice();

   return (order_price);
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//поиск последнего лота
//imagic - маджик номер
//возвращает объем последнего открытого ордера
//+------------------------------------------------------------------+
double FindLastLot(int imagic) {

   int ticket=FindLastOpenTime(-1, imagic);
   if (ticket==-1) return(-1);
   OrderSelect(ticket, SELECT_BY_TICKET);
   double order_lot=OrderLots();

   return (order_lot);
}
//+------------------------------------------------------------------+
Motivazione: