Define range in bars instead of time
12 replies
DM00
7 years ago #115455
Good day everyone,
I would like to set a strategy that is range based to enter a trade. I see in EA wizard where ranges is basically based on start time and end time. However I would like to setup range that is based on number or bars instead.
For example: to enter a sell order if EMA has a certain value for X bars(or X shifts if you please).
So If I want my expert advisor to enter a sell market order when the value of EMA for the past 10 bars is less than that of the current EMA value (shift 0), I have no idea how to go about it. Instead I have to use this long tedious process:
if
EMA (1) < EMA (0)
and
EMA(2) < EMA (0)
and
EMA(3) < EMA (0)
and
EMA(4) < EMA (0)
and
EMA(5) < EMA(0) ……… and so on.
You can imagine how long and tedious this would be if i were to use larger periods, like 20 or 30 bars, rather than having one strategy that says ‘last 20 EMA values less than current EMA value’.
I hope you understand what I’m trying o explain. Please Help
Thanks
Dean
Threshold
7 years ago #138885
DM00
7 years ago #138911
tomas262
7 years ago #138912
Yes, you define the counter as a new variable
DM00
7 years ago #138913
Forgive me I don’t know anything about coding. When defining the counter does it matter how I name it or does it have to be in the format ‘abcdefCounter’ with counter at the end?
tomas262
7 years ago #138914
The name does not matter. You just use this variable to store a calculated value
DM00
7 years ago #138917
Hope I’m not bothering you too much. I’ll give you a specific example to help me.
I want to set up a strategy where SQ will enter a long market order once the following conditions are met:
1. EMA has been above SMA for the past 20 bars and
2. SMA (1) crosses above EMA(1)
Its very hard to put in EMA above SMA individually for 20 bars plus I can’t optimize the number of historical bars( for eg if i ant to change it to 15 or 50 historical bars)
Thanks again
Dean
DM00
7 years ago #138918
DM00
7 years ago #138919
Sorry the file didn’t attach in the previous thread
DM00
7 years ago #138920
Here is the file.. again
tomas262
7 years ago #138925
Hello,
you don’t need to “hard-code” all the bars. Thats what is a counter for. I will create an example for this and upload here
DM00
7 years ago #138933
Thank you. I am looking forward to it.
tomas262
7 years ago #138937
Viewing 12 replies - 1 through 12 (of 12 total)