A bug in the OrderSend() function ? - page 10

 
Roger:
You can't do that. If you don't get the condition right on the first tick, the whole hour will go to waste.


On H1 the condition lasts 60 minutes, i.e. until the next bar

//+------------------------------------------------------------------+
//|                                                     чернoвик.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+

static datetime LastTime = 0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   if(NewBar()==true)
       {
        
           int ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Bid-250*Point,Ask+250*Point," ",16384,0,Green);
        
       }
  Comment ("LastTime   ",LastTime,"   NewBar   ",NewBar());  
//----
   return(0);
  }
//+------------------------------------------------------------------+
bool NewBar() 
    {
       
       if (iTime(NULL,0,0) != LastTime) 
       {
          LastTime = iTime(NULL,0,0);      
          return (true);
       } 
       else
          return (false);
     
    }

Look up the comment in the tester.

 
pako:


keep only one position open on each bar

Pako, I'm surprised! You've been poking me with "Albanian code" throughout this thread, but what did you offer? :) The same thing, only from the side! After all, you have the same function of a new bar, only more primitively used. And then you have the function of sending an order, bypassing all the signals and so on and so forth. And the solution to the problem was not here! So you have the Albanian.

Swan:
Taki then
only if the order is opened on the current bar. i.e. this line in the function OpenBuy/Sell move





Swan, thank you! This is what needed to be done! If the time of the new bar is assigned in the order opening function, then no gaps. I have already checked it and cannot get over how well everything works. My Expert Advisor works exactly as it should be.

I still have one question. Why didn't the previous example work? The previous example has also had the condition:

// Проведение торговых операций
   if (signal != SIGNAL_NO)
       if (!Trade(signal))
           return (0);

I thought the code reads like this... if theTrade(signal) function returns false, then exit the function... and before thelastBarTime variable in the line is updated:

lastBarTime = iTime(NULL, 0, 0);

will not be updated. But as it turns out, it's not like that. May I ask you to explain this point? It's very interesting even. I'm intrigued.

 
hoz:

Swan, Thank you! This is what needed to be done! If the new bar time is assigned in the open order function, then . no omissions. I have already checked it and cannot get over how well everything works. My Expert Advisor works exactly as it should be.

One question remains. Why didn't the last option work? There was a condition there too:

I thought the code read like this... if theTrade(signal)) function returns false, then exit the function... and before thelastBarTime variable in the line is updated:

will not be updated. But as it turns out, it's not like that. May I ask you to explain this point? It's very interesting even. I am intrigued.

Yeah, but if
signal == SIGNAL_NO

on the first tick of a new bar lastBarTime is updated...


maybe without...

   if (signal != SIGNAL_NO)
it will work as intended... It's hard by the code, you have to check it)
 
hoz:

Pako, I'm surprised! You've been poking me with "Albanian code" throughout this thread, but what did you suggest? :) The same thing, but from the side! After all, you have the same function of a new bar, only more primitively used. And then there is the function of sending an order, bypassing all the signals and so on and so forth. And the solution to the problem was not here! So you are the Albanian.

pako:
If you don't mind formulating the ToR again, why do you need to control a new bar?


hoz:
Formulate and easy! I still have not thought of 1 point, but I will explain the whole point.

There should be no limitations on the number of orders at all. I.e. orders may be opened in any quantity... ... it does not matter how many we have, but we need only 1 order to be opened in the current bar. That is it.

I.e., a new bar opens, so we can open 1 order during this bar, but no more than 1 order in the current bar. The next order can be opened only on the next bar, not earlier.

Is this clear now?

I wrote according to the ToR that one position is opened on a new bar

I do not see anything else in the ToR.

Good luck to you

Reason: