[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 589

 
ilunga:
Because these are local variables that already on the second tick store rubbish instead of ticket

Thank you very much! Honestly thought about it all the time!
 
Roman.:


See trailer. Place its contents in the Experts folder of the terminal. Select the timeframe of the instrument you are interested in and place it on the chart of the Expert Advisor,

Set parameters for opening an order in MetaTrader external variables:

Then you wait for the formation of a new bar on the selected timeframe of the instrument.

When the Expert Advisor opens an order from the market, compare the time of its opening with the time of opening a new bar.

Roman, as promised, I want to show you what happens in practice when working with the Expert Advisor on the "open at the opening". First, the EA is triggered on the next tick after placing it on the 1-hour chart and opens a second trade at the opening of the next candle. Why, I cannot yet understand. Secondly, the opening price of the deal does not coincide with the opening price of a new candle:

2012.02.24,12:00,1.3392,1.3405,1.3383,1.3387,768 - the candle opens at 1.3392 and the order is triggered at 1.3390. I specify a slippage of 1 point in the settings. If I were to enter 0 pips, the EA would not trigger at all.

I attached the log. The important thing for me is still that the opening order coincided with the opening price of the candlestick.

 

Hello, gentlemen. I would appreciate a clarification.

Am I correct to understand that if in the code the OrderDelete and OrderSend commands are written sequentially and if the EA receives a signal to execute both commands (withdrawal + setting) on tick #1, then:

- these two commands cannot be executed on the same tick #1, and their execution is stretched by at least 3 ticks, and

- on tick #1 the OrderDelete command is issued;

- after OrderDelete has been submitted, only with the next tick #2 the result is returned, and only now on the same tick #2 can the OrderSend command be submitted;

- the result of the OrderSend command will only be known on tick #3.

Is this the case?


And is it true that there is no possibility to send two commands to MT on the same tick?

I am writing an EA in MT4.

Thank you.

 
Les:

Hello, gentlemen. I would appreciate a clarification.

Am I correct to understand that if in the code the OrderDelete and OrderSend commands are written sequentially and if the EA receives a signal to execute both commands (withdrawal + setting) on tick #1, then:

- these two commands cannot be executed on the same tick #1, and their execution is stretched by at least 3 ticks, and

- on tick #1 the OrderDelete command is issued;

- after OrderDelete has been submitted, only with the next tick #2 the result is returned, and only now on the same tick #2 can the OrderSend command be submitted;

- the result of the OrderSend command will only be known on tick #3.

Is this the case?


And is it true that there is no possibility to send two commands to MT on the same tick?

I am writing an EA in MT4.

Thank you.

A tick is a new quote. And there is no connection between the OrderDelete and OrderSend commands

If there is news updates and slippage, then by the time a simple OrderSend is executed, a dozen ticks will have passed. And if the market is in a nighttime flat, both commands may be executed within one tick

 
Les:

It all depends on how fast the ticks go. In general, functions that return a value, OrderDelete, OrderSend, etc. are not executed asynchronously, i.e. until the entire operation is passed and an error code is issued (or NO_ERROR in case of success), the next operator will not be executed. Another thing is that several ticks may run during this time, but they will not be processed by the start() function.


There may also be a collision when, for example, one order triggers a stoploss and you try to open/close another order on the same tick. Then the server may, in some cases, not allow you to execute the operation.


I.e. the answer to your questions is no, it's not))

 
ilunga:

A tick is a new quote. And there is no connection with OrderDelete and OrderSend commands execution time

If there's news updates and slippage, by the time a simple OrderSend is executed, a dozen ticks have passed. And if the market is in a night-time flat, then both commands may be executed within one tick.

MT, as far as I understand, is pulling information from server via ticking (and server, in its turn, is giving answers on commands simultaneously with sending new ticks, it optimizes costs by time). And before a new tick arrives, nothing is known. That's what I meant. But maybe I'm wrong in that assumption? The question has more to do with the second option you mentioned, when the tick is slow, rather than a dozen ticks.

Did I understand you correctly, thus, that getting a response on command #1 is not a prerequisite to go to command #2 and process it completely?

The command response is the "non-essential" part of the command? Is its presence not critical to move on to the next command?

We got into a discussion with alsu below, and I think I assumed the same as he did: that having a response is critical. You, however, write that two commands can be executed on a single tick. So the information from the server comes with no connection to the quote flow at all?


Thank you.

 
alsu:
It all depends on how fast the ticks go. Generally functions, which return a value, OrderDelete, OrderSend etc. are not executed asynchronously, i.e. until the entire operation is passed and an error code is returned (or NO_ERROR in case of success), the next operator will not be executed. Another thing is that several ticks may run during this time, but they will not be processed by the start() function.


There may also be a collision when, for example, one order triggers a stoploss and you try to open/close another order on the same tick. Then the server may, in some cases, not allow you to execute the operation.


I.e. the answer to your questions is no, it is not))

