Qualcuno scribacchi una sceneggiatura per 5 wmz. - pagina 16

 

E sto solo cercando il motivo per cui le posizioni non si chiudono, nel blocco di chiusura delle posizioni, quando è corretto. Quale sarebbe quello giusto?

 

==================

Rimuovi il tuo blocco di chiusura. Qual è quello giusto lì....

Inserire questo codice prima della linea:

if(total<1){ //se non ci sono posizioni aperte

//============== Закрытие позиций =============================


if(total>=1){  //если "есть открытых позиций"
//----------------------------------------------------------------------
  for (int v=0; v<OrdersTotal(); v++)                             {       
      if (OrderSelect(v, SELECT_BY_POS, MODE_TRADES))               {           
        if (OrderSymbol()==Symbol())                                 { 
//-----------------------------------------------------                  
if (OrderType() == OP_BUY) { //бай позиция 
    if ( DayOfWeek()==1  && Hour() == 22)    {
           OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); // закрываем позицию
                 return(0); // выходим
                }       
     }  
 //--------------------------------------------------------
if (OrderType() == OP_SELL) { //селл позиция
      if ( DayOfWeek()==1  && Hour() == 22)    {
                 OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); // закрываем позицию
                 return(0); // выходим
                }       
     }  
 //-------------------------------------------------------                       
    }  // Symbol()  
  } // select
 } //total

}//если  "есть открытых позиций"
//============= конец блока закрытия =====================
 

Quando si aprono le posizioni si chiama la funzione di errore GetLastError(), ma non c'è alcun riferimento ad essa nel codice per qualche motivo!

Perché l'hai rimosso dal mio codice? -

//-- Подключаемые модули --
#include <stderror.mqh>
#include <stdlib.mqh>
 

viene testato, ma non si chiude a 22 posizioni. Non ho buttato via niente, è un nuovo codice, dato che l'EA non fa trading con il tuo, anche se fa dei test.

extern double Lots          = 0.1;
extern double TakeProfit    = 120;
extern double StopLoss      = 120;

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  int cnt, ticket, total;
  static int prevtime = 0;
if (Time[0] == prevtime) return(0); //если появился новый бар
   prevtime = Time[0]; // начинаем работу


//+------------------------------------------------------------------+
//|               Открытие позиций понедельника                      |
//+------------------------------------------------------------------+
if ( DayOfWeek()==5){//если сегодня вечер пятницы
if ( Hour() == 23)  {//если - 22 часа терминального времени
// BUY
       if ( Close[1]<= Open[24] && Close[23]<=Open[48] && Close[47]<=Open[72]) {    
        
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-40*Point,Ask+120*Point,"Regulest",0,0,Green);}
         if(ticket < 0) {
            Print("Ошибка открытия ордера BUY #", GetLastError()); 
            Sleep(10000);  prevtime = Time[1];  return (0); }}
// SELL
if ( DayOfWeek()==5){//если сегодня вечер пятницы
if ( Hour() == 23)  {//если - 22 часа терминального времени
    if ( Close[1]>= Open[24] && Close[23]<=Open[48] && Close[47]<=Open[72]) {
    
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+40*Point,Bid-100*Point,"Regulest",0,0,Red);
         if(ticket < 0) {
            Print("Ошибка открытия ордера SELL #", GetLastError()); 
            Sleep(10000);  prevtime = Time[1];  return (0); }
          } 
        }
