execute order after candlestick closes

[Deleted]  
Hi,

is there a way to specify in EA that a certain action (open order, close order) is performed provided some conditions are fulfilled but ONLY after the candlestick of the given time frame closes?

I am working with Heikin Ashi candlesticks and want to enter the market upon a certain color of it. But the problem appears when candlestick shortly reverses within the time frame (wrong type of order gets executed) and then reverses back after a while within the same time frame. If I could specify that order is executed only after candlestick is closed, I would avoid that.

Some examples would be appreciated

Jonas
[Deleted]  
Doesn't work. If I say

if((iCustom(PRICE_CLOSE, PERIOD_H1, "Heiken Ashi",3,0))-(iCustom(PRICE_CLOSE, PERIOD_H1, "Heiken Ashi",2,0))>0
&& (iCustom(PRICE_CLOSE, PERIOD_H1, "Heiken Ashi",3,1))-(iCustom(PRICE_CLOSE, PERIOD_H1, "Heiken Ashi",2,1))<0)

to enter long when current closed candle is green and previous was red it still enters market whenever it pleases
Erman Ardianto  
I think you're not doing it right. I don't know about Heiken Ashi, but if you use shift=0, then it may enter the market before the current candle is closed. The idea is to use shift=1 as the latest indicator's value.
This may be working :

if((iCustom(PRICE_CLOSE, PERIOD_H1, "Heiken Ashi",3,1))-(iCustom(PRICE_CLOSE, PERIOD_H1, "Heiken Ashi",2,1))>0
&& (iCustom(PRICE_CLOSE, PERIOD_H1, "Heiken Ashi",3,2))-(iCustom(PRICE_CLOSE, PERIOD_H1, "Heiken Ashi",2,2))<0)

another example :
double latest_ma10=iMA(Symbol(),0,10,0,MODE_SMA,PRICE_CLOSE,1);
double prev_ma10=iMA(Symbol(),0,10,0,MODE_SMA,PRICE_CLOSE,2);

double latest_ma50=iMA(Symbol(),0,50,0,MODE_SMA,PRICE_CLOSE,1);
double prev_ma50=iMA(Symbol(),0,50,0,MODE_SMA,PRICE_CLOSE,2);

if( prev_ma10<=prev_ma50 && latest_ma10>latest_ma50 ) --> enter market if ma10 cross ma50 up after the candle is closed

I hope you grasp the concept.
[Deleted]  
Extremely useful. Now I can't quite perform one order per time frame. Automated, could you point me how to incorporate the code you gave me? I have something like this

// check for long position (BUY) possibility
if(SEma>LEma)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"habuy", 1000,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
Jay  

hi jasius,

you could just make all your calculations and order opening once a bar like this:


datetime Time0 = 0;
 
void start()
{
  if (Time0 != Time[0])
  {
 
    // check for long position (BUY) possibility
    if(SEma>LEma)
    {
      ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"habuy", 1000,0,Green);
      if(ticket>0)
      {
        if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
      }
      else Print("Error opening BUY order : ",GetLastError()); 
    }
 
 
    Time0 = Time[0];
  }
}

thank you

Automated

automatedfx@gmail.com

okwh  

datetime lasttime = NULL;

int start()
{

if (Time[0] == lasttime ) return(0);

lasttime = Time[0];
.......................//do anyother things

return(0);

}

Erman Ardianto  
"execute order after candlestick closes" or "execute one order only at current candle"?
[Deleted]  
Good question devillian... I want to avoid whipsaws when inside the time period candle from red becomes green and vice versa. If it's in the sequence of red candles and in the process of the timeframe it turns red even for a second that messes everything up. So execute after it's closed.

Next step was figuring out how to execute one per candle. That was helpful too
Erman Ardianto  
jasius:
Good question devillian... I want to avoid whipsaws when inside the time period candle from red becomes green and vice versa. If it's in the sequence of red candles and in the process of the timeframe it turns red even for a second that messes everything up. So execute after it's closed.

Next step was figuring out how to execute one per candle. That was helpful too

I see.
Usually to execute after the candle is closed, we compare indicator's shift=1 to shift=2, because Bar[1] is the latest closed bar.
To execute one order per candle we use anything that only change at the opening of a new candle such as Time[0].