Send order to market only on Open

 

Hello Folks. I am trying to create a condition that will send an order to market but I don't want it to happen on EVERY TICK. (arrgh!)

What do I have to do the following in order to make the value of RisingPrice change ONLY if the current tick is in fact the opening tick? (RisingPrice=0 before the program finds the following code)

if(MAslope>0){RisingPrice=1;}

if(MAslope<=0){RisingPrice=-1;}


As a side note, when RisingPrice=0, my EA does not send orders to the market. The value of RisingPrice is changed back to 0 after an order goes through. That's why I need it to change ONLY on the OPENING TICK. MAslope is calculated in my EA as the difference between a moving average's current value and the value of the same at the previous bar.

Thank you.

 
if (NewBar() == false) return(0);

and if not ...... first tick new is true OrderSend(..........)

//+------------------------------------------------------------------+
//| NewBar                                                           |
//| Returns true when new bar gets first tick                        |
//| Returns false otherwise                                          |
//+------------------------------------------------------------------+
bool NewBar()
{
   static datetime dt = 0;
   
   if (Time[0] != dt)
   {
      dt = Time[0];
      return(true);
   }
   return(false);
}

Placing at first tick NewBar.....

A way to do it....

 

Could I do like this:

if(MAslope>0 && NewBar()==true){RisingPrice=1;}

if(MAslope<=0 && NewBar()==true){RisingPrice=-1;}

?

 

BTW, you're my new favourite person who doesn't live in my house. (Wife kind of wins by default for the entire world)

Do you want a copy of this EA when it's finished? I predict that it will work very well.

 
  1. deVries:
    if (NewBar() == false) return(0);
    While creating/using functions is the normal way to go, I have an exception with NewBar. It can not be called more than once per tick (will return false on subsequent calls.)
    int start(){     static datetime Time0;
       if (Time0 == Time[0]) return; Time0 = Time[0]; 
       :
  2. trivates:
    if(MAslope>0 && NewBar()==true){RisingPrice=1;}
    1) You wouldn't ever write if( (x==2) == true ) would you? You'd simply write if (x==2). So you need not write if( BOOL==true ) but simply if( BOOL )
    if( MAslope>0 && NewBar() ){RisingPrice=1;}
    The opposite sense if(BOOL == false) would be written if(!BOOL) and read as if not BOOL.
    2) If the condition is false - what is the value of RisingPrice? You'd better have initialized it to non-one previously. But what is the meaning of one? RisingPrice sounds like true or false. So the one is misleading:
    bool RisingPrice = false;
    if(MAslope>0 && NewBar()){RisingPrice=true;}
    3) bool B=false; If( true ) B=true; can be simplified
    bool RisingPrice = MAslope>0 && NewBar();
Reason: