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

 
xant:
I withdraw the question, I've figured it out myself.
It's not a good idea to decompile. I advise to rework the code completely
 
Petiyashaket:
I need a buy stop trailed (modified) by price fractals until it triggers and a sell stop in the same way.

So the question in your code, highlighted in red.

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);
          }
        } // это пара к той...
     
       }  

You still haven't answered. I don't know what to do with it, but the result of code execution will be different.

 
AlexeyVik:

So the question in your code, highlighted in red.

You still haven't answered. And from this the result of code execution will be different.

Why do you useVolume[0]<2 in the condition?

Sometimes in one tick there is a bunch of them. And on this bar the condition won't work anymore.

 
Vinin:

Why do you useVolume[0]<2 in the condition?

Sometimes there are a bunch of them in one tick. And on this bar the condition will not work anymore

Victor, this question is not for me. I use this function.

bool NewBar()
{
   static datetime lastbar = iTime(_Symbol, PERIOD_H1, 0); // Период можно менять по желанию
   datetime curbar = iTime(_Symbol, PERIOD_H1, 0);         // и будет отсчитывать новый бар заданного периода на любом ТФ
   if(lastbar != curbar)
    {
     lastbar = curbar;
     return (true);
    }
   else return(false);
}//******************************************************************|

I copied a piece of code to ask a question about brackets.

 
Vinin:

Why do you useVolume[0]<2 in the condition?

Sometimes there are a bunch of them in one tick. And on this bar the condition will not work anymore

This is what Oleg Remizov teaches on YouTube. This condition limits trading on the news and catching of Losses :)
 
Petiyashaket:
This is what Oleg Remizov teaches on YouTube, this condition restricts trading on the news and catching moose :)
I have nothing to say about Remizov. But don't be offended if your code will miss bars. All right, if you have a minute code (on what timeframe, of course), but if you're going to run on an hour or more - there will only be pity for you.
 
AlexeyVik:

So the question in your code, highlighted in red.

has never been answered. And that will make the result of code execution different, too.

I experimented with brackets in different ways, I removed and added them, the result is the same
 
Petiyashaket:
I have experimented with brackets in different ways, I have removed and added them, the result is the same

You don't need to experiment, you need to understand the meaning of these brackets and how to apply them. It's written in the documentation, I won't read a lecture about it.

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);
          }
        } // это пара к той...
     
       }  
But this is only part of the code. There is a similar problem further on.
 
//+------------------------------------------------------------------+
//|                                                   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)
    {
    if((High[3]+5*Point-Ask)/Point>MarketInfo(Symbol(),MODE_STOPLEVEL))
    OrderSend(Symbol(),OP_BUYSTOP,Lot,High[3]+5*Point,20,High[3]-sl,High[3]+tp,NULL,Magic,0,Green);
 //----   
    for (int pos=0;pos==OrdersTotal();pos++)
        {
        OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
        if(OrderMagicNumber()==Magic&&OrderSymbol()==Symbol()&&OrderType()==OP_BUYSTOP)
          {
          OrderModify(OrderTicket(),High[3]+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);
    for (pos=0;pos==OrdersTotal();pos++)
        {
        OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
        if(OrderMagicNumber()==Magic&&OrderSymbol()==Symbol()&&OrderType()==OP_SELLSTOP)
          {
          OrderModify(OrderTicket(),Low[3]-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);
  }
//+------------------------------------------------------------------+
If you explain it to me in a line of code and with comments, as in my previous code, I will be very grateful.
 
Vinin:

This formula is quite easy to adjust to the requirements. You just have to take into account the minimum lot

This looks a little different

lot=Min_Lot+lotstep*MathRound((AccountBalance()-X)*0.001/lotstep);

Where X - Balance for opening the minimum lot,

But we still need to check for the minimum lot.

Why do we need all these complexities, X that must be calculated separately? Besides, we'll need additional checking...

Wouldn't it be easier to directly and honestly check validity and acceptability of all values of the formula, and then just honestly calculate it?

By the way, MathRound() rounds to the nearest integer, that is, it can easily overestimate wrongly, which may cause additional consequences.