//+------------------------------------------------------------------+
//|                     Закрытие позиций                             |
//+------------------------------------------------------------------+
if(total>=1){  //если "есть открытых позиций"
//----------------------------------------------------------------------
  for (int v=0; v<OrdersTotal(); v++)                             {       
      if (OrderSelect(v, SELECT_BY_POS, MODE_TRADES))               {           
        if (OrderSymbol()==Symbol())                                 { 
//-----------------------------------------------------                  
if (OrderType() == OP_BUY) { //бай позиция 
    if ( DayOfWeek()==1  && Hour() == 22)    {
           OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); // закрываем позицию
                 return(0); // выходим
                }       
     }  
//--------------------------------------------------------
if (OrderType() == OP_SELL) { //селл позиция
      if ( DayOfWeek()==1  && Hour() == 22)    {
                 OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); // закрываем позицию
                 return(0); // выходим
                }       
     }  
//-------------------------------------------------------                       
    }  // Symbol()  
  } // select
} //total
}//если  "есть открытых позиций"

               }
      return(0);
     }}
 
extern double Lots          = 0.1;
extern double TakeProfit    = 120;
extern double StopLoss      = 120;
//-- Подключаемые модули --
#include <stderror.mqh>
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  int cnt, ticket, total;
  static int prevtime = 0;
if (Time[0] == prevtime) return(0); //если появился новый бар
   prevtime = Time[0]; // начинаем работу


//+------------------------------------------------------------------+
//|               Открытие позиций понедельника                      |
//+------------------------------------------------------------------+
if(total<1){  //если нет открытых позиций"
if ( DayOfWeek()==5){//если сегодня вечер пятницы
if ( Hour() == 23)  {//если - 22 часа терминального времени
//---------------------------------------------
// BUY---------------------
       if ( Close[1]<= Open[24] && Close[23]<=Open[48] && Close[47]<=Open[72]) {    
        
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-40*Point,Ask+120*Point,"Regulest",0,0,Green);
         if(ticket < 0) {
            Print("Ошибка открытия ордера BUY #", GetLastError()); 
            Sleep(10000);  prevtime = Time[1];  return (0); }
                      }
// SELL-----------------------
    if ( Close[1]>= Open[24] && Close[23]<=Open[48] && Close[47]<=Open[72]) {
    
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+40*Point,Bid-100*Point,"Regulest",0,0,Red);
         if(ticket < 0) {
            Print("Ошибка открытия ордера SELL #", GetLastError()); 
            Sleep(10000);  prevtime = Time[1];  return (0); }
          } 
//-----------------------------
    }
    }
   }// если нет открытых позиций

//+------------------------------------------------------------------+
//|                     Закрытие позиций                             |
//+------------------------------------------------------------------+
if(total>=1){  //если "есть открытых позиций"
//----------------------------------------------------------------------
  for (int v=0; v<OrdersTotal(); v++)                             {       
      if (OrderSelect(v, SELECT_BY_POS, MODE_TRADES))               {           
        if (OrderSymbol()==Symbol())                                 { 
//-----------------------------------------------------                  
if (OrderType() == OP_BUY) { //бай позиция 
    if ( DayOfWeek()==1  && Hour() == 22)    {
           OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); // закрываем позицию
                 return(0); // выходим
                }       
     }  
//--------------------------------------------------------
if (OrderType() == OP_SELL) { //селл позиция
      if ( DayOfWeek()==1  && Hour() == 22)    {
                 OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); // закрываем позицию
                 return(0); // выходим
                }       
     }  
//-------------------------------------------------------                       
    }  // Symbol()  
  } // select
} //total
}//если  "есть открытых позиций"

 //
    return(0);
     }

Provate in questo modo. E controlla attentamente le condizioni di apertura per comprare e vendere.

( Close[1]>= Open[24] && ..... ......)

 

Stranamente, sono riuscito a rielaborare il codice della distribuzione base MT4 Moving Average EA. Nel tester i trade vengono testati, nel 22 vengono chiusi, se l'EA si scambierà da solo non lo so. Ecco il codice se ne avete bisogno.

//+------------------------------------------------------------------+
//|                                               Moving Average.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#define MAGICMA  20050610

extern double Lots          = 0.1;
extern double TakeProfit    = 120;
extern double StopLoss      = 120;

//extern double MaximumRisk        = 0.02;
//extern double DecreaseFactor     = 3;
//extern double MovingPeriod       = 12;
//extern double MovingShift        = 6;

