Reply

Define range in bars instead of time

12 replies

DM00

Subscriber, bbp_participant, community, 11 replies.

Visit profile

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

 

 

0

Threshold

Customer, bbp_participant, community, 723 replies.

Visit profile

7 years ago #138885

DM00

Subscriber, bbp_participant, community, 11 replies.

Visit profile

7 years ago #138911

Hi again Threshold. 

 

 

Where is this ‘counter’ created? Is it written in SQ EA wizard?

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

7 years ago #138912

Yes, you define the counter as a new variable

0

DM00

Subscriber, bbp_participant, community, 11 replies.

Visit profile

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?

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

7 years ago #138914

The name does not matter. You just use this variable to store a calculated value

0

DM00

Subscriber, bbp_participant, community, 11 replies.

Visit profile

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

0

DM00

Subscriber, bbp_participant, community, 11 replies.

Visit profile

7 years ago #138918

This is the example I’m referring to. A rather tedious task especially to optimize or correct errors and yet this is just a small portion of what I’m trying.
 
 
file:///Users/deanmolyneaux/Desktop/Screen%20Shot%202016-08-22%20at%2011.00.09%20PM.png

0

DM00

Subscriber, bbp_participant, community, 11 replies.

Visit profile

7 years ago #138919

Sorry the file didn’t attach in the previous thread 

0

DM00

Subscriber, bbp_participant, community, 11 replies.

Visit profile

7 years ago #138920

Here is the file.. again

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

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

0

DM00

Subscriber, bbp_participant, community, 11 replies.

Visit profile

7 years ago #138933

Thank you. I am looking forward to it.

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

7 years ago #138937

Hello,

 

find the example attached. Both EMA and SMA have the same period setting

0

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