enter at bar open

 

How do I program my EA to ONLY enter a trade at the bar open... with in a few ticks ?

I don't want it to open after it has moved a number of pips. That number can be a variable.

Novice programmer... loving this forum... but couldn't find anything by searching... maybe I don't know what to search for.

Thanks.

 
datetime   time_old;

if( time_old != Time[1] &&
    Tradecriteria == true  // if you want your EA to trade
  ) 
  {
   ticket = OrderSend(...);
   time_old = Time[1];
  }
Maybe you want this? Your question is not to precise ;)
 
APeng:
Maybe you want this? Your question is not to precise ;)


thank you so much for the quick reply. I will try this.

but in the mean time (I won't get to it till tomorrow)

One of my indicators I am using with my current EA in process is the Parabolic SAR.

I am checking the previous bar's SAR, and when it changes position, I want my EA to place the order

immediately... not in a minute or two. I want the order to execute as close to the open price as possible.

From there, I have a trailing stop routine that I wrote, and am working on, but its the entry that I want to nail down.

What I have, may take a bit of time to execute, and by then I have lost precious ground.

Thanks again. When I get back to it, and play with it, I will tell you how I'm doing.

I have learned so much from everyone on this forum... its great.

 
if(Tradecriteria == true)  // if you want your EA to trade
   ticket = OrderSend(...); // order is send
The tick your trade criteria comes true, your order will be send.
 

Here is my problem. The EA took the trade order on the bar where the SAR changed from below the price action to above... my EA therefore calls for a SELL.

What I want, is for the SELL order to execute upon the opening of the bar... if it does not execute at the bar open price... then I don't want it to execute.

The picture tells it all... price went below the open price before executing, and therefore ends up costing me a lot of demo money.

How can I fix this? Do you know if the Parabolic SAR repaints? If it does, is there one that does not? I have my indicators paint on open if possible to avoid repainting during

the bar... I don't see where I can set the P SAR to open or close.

Here is my code... please you no laugh at my code... I'm still a novice programmer.

if(
      Bid > lower.bband
   && sma.0     < sma.1       //  current and past moving averages
   && parabol.1 < bar.open 
   && parabol.0 > bar.open
                              ){
      open.short.trade();}
      
      


return;
//----
return(0);
}
// ----------------------------------- End Start -------------------------------------------------+
//================================================================================================


//================================================================================================
// ------------  open short trades ---------------------------------------------------------------+
void open.short.trade()
{

datetime   time_old;

if( time_old != Time[1] ) {
   int ticket=OrderSend(Symbol(),OP_SELL,lot.size.1,Bid,3,0,0,script.2,255,0,CLR_NONE);
   time_old = Time[1];
  }


//----
return(0);
}
// ------- end -----  open short trades ----------------------------------------------------------+
//================================================================================================

 
APeng:
Maybe you want this? Your question is not to precise ;)
Old_time must be static or global.
Reason: