StockFetcher Forums · General Discussion · Help with debugger / code<< 1 2 >>Post Follow-up
lorypanna
19 posts
msg #160383
Ignore lorypanna
modified
6/23/2023 2:58:16 AM

Hi

Just a beginner here.

Just for information, I'm using the advanced/full version of StockFetcher. I think that it's required for executing the filter below.

I'm trying to find stocks with 'converging' values of GMMA EMAs (references in the filter below).

The filter below does this:
1. Assigns short-term EMAs to variables
2. Calculates the min and max of all short-term EMAs
3. / 4. Repeats steps 1 and 2 for long-term EMAs
5. Calculates the min and max of all EMAs (MinAllEMAs and MaxAllEMAs)
6. Calculates a value that should describe how much all these EMAs are converging: the general formula is EMAMinMaxRatio = (MaxAllEMAs - MinAllEMAs) / {MinAllEMAs + [(MaxAllEMAs - MinAllEMAs) / 2]
NOTE: below you see a variation of this formula, just because I was trying different variations of the same formula, but none of them works ...

The problem is that variable EMAMinMaxRatio is not showing in results.
The debugger shows a triangle with an exclamation mark near the following commands but the result of the first two is showed in the results and it seems correct:
set {EMAMinMaxRatioTmp1, MinAllEMA / SumMaxMinAllEMA}
set {EMAMinMaxRatioTmp2, MaxAllEMA / SumMaxMinAllEMA}
set {EMAMinMaxRatio, EMAMinMaxRatioTmp2 - EMAMinMaxRatioTmp1}

I tried many variations of the formula but none of them worked.
Maybe the filter is too complex or maybe there's a limit on the use of "nested-variables".

Any help appreciated. If someone knows better ways (more efficient, maybe) to code the min/max sections, help will be appreciated too. Moreover, if someone knows a different way to obtain the same result (identify stocks with converging GMMA EMAs), thanks for sharing.

Thanks in advance. Have a nice day. Cheers from Italy

Fetcher[
/* GMMA (Guppy Multiple Moving Average) strategy EMAs - Aimed to find the PPL (Pivot Point Low) */
/* Reference - https://youtu.be/kjfW2BaeldU */
/* Website - https://www.guppytraders.com/ */
/* StockFetcher post - https://www.stockfetcher.com/forums/Filter-Exchange/EMA-Crossover/144990/-1/144991 */
/**/
/* Short term group - Valid on all timeframes */
/**/
set {Ema3, ema(3)}
set {Ema5, ema(5)}
set {Ema8, ema(8)}
set {Ema10, ema(10)}
set {Ema12, ema(12)}
set {Ema15, ema(15)}
/**/

/* Minimum and maximum of Short term group of EMAs */
/**/
set {MinStEMATmp1, min(Ema3, Ema5)}
set {MinStEMATmp2, min(MinStEMATmp1, Ema8)}
set {MinStEMATmp3, min(MinStEMATmp2, Ema10)}
set {MinStEMATmp4, min(MinStEMATmp3, Ema12)}
set {MinStEMA, min(MinStEMATmp4, Ema15)}

set {MaxStEMATmp1, max(Ema3, Ema5)}
set {MaxStEMATmp2, max(MaxStEMATmp1, Ema8)}
set {MaxStEMATmp3, max(MaxStEMATmp2, Ema10)}
set {MaxStEMATmp4, max(MaxStEMATmp3, Ema12)}
set {MaxStEMA, max(MaxStEMATmp4, Ema15)}
/**/

/* Long term group - Valid on all timeframes */
/**/
set {Ema30, ema(30)}
set {Ema35, ema(35)}
set {Ema40, ema(40)}
set {Ema45, ema(45)}
set {Ema50, ema(50)}
set {Ema60, ema(60)}
/**/

/* Minimum and maximum of Long term group of EMAs */
/**/
set {MinLtEMATmp1, min(Ema30, Ema35)}
set {MinLtEMATmp2, min(MinLtEMATmp1, Ema40)}
set {MinLtEMATmp3, min(MinLtEMATmp2, Ema45)}
set {MinLtEMATmp4, min(MinLtEMATmp3, Ema50)}
set {MinLtEMA, min(MinLtEMATmp4, Ema60)}

set {MaxLtEMATmp1, max(Ema30, Ema35)}
set {MaxLtEMATmp2, max(MaxLtEMATmp1, Ema40)}
set {MaxLtEMATmp3, max(MaxLtEMATmp2, Ema45)}
set {MaxLtEMATmp4, max(MaxLtEMATmp3, Ema50)}
set {MaxLtEMA, max(MaxLtEMATmp4, Ema60)}
/**/

/* Min and max of all EMAs, and their difference, are calculated */
/**/
set {MinAllEMA, min(MinStEMA, MinLtEMA)}
set {MaxAllEMA, max(MaxStEMA, MaxLtEMA)}
set {DiffMaxMinAllEMA, MaxAllEMA - MinAllEMA}

/* Difference between min and max of all EMAs is divided by the middle point of the interval */
set {SumMaxMinAllEMA, MaxAllEMA + MinAllEMA}
set {EMAMinMaxRatioTmp1, MinAllEMA / SumMaxMinAllEMA}
set {EMAMinMaxRatioTmp2, MaxAllEMA / SumMaxMinAllEMA}
set {EMAMinMaxRatio, EMAMinMaxRatioTmp2 - EMAMinMaxRatioTmp1}

add column MinAllEMA
add column MaxAllEMA
add column DiffMaxMinAllEMA
add column SumMaxMinAllEMA
add column EMAMinMaxRatioTmp1
add column EMAMinMaxRatioTmp2
add column EMAMinMaxRatio
/**/

where close above 10.0 and close below 12.0
]



Mactheriverrat
3,154 posts
msg #160384
Ignore Mactheriverrat
6/23/2023 9:17:22 PM

Well Welcome to Stockfetcher. There a lot of good poster's here still . The bear market of 2022 mid 2023 has slowed SF down some but there still here.

eronnenberg
5 posts
msg #160385
Ignore eronnenberg
modified
6/23/2023 11:11:35 PM

Your script seems to be testing the limits of the calculation engine, or maybe it's just timing it out. The main issue is the unnecessary calculations. This is essentially a MA Wave filter. You're looking for the compression and then expansion of two waves. So you really only need to know the high and low of the two waves; ema3 and ema15 for the fast wave and ema30 and ema60 for the slow wave.

Also, having a variable reference another variable that is just a built-in variable seems to hang up things.

This should fix what you're looking to do. I just marked out a lot of the extra lines. Also, having long variable names can start causing issues if you have too many.

Fetcher[

draw ema(3)
draw ema(5)
draw ema(8)
draw ema(10)
draw ema(12)
draw ema(15)

draw ema(30)
draw ema(35)
draw ema(40)
draw ema(45)
draw ema(50)
draw ema(60)


/* GMMA (Guppy Multiple Moving Average) strategy EMAs - Aimed to find the PPL (Pivot Point Low) */
/* Reference - https://youtu.be/kjfW2BaeldU */
/* Website - https://www.guppytraders.com/ */
/* StockFetcher post - https://www.stockfetcher.com/forums/Filter-Exchange/EMA-Crossover/144990/-1/144991 */
/**/
/* Short term group - Valid on all timeframes */
/*
set {Ema3, ema(3)}
set {Ema5, ema(5)}
set {Ema8, ema(8)}
set {Ema10, ema(10)}
set {Ema12, ema(12)}
set {Ema15, ema(15)}
/*/

/* Minimum and maximum of Short term group of EMAs */
/**/
/*/
set {MinStEMATmp1, min(ema(3), ema(5))}
set {MinStEMATmp2, min(MinStEMATmp1, ema(8))}
set {MinStEMATmp3, min(MinStEMATmp2, ema(10))}
set {MinStEMATmp4, min(MinStEMATmp3, ema(12))}
/*/
set {MinStEMA, min(ema(3), ema(15))}

/*/
set {MaxStEMATmp1, max(ema(3), ema(5))}
set {MaxStEMATmp2, max(MaxStEMATmp1, ema(8))}
set {MaxStEMATmp3, max(MaxStEMATmp2, ema(10))}
set {MaxStEMATmp4, max(MaxStEMATmp3, ema(12))}
/*/
set {MaxStEMA, max(ema(3), ema(15))}
/**/

/* Long term group - Valid on all timeframes */
/*
set {Ema30, ema(30)}
set {Ema35, ema(35)}
set {Ema40, ema(40)}
set {Ema45, ema(45)}
set {Ema50, ema(50)}
set {Ema60, ema(60)}
*/

/* Minimum and maximum of Long term group of EMAs */
/**/
/*/
set {MinLtEMATmp1, min(ema(30), ema(35))}
set {MinLtEMATmp2, min(MinLtEMATmp1, ema(40))}
set {MinLtEMATmp3, min(MinLtEMATmp2, ema(45))}
set {MinLtEMATmp4, min(MinLtEMATmp3, ema(50))}
/*/
set {MinLtEMA, min(ema(30), ema(60))}

/*/
set {MaxLtEMATmp1, max(ema(30), ema(35))}
set {MaxLtEMATmp2, max(MaxLtEMATmp1, ema(40))}
set {MaxLtEMATmp3, max(MaxLtEMATmp2, ema(45))}
set {MaxLtEMATmp4, max(MaxLtEMATmp3, ema(50))}
/*/
set {MaxLtEMA, max(ema(30), ema(60))}
/**/

/* Min and max of all EMAs, and their difference, are calculated */
/**/
set {MinAllEMA, min(MinStEMA, MinLtEMA)}
set {MaxAllEMA, max(MaxStEMA, MaxLtEMA)}
set {DiffMaxMinAllEMA, MaxAllEMA - MinAllEMA}

/* Difference between min and max of all EMAs is divided by the middle point of the interval */
set {SumMaxMinAllEMA, MaxAllEMA + MinAllEMA}
set {EMARatioTmp1, MinAllEMA / SumMaxMinAllEMA}
set {EMARatioTmp2, MaxAllEMA / SumMaxMinAllEMA}
set {EMARatio, EMARatioTmp2 - EMARatioTmp1}

add column MinAllEMA
add column MaxAllEMA
add column DiffMaxMinAllEMA
add column SumMaxMinAllEMA
add column EMARatioTmp1
add column EMARatioTmp2
add column EMARatio


draw EMARatioTmp1
draw EMARatioTmp2
draw EMARatio

/*/
where close above 10.0 and close below 12.0
/*/

dow 30
]



Also, using dow 30 for testing helps load times for faster results. Or russell 1000 if you need more hits.

eronnenberg
5 posts
msg #160386
Ignore eronnenberg
6/23/2023 11:39:28 PM

Now, to get what you're actually looking to do. I think that you're over thinking it.

You're looking for that compression of the faster wave and then the expansion to confirm the signal. So you're really only looking for an MA Cross event. And that'd be ema(3) crossing ema(15) for the fast wave and ema(30) crossing ema(60) for the slow wave.

"fastwave" and "slowwave" are just the EMA values added together into their respective waves. It's just a way to see what the wave as a whole is doing. The "signal_fastwave" will be active if the line above what it was the day before. You can use this to see it compressing if it was in a down trend and start expanding after the MA Cross. And vice versa for "signal_slowwave".

"wave" is just the fastwave minus the shortwave. It'll show when the fastwave crossed above the slow wave with the 0 line. "signal_wave" is the same as the other signals. However, it's also a decent pivot point indicator.

Fetcher[
draw ema(3)
draw ema(5)
draw ema(8)
draw ema(10)
draw ema(12)
draw ema(15)

draw ema(30)
draw ema(35)
draw ema(40)
draw ema(45)
draw ema(50)
draw ema(60)


set{ema3_crossup_ema15, count(ema(3) crossed above ema(15),1)}
draw ema3_crossup_ema15
set{ema30_crossup_ema60, count(ema(30) crossed above ema(60),1)}
draw ema30_crossup_ema60


set{fastwave_1, ema(3) + draw ema(5)}
set{fastwave_2, fastwave_1 + draw ema(8)}
set{fastwave_3, fastwave_2 + draw ema(10)}
set{fastwave_4, fastwave_3 + draw ema(12)}
set{fastwave, fastwave_4 + draw ema(15)}
add column separator
draw fastwave
set{signal_fastwave, count(fastwave > fastwave 1 day ago,1)}
draw signal_fastwave


set{slowwave_1, ema(30) + draw ema(35)}
set{slowwave_2, slowwave_1 + draw ema(40)}
set{slowwave_3, slowwave_2 + draw ema(45)}
set{slowwave_4, slowwave_3 + draw ema(50)}
set{slowwave, slowwave_4 + draw ema(60)}
draw slowwave
set{signal_slowwave, count(slowwave > slowwave 1 day ago,1)}
draw signal_slowwave

set{wave, fastwave - slowwave}
draw wave line at 0
set{signal_wave, count(wave > wave 1 day ago,1)}
draw signal_wave

add column separator
add column wave
add column signal_wave


ema(3) crossed above ema(15)
russell 1000

offset is 20
]



Someone better at this than me could probably come up with a better visual for showing the compression and expansions. But this seems to work.

lorypanna
19 posts
msg #160387
Ignore lorypanna
6/24/2023 4:52:29 AM

Hi

Thanks for the welcome, and thanks eronnenberg for the detailed answers and the code. I know that for sure I'm making useless and probably absurd things, but is the price I have to pay as a beginner with limited time.
Thanks for spending time to explain me what I could do better, I really appreciate that.

I'll provide a better reply after I have studied your code.

But for sure I thank you now because just looking your code I saw a lot of commands / filters I was not aware of.

Have a nice weekend. lp

lorypanna
19 posts
msg #160388
Ignore lorypanna
6/25/2023 11:39:03 AM

Hi eronnenberg, hi everybody

Very interesting the changes you made, in the first reply, to my version of the filter:
- Simplify the calculation of the variable I was thinking to use as an indicator of compression of the 2 waves (but then I saw your second post ...)
- Avoid to assign built-in variables to other variables. I did that because I used them more than once in my filter, and so I thought it was not efficient to ask the system to recalculate them more than once

Far more interesting for me the second version of the filter, thanks for this totally new version.
It helps me understand how much SF is powerful and gives me an idea about the use of 'flags' (0 / 1 variables).
It also shows me how to filter on indexes, I didn't know it was possible (now I found the following help topic: How can I screen for stocks within a specific index? - https://www.stockfetcher.com/help/How-can-I-screen-for-stocks-within-a-specific-index/100337).
But most of all it helps to understand what kind of strategies can be used and how to backtest them.

One question about this version: you use many commands similar to this one: 'set{slowwave_1, ema(30) + draw ema(35)}'. What the 'draw' command is useful for? I see that the command passes the debugger; if I remove it, it seemes to me that no changes happen ...

Thanks again and have a nice sunday. Cheers from Turin, Italy. lp

eronnenberg
5 posts
msg #160389
Ignore eronnenberg
6/25/2023 12:39:39 PM

"set{slowwave_1, ema(30) + draw ema(35)}'. What the 'draw' command is useful for? "

Oh, that was just a mistake on my part. I copy/paste a lot of my commands together, especially if it's similar commands for different variables. The SF scripting seems to be clever enough to ignore commands like that.

nibor100
1,031 posts
msg #160390
Ignore nibor100
6/26/2023 10:50:02 AM

@LP,

Here is a filter I wrote from a prior Guppy thread "Guppy Investigations". Searching on Guppy and/or GMMA might find other related filter info.
Ed S.

Here's a trial short filter version of the Guppy MMA's, all aligned, and sorted by those with least separation (short term group is just coming thru long term group, with both groups aligned).

Just click on the diff% column to reverse the sort and see the stocks having the greatest separation between the 2 aligned groups. (alignment in this case means the EMAs are stacked from shortest to longest in descending numerical order)

Submit
Fetcher[
eMA(3) > eMA(5) > eMA(8) > eMA(10) > eMA(12) > eMA(15)
eMA(30) > eMA(35) > eMA(40) > eMA(45) > eMA(50) > eMA(60)
set{diff, eMA(15) - eMA(30)}
set{diff%, diff/ema(15)}
/*diff < .5*/
diff% < .0575

add column diff
add column diff%
sort by column 6

chart-length is 4 months
price is above 7
average volume is above 50000
]



lorypanna
19 posts
msg #160391
Ignore lorypanna
modified
6/26/2023 1:55:23 PM

Hi @nibor100

Thanks for your post and code.
I found the post and I will read it with much interest.

I'm just a begineer, at present interested in the powerful features of StockFetcher and in reading the interesting posts in the forums.

I still have to find my way in trading ... We'll see.
Have a nice evening. Cheers from Italy

PS: very useful to read your and other users' code. I didn't know it was possible to concatenate many tests on the same line! Thanks

nibor100
1,031 posts
msg #160392
Ignore nibor100
6/26/2023 3:27:17 PM

@LP,

Your filter that you posted first in this thread had one too many nested levels of set variables so I did a slight modification, without changing any of your logic/calcs, to remove a nested level.

Essentially I removed all of your EMA variables and replaced them in your calc statements with the actual EMA(#) calc built into SF, as I've found over the years that SF built in indicators don't seem to count as a level of nesting.

Your "add column EMAMinMaxRatio" now works as you intended....

Ed S.

Fetcher[
/* GMMA (Guppy Multiple Moving Average) strategy EMAs - Aimed to find the PPL (Pivot Point Low) */
/* Reference - https://youtu.be/kjfW2BaeldU */
/* Website - https://www.guppytraders.com/ */
/* StockFetcher post - https://www.stockfetcher.com/forums/Filter-Exchange/EMA-Crossover/144990/-1/144991 */
/**/
/* Short term group - Valid on all timeframes */
/**/
/* Minimum and maximum of Short term group of EMAs */
/**/
where close above 10.0 and close below 12.0
set {MinStEMATmp1, min(Ema(3), Ema(5))}
set {MinStEMATmp2, min(MinStEMATmp1, Ema(8))}
set {MinStEMATmp3, min(MinStEMATmp2, Ema(10))}
set {MinStEMATmp4, min(MinStEMATmp3, Ema(12))}
set {MinStEMA, min(MinStEMATmp4, Ema(15))}

set {MaxStEMATmp1, max(Ema(3), Ema(5))}
set {MaxStEMATmp2, max(MaxStEMATmp1, Ema(8))}
set {MaxStEMATmp3, max(MaxStEMATmp2, Ema(10))}
set {MaxStEMATmp4, max(MaxStEMATmp3, Ema(12))}
set {MaxStEMA, max(MaxStEMATmp4, Ema(15))}
/**/

/* Long term group - Valid on all timeframes */
/* Minimum and maximum of Long term group of EMAs */
/**/
set {MinLtEMATmp1, min(Ema(30), Ema(35))}
set {MinLtEMATmp2, min(MinLtEMATmp1, Ema(40))}
set {MinLtEMATmp3, min(MinLtEMATmp2, Ema(45))}
set {MinLtEMATmp4, min(MinLtEMATmp3, Ema(50))}
set {MinLtEMA, min(MinLtEMATmp4, Ema(60))}

set {MaxLtEMATmp1, max(Ema(30), Ema(35))}
set {MaxLtEMATmp2, max(MaxLtEMATmp1, Ema(40))}
set {MaxLtEMATmp3, max(MaxLtEMATmp2, Ema(45))}
set {MaxLtEMATmp4, max(MaxLtEMATmp3, Ema(50))}
set {MaxLtEMA, max(MaxLtEMATmp4, Ema(60))}
/**/
/* Min and max of all EMAs, and their difference, are calculated */
/**/
set {MinAllEMA, min(MinStEMA, MinLtEMA)}
set {MaxAllEMA, max(MaxStEMA, MaxLtEMA)}
set {DiffMaxMinAllEMA, MaxAllEMA - MinAllEMA}


/* Difference between min and max of all EMAs is divided by the middle point of the interval */
set {SumMaxMinAllEMA, MaxAllEMA + MinAllEMA}
set {EMAMinMaxRatioTmp1, MinAllEMA / SumMaxMinAllEMA}
set {EMAMinMaxRatioTmp2, MaxAllEMA / SumMaxMinAllEMA}
set {EMAMinMaxRatio, EMAMinMaxRatioTmp2 - EMAMinMaxRatioTmp1}

add column MinAllEMA
add column MaxAllEMA
add column DiffMaxMinAllEMA
add column SumMaxMinAllEMA
add column EMAMinMaxRatioTmp1
add column EMAMinMaxRatioTmp2
add column EMAMinMaxRatio
/**/
]



StockFetcher Forums · General Discussion · Help with debugger / code<< 1 2 >>Post Follow-up

*** Disclaimer *** StockFetcher.com does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. StockFetcher.com does not recommend particular securities. StockFetcher.com, Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.


Copyright 2022 - Vestyl Software L.L.C.Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.