Errors, bugs, questions - page 1521

 
Ilya Malev:
Insert the text into the OnCalculate of the default indicator created in the redactor. Place it on any chart. You will see the operation of the indicator in the upper left corner of the chart window. After selecting "Delete" from the list of indicators, it will not stop working, you will see it in the upper left corner. It will continue even after the window is closed. After opening a new window, it will continue in the new window. Moreover, this window does not necessarily have the same symbol as the one you had at the beginning :)
The work of the indicator stops only when the terminal is closed. And I don't know whether it stops or not - I just had to manually remove the terminal via Task Manager to restart it...

At the same time, the IsStopped function's help says that the program operation is forcibly terminated after 3 seconds if there is a command to terminate the mql-program.

And if while(true) is replaced with while(!IsStopped()), the indicator completes successfully when removed from the chart.

Everything is clear. We have made an indulgence for the normal deletion.

When the terminal closes, it will be hard. Not more than 3 seconds.

And I'm not sure we will write this in the documentation, 1. so as not to indulge in writing such reckless indicators (did you write this to check?) 2. As loosened up, so tightened up.

 
Alexandre:

A funny cause of the Internal Compiler Error ( function used in the indicator):

...

The cure is obvious, but agree - very funny glitch. :)))

Thanks for the post!

Wrote you a private message.
 
Hello. I can't manage to write code that would open a position in n-numberof bars after the previous position was opened. Tried using Time[i], iBarShift, iTime. I've had no luck with it all. I am novice in programming. Search didn't yield anything.
 

Dmitri Custurov:
Здравствуйте. Не получается написать код, который открывал бы позицию через n-количество баров после открытия предыдущей позиции. Пробовал использовать Time[i], iBarShift, iTime. Все безуспешно. В программировании новичок. Поиск ничего не дал.

Greetings, in order for you to get help to find the error - you need to attach the code at least. No one here will write for you - it is customary here to help you find the error and correct it with advice. Or - contact a freelancer.
 

Here is the code:

if ((OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==False)&&(Signal==1))
{int send1=OrderSend(Symbol(), OP_SELL, Volume_, Bid, 0, 0, 0, NULL, 1, 0, Red);
z=1;

Timer=Time[0];}

TimerNull=iBarShift(NULL,0,Timer,false);

if ((TimerNull>=n)&&(z==1))

{int send2=OrderSend(Symbol(), OP_SELL, Volume_, Bid, 0, 0, 0, NULL, 2, 0, Red);

z=2;}

I also tried this way:

if ((OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==False)&&(Signal==1))
{int send1=OrderSend(Symbol(), OP_SELL, Volume_, Bid, 0, 0, 0, NULL, 1, 0, Red);
z=1;

Timer=Time[0];}

TimerNull=Time[0];

if ((TimerNull>=(Timer+2700))&&(z==1)) //as an example here I put 2700 seconds instead of n, which in testing meant 3 15-minute candles) {int send2=OrderSend(Symbol(), OP_SELL, Volume_, Bid, 0, 0, 0, NULL, 2, 0, Red);

z=2;}

And also like this:

if ((OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==False)&&(Signal==1))
{int send1=OrderSend(Symbol(), OP_SELL, Volume_, Bid, 0, 0, 0, NULL, 1, 0, Red);
z=1;

Timer=Time[0];}

TimerNull=Time[0];

if ((CurrentTime()>=(Timer+2700))&&(z==1))

