MQL4 - automated forex trading   /  

Forum

execute order after candlestick closes

Back to topics list To post a new topic, please log in or register

avatar
9
jasius 2008.01.26 04:44 
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
article

Report: The Championship Started

The Automated Trading Championship 2006 started two days ago. 258 Expert Advisors are now competing for prizes. Unfortunately, not everything went like clockwork.


avatar
279
devilian1899 2008.01.26 05:03 
use PRICE_CLOSE on shift=1

avatar
9
jasius 2008.01.26 06:16 
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


avatar
279
devilian1899 2008.01.26 07:43 
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.




avatar
59
Automated 2008.01.26 07:46 

you may want to check the following post too:

'how to open only one position per bar?'


the code example given there sends an order at the very first tick of a new bar i.e. immediately after the previous bar has closed...if this is what you need.. .

thank you

Automated


avatar
9
jasius 2008.01.27 01:02 
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);
}

avatar
59
Automated 2008.01.27 05:19 

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


avatar
1515
DxdCn 2008.01.27 08:49 

datetime lasttime = NULL;

int start()
{

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

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

return(0);

}


avatar
279
devilian1899 2008.01.27 13:37 
"execute order after candlestick closes" or "execute one order only at current candle"?

avatar
9
jasius 2008.01.27 18:59 
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

avatar
279
devilian1899 2008.01.27 22:25 
jasius wrote:
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].
Back to topics list  

To add comments, please log in or register