//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys=0,sells=0;
//----
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//---- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }

//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   int    res;
   if(Volume[0]>1) return;
   if ( DayOfWeek()==5){//если сегодня вечер пятницы
   if ( Hour() == 23)  {//если - 22 часа терминального времени
   if ( Close[1]>= Open[24] && Close[23]<=Open[48] && Close[47]<=Open[72]) 
     {
      res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+40*Point,Bid-100*Point,"Regulest",MAGICMA,0,Red);
      return;
     }}}
//---- buy conditions
   if ( DayOfWeek()==5){//если сегодня вечер пятницы
   if ( Hour() == 23)  {//если - 22 часа терминального времени
   if ( Close[1]<= Open[24] && Close[23]<=Open[48] && Close[47]<=Open[72])   
     {
      res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-40*Point,Ask+120*Point,"Regulest",MAGICMA,0,Blue);
      return;
     }}}
//----
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double ma;
//---- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)        break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      //---- check order type 
      if(OrderType()==OP_BUY)
        {
         if ( DayOfWeek()==1  && Hour() == 22) OrderClose(OrderTicket(),OrderLots(),Bid,3,White);
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if( DayOfWeek()==1  && Hour() == 22) OrderClose(OrderTicket(),OrderLots(),Ask,3,White);
         break;
        }
     }
//----
  }
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
  {
//---- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false) return;
//---- calculate open orders by current symbol
   if(CalculateCurrentOrders(Symbol())==0) CheckForOpen();
   else                                    CheckForClose();
//----
  }
//+------------------------------------------------------------------+
 
leonid553:

Provate in questo modo. E controlla attentamente le condizioni di apertura per comprare e vendere.

( Close[1]>= Open[24] && ..... ......)


Lasciate perdere questo, grazie, tutto è stato risolto con il codice Moving Avrage. Se non fa lui stesso gli scambi lunedì, continuiamo la nostra discussione. Spero che il mio metodo di teanalisi sia valso, quattro EAs GBPUSD, EURUSD, USDJPY, USDCHF possono, a giudicare da un CHF, portare buoni profitti.
 
Profitabl:

Stranamente, sono riuscito a rielaborare il codice della distribuzione di base MT4 Moving Aviagre EA. Nel tester i trade vengono testati, nel 22 vengono chiusi, se l'EA si scambierà da solo non lo so. Ecco il codice se ne avete bisogno.


Sfortunatamente, questo consulente può funzionare correttamente solo nel tester....

Online - più della metà dei segnali sarà persa. Ciò è dovuto a questa condizione:

 if(Volume[0]>1) return;
 

cosa fare, come cambiarlo, forse solo cancellarlo, perché i parametri Movinga non sono più nel codice

come fa Movinga con questo codice a eseguire tutte le offerte?

è necessario lasciare che tutti i trade siano eseguiti, non ce ne saranno molti, uno al giorno. è necessario che l'Expert Advisor faccia 20-40 tentativi e apra una posizione entro mezz'ora dopo che il prezzo di apertura appare alle ore 23

significa che con il tuo codice l'Expert Advisor potrebbe aprire una posizione il martedì e perdere i tick il giovedì e il venerdì

 
Profitabl:

cosa fare, come cambiarlo, forse solo cancellarlo, perché i parametri Movinga non sono più nel codice

come fa Movinga con questo codice a eseguire tutte le offerte?

è necessario lasciare che tutti i trade siano eseguiti, non ce ne saranno molti, uno al giorno. è necessario che l'Expert Advisor faccia 20-40 tentativi e apra una posizione entro mezz'ora dopo che il prezzo di apertura appare alle ore 23

significa che con il tuo codice l'Expert Advisor potrebbe aprire una posizione il martedì e perdere i tick il giovedì e il venerdì

Sì, cancella tutte quelle righe. Secondo la logica del suo consulente, non sono necessari.