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

 
Artyom Trishkin:

Thank you.

 
Good afternoon! Please help me with a question about a simple loop.
The essence of the loop is that the variable I is incremented by one.
The value is printed.
The loop itself:

for (int i=0; i<100000;i++)
{
Print("I =",i);
if(i>3000)
{
Print("I =",i);
break;
}

The issue is that if the number in the condition if(i>3000) is roughly greater than 100 (in my case three thousand),
then the print outputs different values. Constantly.
My point is that if the loop looks like this
for (int i=0; i<100000;i++)
{
Print("I =",i);
if(i>100)
{
Print("I =",i);
break;
}

Print in the tester shows the value I = 0, then 1, then 2, then 3, then 4,... and so on till 100.
But! If the condition is for example if(i>3000), Print will show the value since... I don't even know how to phrase it correctly...
from a single number, e.g. 2895 and then adds one!

Here is an example of how it may look:

if i > 100

100


if i >3000

3000



What's the problem? I've been struggling all day and can't figure it out(((( Please HELP!







 
eflaer:
What is the problem? I've been struggling all day and can't figure it out(((( Please Help!

open the log file, there's a full report

 
Taras Slobodyanik:

open the log file, there's a full report

Thanks, opened the log file, indeed all the countdown starts with zero................ why is not everything written in the log?

How do I get everything to show up in the log, I need the entire timing, I'm looking for a bug in the algorithm.

 
It's just not convenient to open a 7+GB txt log file every time.......
 
eflaer:

Thank you, opened the log file, indeed all the countdown starts from zero................ why is not everything written in the log?

How do I get everything to show up in the log, I need the entire timeline, I'm looking for a bug in the algorithm.

Because logging and working with graphical objects takes a lot of resources (time), MT is optimized for it, and can "swallow" part of the log, but quickly execute the script body itself

add Sleep(120) after Print().


eflaer:
It's not convenient to open each time log file, txt which weighs 7+GB.......

Delete the log file periodically, it is recorded by date, if you only write experiments in it today, why do you need such a big file?

 
Thank you so much! Really helpful! I'll keep looking for the error...
 
Vitali Vakulin:
Hello.I would like to make a drawdown of 10% so that if I have a drawdown for example, my Expert Advisor will not open new orders, it will just catch up the open ones to TP and that's it, only the averaging ones will open. This will help me not to fall into a big drawdown, if my trading is performed on several pairs. I understand the work of the function and I wish I could implement it.

Guys, please help.

 

Good evening.

First attempts to write an EA. Can you please tell me why my Expert Advisor opens only Buy? Where is the error?

extern double volume     = 0.05;   // Volume
extern int    stopLoss   = 1;      // StopLoss
extern int    takeProfit = 3;      // TakeProfit
extern int    slippage  = 10;          // Slippage
extern int    Period_bars  = 100;    // Period
extern int    magic      = 321;    // Magic
extern int    ATR_Period = 50;      // ATR Period

datetime newCandle;
double ABS_High=0;
double ABS_Low=1000000;

int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+

void OnDeinit(const int reason)
  {
//---
 

  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

void OnTick()
  {

        double TD_Close=Close[1];

        double ATR=iATR(Symbol(),Period(),ATR_Period,0);

        double bsl=NormalizeDouble(Ask-(stopLoss*ATR),_Digits);

        double btp=NormalizeDouble(Ask+(takeProfit*ATR),_Digits); 

        double ssl=NormalizeDouble(Bid+(stopLoss*ATR),_Digits);

        double stp=NormalizeDouble(Bid-(takeProfit*ATR),_Digits); 

        for (int i=2; i<=Period_bars; i++)
        {
                if (Period_bars<=Bars-1)
                {
                        if (ABS_High<High[i]) ABS_High=High[i];
                        if (ABS_Low>Low[i]) ABS_Low=Low[i];
                }

                break;
        }

        if (TD_Close>ABS_High)
        {
                if (OrdersTotal () < 1 && newCandle != Time[0]) int tiket=OrderSend(Symbol(),OP_BUY,volume,Ask,slippage,bsl,btp,"Система пробоя открыла ордер BUY ",magic,0);

                else newCandle = Time[0];
        }
        else
        if (TD_Close<ABS_Low)
        {
                if (OrdersTotal () < 1 && newCandle != Time[0]) int tiket=OrderSend(Symbol(),OP_SELL,volume,Bid,slippage,ssl,stp,"Система пробоя открыла ордер SELL ",magic,0);
                else newCandle = Time[0];
        }
}

 
Andrey.Sabitov:

Good evening.

First attempts to write an EA. Can you please tell me why my Expert Advisor opens only Buy? Where is the error?



Insert (into) the code more carefully :-)

I cannot see where ABS_High is changed, it seems to be constant 0 and the TD_Close>ABS_High condition is always correct

Reason: