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

 
danya-asg:

I have understood my error, but I have not understood how to solve it. The task is normally started every second, but the time from the beginning of the current candle is not counted correctly.

The Seconds() function outputs seconds from the data of the last known tick, but I need to somehow count the real number of seconds since the opening of the minute candle at the moment the function is called, even if there were no ticks at all for the last couple of seconds.

TimeSeconds (TimeLocal()) or ( TimeLocal() - Time[0]) will not work either, because the local time can differ from the server by several seconds. How to solve the problem?


You haveOnTimer() running every second,

void OnTimer()
{
OnTick(); //-- старт каждую секунду
}
 
Alekseu Fedotov:


You haveOnTimer() running every second,


But for correct program work I need it to show server's time every second, and here it depends on whether the next tick has come or not. If it doesn't, then ontimer is started but shows lagging time, that's the problem.
 

The only thing I've come up with so far, but it's a bit crooked:

int sek
void OnTick()
{
if(Seconds() > sek)
sek = Seconds ();
Clicker (); //-- старт каждый тик
}
void OnTimer()
{
sek = TimeSeconds(TimeLocal());
Clicker (); //-- старт каждую секунду
}

And to do that, I had to set the computer to synchronise time every 10 minutes.

 
danya-asg:

The only thing I've come up with so far, but it's a bit crooked:

And to do this, I had to set the computer to synchronise the time every 10 minutes.


You have to make a millisecond timer of 100-200ms, and work entirely within it.
Seconds are too long, and they slip frequently.

EventSetMillisecondTimer(200);
GetTickCount();
 

I have no idea what to do in the beginning, in the middle, and in the end. The problem is to make an owl on an indicator, and the stop to drag 2 candles after entry, if the deal goes against the current trend, then close the deal and open a reversal, reversing the stop in the same way. I have no idea how to make a constant 20 and 80 as an entry and exit point.

Files:
f9h46khtl1.png  29 kb
 
novikov433:

I have no idea what to do in the beginning, in the middle, and in the end. The problem is to make an owl on an indicator, and the stop to drag 2 candles after entry, if the deal goes against the current trend, then close the deal and open a reversal, reversing the stop in the same way. I have no idea how to make constant 20 and 80 as entry and exit points.

Forgive me, drunken idiot... But i'll tell you this: if you're so sure that "this TS won't fail" what's stopping you from earning $20 manually and ordering this EA from freelancers? I assure you, most of the decent people there and will not distribute this TS, much less advisor anywhere...
 
Alexey Viktorov:
Forgive me, drunken idiot ... But I'll tell you this: If you are so sure that "this TS won't fail", what's stopping you from earning $20 manually and ordering this EA on freelancer? I can assure you, most of the decent people there and will not distribute this TS, much less advisor anywhere ...

I want to learn how to make an EA. Maybe the market will change and I will have to pay more, for example, to change the algorithm a bit?

I don't know if I can really make it with some owl constructor, but I'd rather understand the basic functions like making a stop in a certain place or order an order to trade on certain days.

I don't know why I should make 1,2,3 etc. even in the constructor and why I should connect everything in this order with arrows. Who teaches mql 4 from A to Z and not as internet warriors create courses that do not explain why they do it that way, in words, you won't make anything new by yourself and will have to copy their code .... I mean, they know what order is responsible for what, and they didn't just point at random ..... Well, let the professionals do pyramiding, dynamic lot, smart stop; my task is different - to download the required filters and understand the essence of trend formation. Thanks for your help!

 
novikov433:

I want to learn how to make an EA. Maybe the market will change and I will have to pay more, for example, to change the algorithm a bit?

As for the possibility to make a TS with some owls constructor?

It is realistic to write TOR for ATC, and in the TOR specify that would be commented all lines - you will pay a little more, but will see how and what works, and then, gradually you will make changes in the working code and watch the changes - and so starts self-training.
 
novikov433: ... want to ... understand how to make an EA ... i want to understand how to make an EA ... i want to understand how to make an EA ... but this EA should not be really losing because loss-making orders are moved to Breakeven and i just need to wait for the trend to move ... so i´m already working on it ...
Dear novikov433! As you know the symbolic features of the trading robot, you have to be careful when writing your trading robot, and you have to be careful when writing your trading robot! You can use a simple example. I give my wife an order (order): buy a bucket of potatoes early in the morning at the market, and by 10 o'clock (fundamental analysis) the price goes up - sell. But sometimes a truckload of potatoes arrives at 10:30 (news). And the price (on the news) instantly goes down and it lasts till the end of the day, or even for the whole week. I put a Stop Loss - if the price goes down by 10 rubles, I sell as soon as I can (at the market price). How to change the order, to avoid losses. If this variant is interesting - write your email in a personal message.
 
Hello. Please help me deal with one error when testing on the tester. During testing, on all ticks, my Expert Advisor opens the 1st sellstop trade, the condition has not been passed and it deletes it. The 2nd sellstop is opened and closed although the condition has not been triggered. Then in the log appears an attempt to close buy2, unknown ticket for orderclose function. I am pasting the code since I am working and some inaccuracies may appear. Orders block is usual
Symb=Symbol();                               
   Total=0;                                     
   for(int i=1; i<=OrdersTotal(); i++)          
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) 
        {                                       
         if (OrderSymbol()!=Symb)continue;      
         if (OrderType()>1) continue;
         if (OrderType<=1)                     
            {
             Total++;                               
             if (Total>1)                           
               {
                Alert("Несколько рыночных ордеров. Эксперт не работает.");
                return;                             
               }
             Ticket=OrderTicket();                  
             Tip   =OrderType();                    
             Price =OrderOpenPrice();               
             SL    =OrderStopLoss();                
             TP    =OrderTakeProfit();              
             Lot   =OrderLots();                    
            }
        }

the closing block doesn't seem to raise much of a question either, the conditions have been shown to be simplified:

while(true)                                  
     {
      if (Tip==0 && Cls_B==true)                
        {                                       
         Alert("Попытка закрыть Buy ",Ticket);
         RefreshRates();                        
         Ans=OrderClose(Ticket,Lot,Bid,2);      
         if (Ans==true)                         
           {
            Alert ("Закрыт ордер Buy ",Ticket);
            break;                              
           }
         return;                                
        }
 
      if (Tip==1 && Cls_S==true)                
        {                                       
         Alert("Попытка закрыть Sell ",Ticket);
         RefreshRates();                        
         Ans=OrderClose(Ticket,Lot,Ask,2);      
         if (Ans==true)                         
           {
            Alert ("Закрыт ордер Sell ",Ticket);
            break;                              // Выход из цикла закр
           }
         return;                                // Выход из start()
        }
      break;                                    // Выход из while
     }

would be much appreciated.

Reason: