Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 747

 
TarasBY:

2) There cannot be UPPER and LOWER fractals on the same bar at the same time, respectively, check

belongs to the category of programmer idiocy.


Both fractals can be on the same bar
 
Vinin:
Both fractals can be on the same bar
he meant minutes, but forgot about months
 
Hello

There is the following line in the code

 if (G_time_344 == Time[0]) return (0);
As I understand it, it is responsible for the EA delaying recalculation until a new bar appears. Until the zero bar open time changes, the recalculation stops.

Accordingly, if I open an EA on minutes, it will be recalculated with every new minute. And if I open it on H4, it will be recalculated every 4 hours.

How to write this line correctly, so that the EA will not take the opening time of the current bar, ie, the bar at which the terminal is open, but the one that I will specify in the settings? That is, I place the EA on H4, for example, and it will recalculate every 5 minutes, because I have set it so. Or every minute.


 
_new-rena:
he meant minutes, but forgot about months

What's the difference between minutes and months?


 
evillive:
What is it complaining about in the modification log? "Stupidly opens new pending orders" because there is no limit, but there is an OrderSend.
No errors, just yellow triangles.
 
AlexeyVik:

What's the difference between minutes and months?

I agree, there are nice moments on the M1 as well. but on the months every bar is like that.
 
No further questions, I've worked it out myself.
 
TarasBY:

1) Any strategy must be defined by the number of orders open at the same time. Accordingly, before opening the next order, we should check how many are already open.

2) On one bar, there cannot be UPPER and LOWER fractals at the same time, respectively, the check is classified as

belongs to the category of programmer's idiocy.

3) Before writing the conditions for returning buffer indicator values, you need to know exactly what value is "empty" for it? Have you checked that it is 0?

4) The construct.

Although it will work (in most cases), but is unnatural, because it is a "free-will" idea of the developer, and is uninformative for the trader. An alternative - the tracking of a new bar.

5) You have to start from the basics, because this:

Indicates that you don't understand what you're writing at all.

The best way to understand is to study how other people's codes work and modify them for your own purposes. Good luck.

He displays them as written, point by point. He does not modify them, which you have not said a word about. Here is the full code:
//+------------------------------------------------------------------+
//|                                                   Strategy 3.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+

#property copyright ""
#property link      ""
#include <Library1.mqh>
extern int Magic=111;
extern int TP=20;
extern int SL=30;
extern int Trall_dist=10;
extern int Shag=10;
extern bool Isp_shag=false;
extern bool Isp_bezubitok=false;
extern double Lot=0.1;
double SS=0,BS=0;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  double tp,sl;
  if(Digits==3||Digits==5) {tp=TP*10*Point;sl=SL*10*Point;} // условие для пятизнака
  else if(Digits==2||Digits==4) {tp=TP*Point;sl=SL*Point;} // условие для четырехзнака
  double Up=iFractals(Symbol(),0,MODE_UPPER,3);       //верхний фрактал,формируется на третьей свече
  double Down=iFractals(Symbol(),0,MODE_LOWER,3);     //нижний фрактал,формируется на третьей свече                                                   
//----
  if(Up>0&&Down==0&&Volume[0]<2)     //если верхний фрактал есть а нижнего нету и прошло не больше 2х тиков то:
    {
    if((High[3]+5*Point-Ask)/Point>MarketInfo(Symbol(),MODE_STOPLEVEL)) //если расстояние 0 бара от хая фрактала позволяет то:
    OrderSend(Symbol(),OP_BUYSTOP,Lot,High[3]+5*Point,20,High[3]-sl,High[3]+tp,NULL,Magic,0,Green);//выставляем отложенный на покупку
    else {BS=High[3]+5*Point; Print("Виртуальный BS:",BS);} // а ели нет то запоминаем(позже будет добавлен вход с рынка)
        {
        for (int pos=0;pos==OrdersTotal();pos++)
        OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
        if(OrderMagicNumber()==Magic&&OrderSymbol()==Symbol()&&OrderType()==OP_BUYSTOP)
          {
          OrderModify(OrderTicket(),Up+5*Point,High[3]-sl,High[3]+tp,0,CLR_NONE);
          }
        }
     
       }   
   else if(Up==0&&Down>0&&Volume[0]<2)
    {
    if((Bid-Low[3]-5*Point)/Point>MarketInfo(Symbol(),MODE_STOPLEVEL))
    OrderSend(Symbol(),OP_SELLSTOP,Lot,Low[3]-5*Point,20,Low[3]+sl,Low[3]-tp,NULL,Magic,0,Red);
    else {SS=Low[3]-5*Point; Print("Виртуальный SS:",SS);}
         {
         for (pos=1;pos==OrdersTotal();pos++)
             {
             OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
             if(OrderMagicNumber()==Magic&&OrderSymbol()==Symbol()&&OrderType()==OP_SELLSTOP)
               {
               OrderModify(OrderTicket(),Down-5*Point,Low[3]+sl,Low[3]-tp,0,CLR_NONE);
               } 
             }
         }
    
            
    if(OrdersTotal()>0)
    Trailing_stop(Magic,Symbol(),Trall_dist,Shag,Isp_shag,Isp_bezubitok);
    return(0);
  }}
//+------------------------------------------------------------------+
I'm trying to write as I've read, looked, understood. Your critique reminds me of an MQL4 manual - I understand it only if somebody explains it to me.
 
if(Up>0&&Down==0&&Volume[0]<2)     //если верхний фрактал есть а нижнего нету и прошло не больше 2х тиков то:
    {
    if((High[3]+5*Point-Ask)/Point>MarketInfo(Symbol(),MODE_STOPLEVEL)) //если расстояние 0 бара от хая фрактала позволяет то:
    OrderSend(Symbol(),OP_BUYSTOP,Lot,High[3]+5*Point,20,High[3]-sl,High[3]+tp,NULL,Magic,0,Green);//выставляем отложенный на покупку
    else {BS=High[3]+5*Point; Print("Виртуальный BS:",BS);} // а ели нет то запоминаем(позже будет добавлен вход с рынка)
        { // К чему относится эта скобка???
        for (int pos=0;pos==OrdersTotal();pos++)
        OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
        if(OrderMagicNumber()==Magic&&OrderSymbol()==Symbol()&&OrderType()==OP_BUYSTOP)
          {
          OrderModify(OrderTicket(),Up+5*Point,High[3]-sl,High[3]+tp,0,CLR_NONE);
          }
       } // это пара к той...
      }
     


And this code

if(Digits==3||Digits==5) {tp=TP*10*Point;sl=SL*10*Point;} // условие для пятизнака
  else if(Digits==2||Digits==4) {tp=TP*Point;sl=SL*Point;} // условие для четырехзнака

it is better to write in init() and better not like this

double   point; // на уровне глобальных переменных

int OnInit()
{
   point = Digits%2 == 0 ? _Point : _Point * 10;
}

and then in start()

tp = High[3]+TP*point;
 
AlexeyVik:


And this code

it is better to write in init() and better not like this

and then in start()

I need a buy stop followed by a fractal trailing behind the price and a sell stop with the same procedure.
Reason: