Login Page - Create Account

Support Board


Date/Time: Wed, 24 Apr 2024 05:57:45 +0000



[Programming Help] - Moving average cross then price retraces to go back and touch another ma

View Count: 1212

[2019-09-03 20:21:54]
User334484 - Posts: 6
Hello
Thanks for any help with this, I'm trying to write code for spreadsheet auto trading, for when a 55 ema crosses a 34 ema with a gap, then price comes retraces and touches a 34 ema.
I've been able to write the basic formula for a moving average cross (=CROSSFROMBELOW(ID4.SG1@3:ID4.SG1@4,ID3.SG1@3:ID3.SG1@4), but can't seem to find anything with using a cross with a gap, then price retracing to touch.
Any leads, help would be much appreciated.
Thanks Again
Mark
Date Time Of Last Edit: 2019-09-03 21:15:50
[2019-09-04 01:32:57]
Sawtooth - Posts: 3976
Do you mean when the 34EMA crosses the 55EMA? (It is rare for a slower EMA to cross a faster EMA, in the direction of the trade.)

You'll need to create a persistent variable of the cross event so it is available to reference when price retraces.
You'll also need a condition to release the persistent variable. See example formulas below.

ID3 = 34EMA
ID4 = 55EMA

Cell P3:
=IF(ID3.SG1@3>ID4.SG1@3+$J$21*2,1,IF(AND(ID3.SG1@4>ID4.SG1@4,ID3.SG1@3<ID4.SG1@3),0,P4))
This returns 1 at the first bar when the 34EMA is 2 ticks above the 55EMA, and makes it persistent until the 34EMA crosses below the 55EMA.

Cell Q3:
=IF(AND(P3,E4>ID3.SG1@4,E3<=ID3.SG1@3),1,IF(P3=0,0,Q4))
This looks for a 1 in column P, when the Last price touches/crosses the 34EMA, then makes it persistent until the 34EMA crosses below the 55EMA.

Cell K3:
=AND(Q4=0,Q3)

You'll need to replicate the examples for short entries in M3.
Date Time Of Last Edit: 2019-09-07 01:00:13
[2019-09-07 01:27:05]
Bubba - Posts: 30
Yes that was my original question.
I looked in the support board tickets but couldn't find the link for my original.
I didn't see this updated version.
I also neglected to put the variable of ID3 and ID4, remembering back it was because I wasn't sure where to put it
Mark

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account