I will write an advisor free of charge - page 156

 
Valeriy Yastremskiy #:

If you want to watch in the tester, you can remove the test for a time later than the actual time. This is in OnInit. And I don't remember if in 4ka in the tester a time request will exactly return the tester time. I think it will return the current time, so in the tester there are just placing orders at once and that's it. Also requesting local time will give the current local time.

It's in the 5k in the tester a complete environment emulator.

Thanks for the clarification

 
The previous one, unfortunately, did not fit. After a closer look at the codebase, I found almost exactly what I need

https://www.mql5.com/ru/code/10236

//+------------------------------------------------------------------+
//|                                                    i`lbeback.mq4 |
//|                                Copyright ? 2011, AM2 && Tiburond |
//|                                      http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright ? 2011, AM2 && Tiburond"
#property link      "http://www.forexsystems.biz"

#define MAGIC  20110406

extern int  StopLoss    = 1300;   //???????? ??????
extern int  StartHour   = 21;     //??? ?????? ????????(???????????? ?????)
extern int  Distance    = 250;    //?????????? ?? ???? ??? ????????? ??????
extern int  Step        = 50;     //??? ????????? ???????
extern int  Count       = 4;      //?????????? ??????????????? ???????
extern int  Expiration  = 4;      //????? ????????? ??????
extern double  Lots     = 1;      //???
extern bool  MM         = true;   //?????????? ???????????????
extern double  TSP      = 5;      //????
extern bool  BU         = true;   //?????????? ?????? ??????? ? ????????? ? ??????? ???
extern int  BUHour      = 2;      //??? ????? ??????? ??????? ??????? ? ?????????

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int  init()
  {
//----
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int  deinit()
  {
//----
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int  start()
  {
   int  b=0,s=0,res;
   datetime  expiration = TimeCurrent()+3600*Expiration;
   double  BuyPrice=fND(Open[0]-Distance*Point);
   double  SellPrice=fND(Open[0]+Distance*Point);  
   for (int  i=OrdersTotal()-1;i>=0;i--)
     {
      if (OrderSelect(i, SELECT_BY_POS))
        {  
         if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=MAGIC) continue;
         if (OrderType()==OP_BUYLIMIT) b++;
         if (OrderType()==OP_SELLLIMIT) s++;
        }  
     }
   if (Hour()>BUHour && Hour()<StartHour && AllProfit()>0) ClosePositions();
   if (Hour()>BUHour && DayOfWeek() == 5) ClosePositions();  
   if (Hour()==StartHour && b<1 && DayOfWeek() != 5)
   for(i=1;i<=Count;i++)
    {
     {              
      res=OrderSend(Symbol(),OP_BUYLIMIT,fLots(),fND(Ask-(Distance*Point+i*Step*Point)),3,fND(BuyPrice-StopLoss*Point),fND(Open[0]),"",MAGIC,expiration,Blue);      
      Sleep(3000);
      if(res<0)
         {
            Print("??????: ",GetLastError());
         } else {
            RefreshRates();
         }    
     }
    }
        
   if (Hour()==StartHour && s<1 && DayOfWeek() != 5)
   for(i=1;i<=Count;i++)
    {  
     {              
      res=OrderSend(Symbol(),OP_SELLLIMIT,fLots(),fND(Bid+(Distance*Point+i*Step*Point)),3,fND(SellPrice+StopLoss*Point),fND(Open[0]),"",MAGIC,expiration,Red );
      Sleep(3000);
      if(res<0)
         {
            Print("??????: ",GetLastError());
         } else {
            RefreshRates();
         }    
     }
    }    
//----  
   return(0);
  }
//+------------------------------------------------------------------+
double  fND(double  d, int  n=-1)
  {  
   if (n<0) return(NormalizeDouble(d, Digits));
   return(NormalizeDouble(d, n));
  }
//+------------------------------------------------------------------+
double  fLots()
  {
   double  lot=Lots;
   double  lot_min =MarketInfo( Symbol(), MODE_MINLOT  );
   double  lot_max =MarketInfo( Symbol(), MODE_MAXLOT  );
   if (MM)
     {
      double  lot_step =MarketInfo( Symbol(), MODE_LOTSTEP );
      double  lotcost =MarketInfo( Symbol(), MODE_TICKVALUE );      
      double  dollarsPerPip=0.0;

      lot = AccountFreeMargin()*TSP/100.0;
      dollarsPerPip=lot/StopLoss;
      lot=fND(dollarsPerPip/lotcost, 2);      
      lot=fND(lot/lot_step, 0) * lot_step;
     }
   if (lot<lot_min) lot=lot_min;
   if (lot>lot_max) lot=lot_max;
   return(lot);
  }
//+------------------------------------------------------------------+
void  ClosePositions()
  {
   if(BU)
   for (int  i=OrdersTotal()-1;i>=0;i--)
    {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol())
       {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC)
          {
            if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, 3, Blue);
            if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red);
          }
         Sleep(1000);
      }
    }
  }
//+------------------------------------------------------------------+
double  AllProfit()
  {
   double  Profit = 0;
   for (int  i=OrdersTotal()-1;i>=0;i--)
    {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MAGIC) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MAGIC)
         if (OrderType() == OP_BUY || OrderType() == OP_SELL) Profit += OrderProfit();
    }
   return (Profit);
  }
//+------------------------------------------------------------------+


Please help me make corrections. This EA does not forcefully close the open orders. I would like that along with the time of setting limits we could also set the time of their forced closing.
We need TP and trall to optimize them. A trall, so that all limits would be closed in a small way but collect nightly noise.
Советник по стратегии "Возврат".
Советник по стратегии "Возврат".
  • www.mql5.com
Ночной скальпер. EURUSD H1.
 
Hello. Who can help with an EA for MT4. I need an EA without any trickery to follow manually placed orders (with or without magic). If an order is closed on a stop loss, the EA will open a new order in the same direction with a specified lot, SL and TP.If an order is closed on a take profit, the EA will open a new order in the opposite direction with a specified lot, SL and TP. Maybe there are some ready-made solutions, I have not been able to find anything. Many thanks in advance.
 
Anton Yakovlev:
If you have a good strategy and are willing to share it, I can write an EA.
Hello, I need an indicator that works on the basis of candle movements (pattern). is it possible to write it, how much and how to pass your request.
 
Hello!
Can you write a pips advisor for mt4
Strategy :
Set 2 differently directed buy limit/sell limit orders at X distance from each other with stop, take, trawl.
For example:
If the price hits any of the limits and closes this order at stop or take, the opposite limit is cancelled and 2 differently directed limits are set again.
EA parameters:
Lot
Stop
Take
Trawl
Limit Spacing
Magic
Slippage
 
Ivan Bielyi #:
Setting 2 differently directed buy limit/sell limit orders with a spread limit on

How do I limit spread on limit orders?

 
Evgeny Belyaev #:

And how can you limit the spread on limiters?

I mean, if the spread is higher than 5 pips, for example, then do not place pending orders, but if it is too much of a problem, you can skip this parameter.
 
Ivan Bielyi #:
I mean that if the spread is higher than 5 points then we shouldn't place pending orders, but if it is very problematic, we can skip this parameter.

What's the point? They will not be executed now (they are limits). And when the time comes to execute, the spread will be completely different.

 
Evgeny Belyaev #:

What's the point? They will not be executed now (they are limits). And when the time comes to execute, the spread will be completely different.

Dumb, then exactly without this parameter)))
 
Daniil Osipov #:
What it takes as a basis and how complex the algorithm is.

Determines the moving average trend

TrendUp := MAvg[1]>TrendUp[1] ? max(Up,TrendUp[1]) : Up