Someone scribble a script for 5 wmz. - page 16

 

And I'm just looking for the reason why positions don't close, in the position closing block, when it's correct. What would be the right one?

 

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

Remove your closing block. What's the right one there....

Insert this code before the line :

if(total<1){ //if there are no open positions

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


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

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

When opening positions you call the GetLastError() error function, but there is no reference to it in the code for some reason!

Why did you remove it from my code? -

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

is tested, but does not close at 22 positions. I haven't thrown anything out, it's a new code, as the EA doesn't trade with yours, although it does 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);
     }

Try it this way. And check carefully the opening conditions for buy and sell.

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

 

Oddly enough, I managed to rework the code of the base MT4 distribution Moving Average EA. In the tester the trades are tested, in 22 they are closed, whether the EA will trade itself I don't know. Here is the code if you need it.

//+------------------------------------------------------------------+
//|                                               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:

Try it this way. And check carefully the opening conditions for buy and sell.

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


Drop this one, thanks, all worked out with the Moving Avrage code. If he doesn't make the trades himself on Monday, let's continue our discussion. I hope my tehanalysis method was worth it, four GBPUSD, EURUSD, USDJPY, USDCHF EAs can, judging by one CHF, bring good profits.
 
Profitabl:

Oddly enough, I managed to rework the code of the basic MT4 distribution Moving Aviagre EA. In the tester trades are tested, in 22 they are closed, whether the EA will trade itself I don't know. Here is the code if you need it.


Unfortunately, this advisor can only work correctly in the tester....

Online - more than half of the signals will be missed. This is because of this condition:

 if(Volume[0]>1) return;
 

what to do, how to change it, maybe just delete it, because Movinga parameters aren't in the code anymore

how does Movinga with this code perform all deals?

you need to let all trades be executed, there won't be many of them, one a day. It needs the Expert Advisor to make 20-40 attempts and open a position within half an hour after the Open Price appears at 23 o'clock

it means that with your code the Expert Advisor could open a position on Tuesday and miss the ticks on Thursday and Friday

 
Profitabl:

what to do, how to change it, maybe just delete it, because Movinga parameters aren't in the code anymore

how does Movinga with this code perform all deals?

you need to let all trades be executed, there won't be many of them, one a day. It needs the Expert Advisor to make 20-40 attempts and open a position within half an hour after the Open Price appears at 23 o'clock

it means that with your code the Expert Advisor could open a position on Tuesday and miss the ticks on Thursday and Friday

Yes, delete all those lines. By your advisor's logic, they are unnecessary.
Reason: