MQL4 - automated forex trading   /  

Forum

EMA on Close

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

avatar
29
Sendra 2008.01.06 22:08 
I'm writing an EA based on EMA crossover. I want it to calculate EMA only on today's close, so if "buy" or "sell" signal occured, it trades by tomorrow's open. Please help. Thank you.
article

Expert Advisors Based on Popular Trading Systems and Alchemy of Trading Robot Optimization (Cont.)

In this article the author continues to analyze implementation algorithms of simplest trading systems and introduces recording of optimization results in backtesting into one html file in the form of a table. The article will be useful for beginning traders and EA writers.


avatar
Moderator
33780
Rosh 2008.01.07 16:14 
See values of an indicator on first tick of new bar.

avatar
29
Sendra 2008.01.08 21:45 
Thank you, but sorry, I don't understand what you mean. I'm not programmer, and just learning MQL4 for the last few months. See how? Thanks.

avatar
2462
phy 2008.01.09 02:30 

Rosh: See values of an indicator on first tick of new bar.

Transliteration: When the first tick of the new day comes, make your decision based on the last bar of the old day.

"I want it to calculate EMA only on today's close"

To be precise, there is no "close" for today, only the current price

"so if "buy" or "sell" signal occured, it trades by tomorrow's open"

Tomorrow isn't here yet.

What you should be saying, and programming is this:

"I want to calculate EMA on yesterday's close, so if "buy" or "sell" signal occurred, it trades by today's open. Please help"

Ok, here is the rest of the help

int dayNumber;
 
int init(){
   dayNumber = TimeDayOfYear(Time[0]);
}
 
int start(){
   
   if(dayNumber != TimeDayOfYear(Time[0])){
      dayNumber = TimeDayOfYear(Time[0]);
      // first tick of new day is detected
      // do your calculation and make your decision based on indicator value calculated for yesterday's close

avatar
29
Sendra 2008.01.10 18:56 
phy wrote:

Rosh: See values of an indicator on first tick of new bar.

Transliteration: When the first tick of the new day comes, make your decision based on the last bar of the old day.

"I want it to calculate EMA only on today's close"

To be precise, there is no "close" for today, only the current price

"so if "buy" or "sell" signal occured, it trades by tomorrow's open"

Tomorrow isn't here yet.

What you should be saying, and programming is this:

"I want to calculate EMA on yesterday's close, so if "buy" or "sell" signal occurred, it trades by today's open. Please help"

Ok, here is the rest of the help

int dayNumber;
 
int init(){
   dayNumber = TimeDayOfYear(Time[0]);
}
 
int start(){
   
   if(dayNumber != TimeDayOfYear(Time[0])){
      dayNumber = TimeDayOfYear(Time[0]);
      // first tick of new day is detected
      // do your calculation and make your decision based on indicator value calculated for yesterday's close
Thanks, Phy.

I tried, it doesn't work. But it's okay, I have other solution in mind instead of EA trade on the open of the next bar. Will you please check it out.

Thanks again.
Back to topics list  

To add comments, please log in or register