Reply

How to make a condition delay for a period time in a strategy

2 replies

Hans Hwang

Subscriber, bbp_participant, 2 replies.

Visit profile

3 years ago #259239

Hello I found AlgoWizard today and very exciting that this is really a good tool.

I have read the help document and tried some EA.

I want to make an EA with one or 2 conditions delay, which means when these condition trigered, the condition will be set to be True for a period time, no mater the original condition has turn into false。

here is an simple example:

When MACD divergency in the past 60 bars, when MACD cross 0 line open buy. ( it shows divergency in the past but maybe not in recent. )

I saw that we can use if…then to set variables, maybe I can set a variable when MACD divergency and let it last for 60 bars ?

And MACD divergency is another feature, which I have saw a sample in the user document, havn’t view it yet.

Any responce will be thanksful, I will go on try this and will give some further info.

thanks

 

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

3 years ago #259278

Hi,

if you want to combine two signals that do not have to appear at the same time but with a delay from one another you can easily achieve that by using variables (call them state variables) so you will split the logic into 2 steps:

1) check for MACD divergency … when a buy MACD divergency occurs you set a variable (create a new one called ‘divergencyState (int)) to +1

2) create a second condition that checks a situation when MACD crosses above 0 AND divergencyState = 1 …. now you can trigger a buy entry and set divergencyState back to 0 for next situation

This way there can be multiple bars delay between those two signals so after a divergence a strategy “waits” until the MACD crosses above 0 line

If you want to limit the number of bars between signals you also need to “count bars” after divergencyState is set to 1 and check for “max bars to detect MACD cross above 0”

Let me know if you need any help with this

0

Hans Hwang

Subscriber, bbp_participant, 2 replies.

Visit profile

3 years ago #259306

Thank you for your reply.

I have question about “count bars”, how can I do this ?

And about the macd divergency, I found that the example can’t click, which is https://algowizard.io/examples/

how can I check divergency?

thanks

0

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