conditions on different time frames

Post Reply
Dewey McG
Trader
Posts: 435
Joined: Sat Nov 26, 2011 4:20 pm
Location: Tampa FL

conditions on different time frames

Post by Dewey McG »

Sorry for such a newbie question.

I thought this should be simple but it isn't working. I wanted to make a simple EA to test an idea I saw (before modifying it further) that would check to see if price is above both EMA 20 and EMA 50 on the Daily time frame, then place an order on the H1 time frame to go long when Williams%R is less then -80. ((The opposite for going short)I did this:



// Go Long 1
if (((sqGetMarketPosition() == 0)
&& ((iOpen(NULL, PERIOD_D1, 1) > iMA(NULL, 0 , 50, 0, MODE_EMA, 0, 1))
&& ((iOpen(NULL, PERIOD_D1, 1) > iMA(NULL, 0 , 20, 0, MODE_EMA, 0, 1))
&& (iWPR(NULL, 0 , 14 , 1) < (-80))))))



then placed the EA on the H1 chart.



However, it ignores the first condition, taking orders even when the price on the Daily is under EMA 20. What am I doing wrong? I probably should have used Daily close from the previous bar but even when price was well under EMA 20 on both open and close it was placing trades.
Last edited by Dewey McG on Thu May 09, 2013 8:29 pm, edited 1 time in total.
Dewey McG
Trader
Posts: 435
Joined: Sat Nov 26, 2011 4:20 pm
Location: Tampa FL

Re: conditions on different time frames

Post by Dewey McG »

I think I fixed it:

// Go Long 1
if (((sqGetMarketPosition() == 0)
&& ((iClose(NULL, PERIOD_D1, 1) > iMA(NULL, 1440 , 50, 0, MODE_EMA, 0, 1))
&& ((iOpen(NULL, PERIOD_D1, 1) > iMA(NULL, 1440 , 20, 0, MODE_EMA, 0, 1))
&& (iWPR(NULL, 60 , 14 , 1) < (-80))))))
dietcoke
Trader
Posts: 162
Joined: Tue Nov 15, 2011 9:59 pm

Re: conditions on different time frames

Post by dietcoke »

Dewey McG wrote:Sorry for such a newbie question.

I thought this should be simple but it isn't working. I wanted to make a simple EA to test an idea I saw (before modifying it further) that would check to see if price is above EMA 20 on the Daily time frame, then place an order on the H1 time frame to go long when Williams%R is less then -80. ((The opposite for going short)I did this:



// Go Long 1
if (((sqGetMarketPosition() == 0)
&& ((iOpen(NULL, PERIOD_D1, 1) > iMA(NULL, 0 , 50, 0, MODE_EMA, 0, 1))
&& ((iOpen(NULL, PERIOD_D1, 1) > iMA(NULL, 0 , 20, 0, MODE_EMA, 0, 1))
&& (iWPR(NULL, 0 , 14 , 1) < (-80))))))



then placed the EA on the H1 chart.



However, it ignores the first condition, taking orders even when the price on the Daily is under EMA 20. What am I doing wrong? I probably should have used Daily close from the previous bar but even when price was well under EMA 20 on both open and close it was placing trades.

You cannot see the wood for the trees here. You should use variables when you can as it's much easier to see whats going on.

Second, I've removed all the excess brackets as well and finally added a print statement to inspect the values you are getting.

It may still be wrong but you should be able to see better.

Code: Select all

double D1open = iOpen(NULL, PERIOD_D1, 1);
double EMA50	= iMA(NULL, 0 , 50, 0, MODE_EMA, 0, 1) ;
double EMA20	= iMA(NULL, 0 , 20, 0, MODE_EMA, 0, 1) ;
double WPR14	= iWPR(NULL, 0 , 14 , 1);
int	 MKTPos  = sqGetMarketPosition();

Print ("D1open=",D1open," EMA50=",EMA50," EMA20=",EMA20," WPR14=",WPR14," MKTPos=",MKTPos);

if (MKTPos == 0  && (D1open > EMA50 && (D1open > EMA20 && WPR14 < -80)))

Image
Dewey McG
Trader
Posts: 435
Joined: Sat Nov 26, 2011 4:20 pm
Location: Tampa FL

Re: conditions on different time frames

Post by Dewey McG »

Thanks--yours is much cleaner.
Post Reply

Return to “Coders Hangout”