Questions from Beginners MQL4 MT4 MetaTrader 4 - page 79

 

Hello, there is a simple question like this. First we open a one-way trade and pay the spread. Then we open a counter trade with the same lot and the spread is also taken from it. In other words, when we close these trades against each other, it means that we pay two spreads?

 

please advise a couple of lines of code

1) how to make owls work, say, once every 10 seconds

2)set a pending order if there is no pending order at this price

3) if applicable, please advise how to calculate a difference between the set (open) orders

 
Rustem71:


Just tell me what you want to do when the tick arrives.

There's so much extra work you're doing.

And write the code correctly, don't abbreviate brackets. If you are supposed to write curly brackets in the condition, you should write them. It will be easier to understand the code. When you get the hang of it, you may start abbreviating.

I'm waiting for clarifications on the tick.


The idea is that 2 pending orders are opened first which worked with the initial lot, for example BUY immediately deleted SELLSTOP and in the same place is put SELLSTOP but with double lot, just opens SELL put BUYSTOP *2 lot, and then, for example if not triggered trilling stop and the trend turned around put pending with *2 lot. And then if comes in without a loss in the plus, such as 0.05 will be put trailing stop. Like this!!! If you tell me how to optimize + your comments on my mistakes will be very grateful! I can not understand why I have a place of one pending order, pending orders open until the total drain of the deposit!
 
Akinak:
Look please! If you can explain what I did wrong! I've tried everything, either without opening an order or opening a bunch in a loop!

if it is greater than or equal to one (simpler - greater than zero) - do not open, the same should be repeated for baikas

and you have it the other way round:

if(s==1)

So it should be something like this:

if(s==0)
{ 
//открываем селл
}
 
Akinak:
Please take a look at it! If you can explain what I did wrong! As only I have not tried or does not open an order or opens a pack by the cycle!!!


If I got it right it goes like this. The rest is up to you.

And write the codes properly.

Files:
888.mq4  8 kb
 
Hello! Please help me with this function, I'm already exhausted and don't know how to do it right! I need that would be able to enter in the parameters, the time of my computer. Thanks in advance!
extern bool    HOUR = false;             // Часы Вкл (true) / Выкл (folse)
extern string  TimeBegin = "13:30";      // Время начала (ЧЧ:ММ)
extern string  TimeEnd   = "17:00";      // Время окончания (ЧЧ:ММ)
//Отправляет true если по времени разрешено торговать
bool isTradeTimeString()
{
 datetime hbegin = StrToTime(TimeBegin) + TimeGMTOffset();
 datetime hend = StrToTime(TimeEnd) + TimeGMTOffset();
 
 datetime dtBegin, dtEnd;        // Время начала и окончания работы
 int      hc, he;                // Часы текущего времени и окончания работы

 dtBegin=StrToTime(TimeToStr(TimeCurrent(),TIME_DATE)+" "+TimeToStr(hbegin,TIME_MINUTES));
 dtEnd=StrToTime(TimeToStr(TimeCurrent(),TIME_DATE)+" "+TimeToStr(hend,TIME_MINUTES));
 hc = TimeHour(TimeCurrent());
 he = TimeHour(dtEnd);
 if(dtBegin>=dtEnd)
 {
  if(hc>=he)
   dtEnd+=24*60*60;
  else
   dtBegin-=24*60*60;
 }
 if(HOUR==true)
 {
  if(TimeCurrent()>=dtBegin && TimeCurrent()<=dtEnd)
   return(true);
  else
  {
   if(CountTrades()==0)
    return(false);
  }
 }
 return(true);
}
 
Arseniy Barudkin:
Hello! Please help me with this function, I'm already exhausted and don't know how to do it right! I need that would be able to enter in the parameters, the time of my computer. Thanks in advance!
TimeLocal()
 
Rustem71:


If you got it right, it's like this. You take it from here.

And write the codes properly.


Thank you very much! Very helpful! I am a little over two weeks of writing still did not know such subtleties!
 
Hello, dear forum members! When I create a simple EA, I get an error! Can you please tell me the reason for this?
Files:
meryjj.jpg  197 kb
 
naravat:
Hello, dear forum members! When I create a simple Expert Advisor, I get an error! Can you please tell me the reason.

You have to put parentheses after return and in them you have to write some value of the same type as the function type.