How is it not so, if it turns out to be exactly "so", according to your own words? )) Or am I misunderstanding something again? In reply you write that functions are executed in such a way that the next operator is executed only after the previous operator's error code is processed. I think that's what I meant: that "two commands can't be executed on the same tick #1", because the response - that response or error code - appears earliest with the new tick. Or doesn't it? Or do the command responses go in a separate timed stream, unrelated to the quote stream? Perhaps my mistake was in assuming that command execution results are returned with a new quote?

Of course, I was referring primarily to the situation where the ticks are slow.

 
Please tell me if it is possible for the Expert Advisor to close only positive deals, despite the signal of the indicator to close the deal and close them at the next indicator signals, as they come out to profit?
 
Les:

The MT, as far as I understand, pulls information from the potikovo server (and the server, in turn, gives command responses at the same time as sending new ticks, this optimises time costs). And before a new tick arrives, nothing is known. That's what I meant. But maybe I'm wrong in that assumption? The question has more to do with the second option you mentioned, when the tick is slow, rather than a dozen ticks.

Did I understand you correctly, thus, that getting a response on command #1 is not a prerequisite to go to command #2 and process it completely?

The command response is the "non-essential" part of the command? Is its presence not critical to move on to the next command?

We got into a discussion with alsu below, and I think I assumed the same as he did: that having a response is critical. You do write that two commands can be executed on a single tick. So the information from the server comes with no connection to the quote flow at all?


Thank you.

Command responses and ticks are separate and unrelated. If there is a dead flat, you can "catch" several orders open/close on the same tick.
 

Hello. I am not good at programming at all. I am not so experienced in coding, so please help me to add closing positions byStopLoss and TrailingStop to my code. The Expert Advisor is not mine, but the strategy is not bad, so trial and error reworking the EA for me - and to be honest, I`m already blowing my mind, and there is not much time - work. I have already tried and tested it and, frankly, I have no time for it - work. And here is what I do with it:


//+------------------------------------------------------------------+
//|                                             stohastic_system.mq4 |
//|                                                    Анатолий      |                                                                  |
//+------------------------------------------------------------------+

extern double Lots=0.4;
extern int TakeProfit=50;
extern int NWave=2;
extern int K=9;
extern int D=3;
extern int slowing=5;
extern int Average_method=2;
extern int price_field=0;

int K_level=0;
int down=0;
int up=0;


int init()
  {

   return(0);
  }

int deinit()
  {

   return(0);
  }

int start()
  {
    int ticket=0;
    double stoch_1=iStochastic(NULL,0,K,D,slowing,Average_method,price_field,MODE_MAIN,1);
    double stoch_2=iStochastic(NULL,0,K,D,slowing,Average_method,price_field,MODE_MAIN,2);
    double stoch_3=iStochastic(NULL,0,K,D,slowing,Average_method,price_field,MODE_MAIN,3);
    int Hour_curr=TimeHour(TimeCurrent());
    
    if ((stoch_1>90)&&(stoch_2>70)) K_level=90;
    if ((stoch_1<10)&&(stoch_2<30)) K_level=10;  
    if(OrdersTotal()<1)
      {        
        if((Hour_curr>=1)&&(Hour_curr<24))//проверка сигналов только в этот промежуток времени
          {
            if((K_level==10)&&(stoch_1>10))//сигнал на покупку
              {
                RefreshRates();
                Print("Сигнал на покупку. stoch_1=",stoch_1," stoch_2=",stoch_2);
                ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,10,0,Ask+TakeProfit*Point,"buy_order1",1,0,Blue);
                
                K_level=10; 
                down=0;               
              }
            if((K_level==90)&&(stoch_1<90))//сигнал на продажу
              {
                RefreshRates();
                Print("Сигнал на продажу. stoch_1=",stoch_1," stoch_2=",stoch_2);
                ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,10,0,Ask-TakeProfit*Point,"sell_order1",1,0,Red);
               
                K_level=90;
                up=0; 
              }
          }
      }
    
   
   
    return(0);
  }
   
Files:
Reason: