Reply

setting validity period for IF conditions

7 replies

huangwh88

Customer, bbp_participant, community, 113 replies.

Visit profile

7 years ago #116256

Hello fellow traders, 

 

I was wondering whether I can program the following into the wizard:

 

Suppose I have a MACD and RSI crossover system with 2 entry conditions.

 

Condition 1 is MACD crosses over 0. Assuming it stays above 0, there is a 10 period window for RSI to cross over 50. If this happens, trade is executed. If it does not, MACD condition is reset, and we wait for the next instance of MACD crossing over 0. 

 

For cases when both MACD and RSI cross over at the same time, IF statement can be:

 

MACD cross over 0 AND RSI cross over 50

 

But if the RSI cross happens 5 periods after, the IF statement may be:

 

MACD > 0 AND RSI cross over 50

 

How can I make the EA recognize that the MACD crossover has occurred so that it will use MACD > 0 instead for subsequent periods?

 

Secondly, how can I add in the 10 period validity window?

 

Hope this makes sense. Thanks for any assistance.

0

chris.marshall

Subscriber, bbp_participant, community, 4 replies.

Visit profile

7 years ago #141290

I am only a few indicators in to my journey with this product but I have got the following solution to work with a similar problem I had in an EA. Note when I tried to use it as an indicator though it didn’t work not sure why yet.

You could set up 2 variables MACDP (to count candles after cross above) and MACDN (to count candles after cross below) or anything else that makes sense to you. This is done in the Strategy tab in the bottom box “Strategy parameters”. Make them integer type.

Then set up 2 new rules that calculate on candle close
1) IF MACD > 0 Then MACDP = MACDP + 1 AND MACDN = 0
2) IF MACD < 0 Then MACDN = MACDN + 1 AND MACDP = 0
Make sure these 2 rules are before the RSI test in order of execution

Then your RSI test would be
1) IF RSI Crosses above 50 and MACDP > 0 and MACDP < 11 Then trade condition
2) IF RSI Crosses below 50 and MACDN -11 Then trade condition

0

huangwh88

Customer, bbp_participant, community, 113 replies.

Visit profile

7 years ago #141294

I am only a few indicators in to my journey with this product but I have got the following solution to work with a similar problem I had in an EA. Note when I tried to use it as an indicator though it didn’t work not sure why yet.

You could set up 2 variables MACDP (to count candles after cross above) and MACDN (to count candles after cross below) or anything else that makes sense to you. This is done in the Strategy tab in the bottom box “Strategy parameters”. Make them integer type.

Then set up 2 new rules that calculate on candle close
1) IF MACD > 0 Then MACDP = MACDP + 1 AND MACDN = 0
2) IF MACD < 0 Then MACDN = MACDN + 1 AND MACDP = 0
Make sure these 2 rules are before the RSI test in order of execution

Then your RSI test would be
1) IF RSI Crosses above 50 and MACDP > 0 and MACDP < 11 Then trade condition
2) IF RSI Crosses below 50 and MACDN -11 Then trade condition

Hi Chris, 

 

Really appreciate the insight. I understand what you’re saying, but how does the EA recognize that it should only add to MACDP and MACDN after a cross over/under has occurred within the previous 10 periods? 

 

For example, if I attach the EA when MACD is above 0 and the crossover occurred 20 periods ago, MACDP would be 1, and the condition would be ripe for entry, though it has actually expired.

 

If we could use a WHILE operator in conjunction with a true/false flag, this would be a lot easier, but with only IF, I’m still unsure.

0

chris.marshall

Subscriber, bbp_participant, community, 4 replies.

Visit profile

7 years ago #141297

The way it is written above it would count from the first candle after the cross in either direction.

If there were 20 positive candles MACDP would get to 20 but your RSI test would only be valid while MACDP is between 1 and 10.

 

You are right though this doesn’t account for the period between when you load the EA and the first cross. An easy way to get around this would be to just count candles since last cross either above or below and set starting value of MACDP/MACDN accordingly when loading the EA.

 

I am sure there are more elegant ways around it but I am still new to the program.

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

7 years ago #141311

Hello,

 

the easiest way to accomplish this is to setup a counter. When MACD condition is valid than counter is being activated to do counter = counter + 1 (initially it is set to 0)

You now count each new bar using this. At the same time the counter is active you watch RSI condition but only until counter is less than 10. Once counter > 10 your reset it to 0 and wait for another MACD signal.

 

Let me know if you need an example project for this

0

huangwh88

Customer, bbp_participant, community, 113 replies.

Visit profile

7 years ago #141325

The way it is written above it would count from the first candle after the cross in either direction.

If there were 20 positive candles MACDP would get to 20 but your RSI test would only be valid while MACDP is between 1 and 10.

 

You are right though this doesn’t account for the period between when you load the EA and the first cross. An easy way to get around this would be to just count candles since last cross either above or below and set starting value of MACDP/MACDN accordingly when loading the EA.

 

I am sure there are more elegant ways around it but I am still new to the program.

Yes I thought about it and there is indeed an easy solution, similar to the one you mentioned. We can set the counter to start only after a cross. There could be some ‘lost time’ if a cross happened to occur shortly before I attached the EA, but it’s no big issue. 

 

Thank you for your help!

0

huangwh88

Customer, bbp_participant, community, 113 replies.

Visit profile

7 years ago #141326

Hello,

 

the easiest way to accomplish this is to setup a counter. When MACD condition is valid than counter is being activated to do counter = counter + 1 (initially it is set to 0)

You now count each new bar using this. At the same time the counter is active you watch RSI condition but only until counter is less than 10. Once counter > 10 your reset it to 0 and wait for another MACD signal.

 

Let me know if you need an example project for this

Hi Tomas, 

 

please send me the example project. Thank you!

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

7 years ago #141338

Hello,

 

find the example attached. EA waits for RSI cross above 20 level. Then it waits 10 bars for MACD cross 0 level. If no signal comes from MACD, everything starts over

0

Viewing 7 replies - 1 through 7 (of 7 total)