{int send2=OrderSend(Symbol(), OP_SELL, Volume_, Bid, 0, 0, 0, NULL, 2, 0, Red); //In this case when I removed 2700 the second trade was opened right after the first one in the same bar, it makes sense. And even when I put any value up to 600 instead of 2700, the second deal was opened in the same bar. With a value higher than 600 the second trade never opened. I cannot understand what the problem is. I would be very grateful to you for your help.

The Timer and TimerNull parameters are in datetime format.


 

in your example there is no enumeration of e.g. positions

if ((OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==False)&&(Signal==1))

therefore it always selects position 0.

 
I'm still writing a rough draft to make the basic logic work. After that, I will refine it. In this case, I may be wrong, the problem is in the second part of the code.
 
Slawa:

It all makes sense. Made an indulgence for normal deletion.

When you close the terminal, it will be hard. No more than 3 seconds.

And I'm not sure we will write this in the documentation, 1. so as not to indulge in writing such reckless indicators (did you write this to check?) 2. As loosened up, so tighten it up.

So tighten it up already, or fix the reference. Indulging not indulging is not a serious conversation. What programmers expect from you is not "coddling", but clear, well-documented software.

Of course this code has no purpose other than a demonstration, which you yourself have asked for. And it's quite harmless, harmless to get it, if you remove Sleep and replace Comment with Print. There is no protection against spamming gigabytes of Print into the log in either Quartet or Quartet 5.

 
Dmitri Custurov:

Here is the code:

if ((OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==False)&&(Signal==1))
{int send1=OrderSend(Symbol(), OP_SELL, Volume_, Bid, 0, 0, 0, NULL, 1, 0, Red);
z=1;

Timer=Time[0];}

TimerNull=iBarShift(NULL,0,Timer,false);

if ((TimerNull>=n)&&(z==1))

{int send2=OrderSend(Symbol(), OP_SELL, Volume_, Bid, 0, 0, 0, NULL, 2, 0, Red);

z=2;}

I also tried this way:

if ((OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==False)&&(Signal==1))
{int send1=OrderSend(Symbol(), OP_SELL, Volume_, Bid, 0, 0, 0, NULL, 1, 0, Red);
z=1;

Timer=Time[0];}

TimerNull=Time[0];

if ((TimerNull>=(Timer+2700))&&(z==1)) //as an example here I put 2700 seconds instead of n, which in testing meant 3 15-minute candles) {int send2=OrderSend(Symbol(), OP_SELL, Volume_, Bid, 0, 0, 0, NULL, 2, 0, Red);

z=2;}

And also like this:

if ((OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==False)&&(Signal==1))
{int send1=OrderSend(Symbol(), OP_SELL, Volume_, Bid, 0, 0, 0, NULL, 1, 0, Red);
z=1;

Timer=Time[0];}

TimerNull=Time[0];

if ((CurrentTime()>=(Timer+2700))&&(z==1))

{int send2=OrderSend(Symbol(), OP_SELL, Volume_, Bid, 0, 0, 0, NULL, 2, 0, Red); //In this case when I removed 2700 the second trade was opened right after the first one in the same bar, it makes sense. And even when I put any value up to 600 instead of 2700, the second deal was opened in the same bar. With a value higher than 600 the second trade never opened. I cannot understand what the problem is. I would be very grateful to you for your help.

The Timer and TimerNull parameters are in datetime format.


This is one of the possible implementations. This EA should open an order after the specified number of bars. And learn how to insert EA code correctly, the SRC button on the message bar.

//+------------------------------------------------------------------+
//|                                                          111.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

input int nymber_bar=10;
input double Volume_=0.01;
int send1;
int send2;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(Total_orders(_Symbol,OP_SELL)==0 && send1<=0)
     {
      send1=OrderSend(Symbol(),OP_SELL,Volume_,Bid,0,0,0,NULL,1,0,Red);
     }

   if(OrderSelect(send1,SELECT_BY_TICKET))
     {
      if(iBarShift(NULL,0,OrderOpenTime())>=nymber_bar)
        {
         send1=OrderSend(Symbol(),OP_SELL,Volume_,Bid,0,0,0,NULL,1,0,Red);
        }
     }

  }
//+------------------------------------------------------------------+
int Total_orders(string symbol,int type)
  {
   int n=0;
   int total=OrdersTotal();

   for(int i=0; i<total; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS))
        {
         if(OrderType()!=type)continue;
         //if(OrderMagicNumber()!=Magic)continue;
         if(OrderSymbol()!=symbol)continue;
         n++;
        }
     }
   return(n);
  }
//+------------------------------------------------------------------+

111

 

The question is probably for the website developers or the Freelance service administrators

---

Used to be: 568 jobs completed, 75% personal

Added 13 jobs (all personal) and became: completed 581, 75% personal

---

Therefore the question: decipher please, what does 75% mean ?