Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 92

 
Artyom Trishkin:
So check the number of open positions on the M15 zero candle. If you already have a position and it is open on an M15 null candle, then don't open any more.
I do not know much about programming, but this module deals with this
b=0;
    for (i=OrdersTotal()-1;i>=0;i--)  
       {
        RefreshRates();
        if(OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == true) a = 0;
        if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) b++;
       }
But the issue is that when the order is closed by SL or TP, the next signal at M15 will open it again.
 
customer03:
I am not very good at programming, but this module does it
b=0;
       }
But the issue is that when the order is closed by SL or TP the next signal on M15 will open it again.

Try to make a control for a new bar on H1

b=0;
    for (i=OrdersTotal()-1;i>=0;i--)  
       {
        RefreshRates();
        if(OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == true) a = 0;
        if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) b++;
       }

      
if(  stM1 <= 20 && stM0 > 20  && stH0 > 70  && b==0   && opp != iTime(_Symbol,PERIOD_H1,0)) // покупка
      {
       opp = iTime(_Symbol,PERIOD_H1,0);

    RefreshRates();
    op = Ask;
 
Vitaly Muzichenko:

Try a new bar control on H1

b=0;
    for (i=OrdersTotal()-1;i>=0;i--)  
       {
        RefreshRates();
        if(OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == true) a = 0;
        if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) b++;
       }

      
if(  stM1 <= 20 && stM0 > 20  && stH0 > 70  && b==0   && opp != iTime(_Symbol,PERIOD_H1,0)) // покупка
      {
       opp = iTime(_Symbol,PERIOD_H1,0);

    RefreshRates();
    op = Ask;
Tried it, but no change.
 
customer03:
I'm not very good at programming, but this module does that
b=0;
    for (i=OrdersTotal()-1;i>=0;i--)  
       {
        RefreshRates();
        if(OrderSelect (i, SELECT_BY_POS, MODE_TRADES) == true) a = 0;
        if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) b++;
       }
But when the order is closed by SL or TP, the next signal on M15 will open it again.

No, that's definitely not what this piece of code does.

You need to check that the position opening bar on M15 period is not equal to zero - then you can open a position:

if(iBarShift(Symbol(),PERIOD_M15,OrderOpenTime())!=0)
  {
   // код открытия позиции
  }
 

Hello! Help me out with the classes, what am I doing wrong?

class ASD
{
private:
// Variables and functions available only within the class are located here
int c (int m_a,int m_b)
{ int m_d = m_a+m_b;}

public:
void d (int a,int b )
{
m_a=a+b;
}
// Variables and functions available outside the class are located here
};
 
Vikon:

Hello! Help me out with the classes, what am I doing wrong?

class ASD
{
private:
// Variables and functions available only within the class are located here
int c (int m_a,int m_b)
{ int m_d = m_a+m_b;}

public:
void d (int a,int b )
{
m_a=a+b;
}
// Variables and functions available outside the class are located here
};
Start by reading the article.
 
Artyom Trishkin:
Start by reading the article.

I do read it, but I don't get it right.

Here's what I get:

class:

class ASD

  {

private:

   // Здесь располагаются переменные и функции, доступные только внутри класса

   int c(int m_a,int m_b)

     {
      m_a=a+b; m_b=a-b;

      int m_d=m_a+m_b;

      d=m_d;

      return(c(m_a,m_b));
     }

public:

   int               a;

   int               b;

   int               d;

  };

script:

#include <ASD.mqh>


ASD ar;
//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

void OnStart()

  {

   ar.a=1;

   ar.b=3;

   Alert(ar.d);

  }
//+------------------------------------------------------------------+

Alert gives out zero. What's wrong?

 
Vikon:

I do read it, but I don't get it right.

Here's what I get:

class:


Alert gives out zero. What's wrong?

Is it difficult to insert the code via the SRC button ?

I have inserted the correct code for you.

 
Vikon:

I do read it, but I don't get it right.

Here's what I get:

class:

class ASD

  {

private:

   // Здесь располагаются переменные и функции, доступные только внутри класса

   int c(int m_a,int m_b)

     {
      m_a=a+b; m_b=a-b;

      int m_d=m_a+m_b;

      d=m_d;

      return(c(m_a,m_b));
     }

public:

   int               a;

   int               b;

   int               d;

  };

script:

#include <ASD.mqh>


ASD ar;
//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

void OnStart()

  {

   ar.a=1;

   ar.b=3;

   Alert(ar.d);

  }
//+------------------------------------------------------------------+

Alert gives out zero. What's wrong?

Inside the class, make Prints to values. And then look in the log what will be printed when you run the script ;)
 
Artyom Trishkin:
Inside the class, make Prints to the values. And then look in the log what will be printed when the script runs ;)
Prints can only be inserted within a function, but how to call this function to make the print or alert work I do not understand. Can you help fixing my code with three simple variables??? I do everything as described in the article, but the editor won't accept it or something is missing, in any case a wall, that's why I am asking for help. Thanks for SKC.
Reason: