StockFetcher Forums · General Discussion · Help for 'strange' syntax error<< >>Post Follow-up
lorypanna
19 posts
msg #160239
Ignore lorypanna
4/3/2023 11:54:23 AM

Hi

I'm trying the code below (it's an attempt of mine to code in SF a TC2K scan).

NOTE1: likely its execution requires advanced SF subscription level.
NOTE2: the code below is the working version where I commented out the lines causing it not to work. Removing the comments' delimiters from those lines (all the ones beginning with '/* SYNTAX ERROR? ...') the script stops working.

It contains some commented lines beginning with '/* SYNTAX ERROR? ...'.
The first of them seems the one causing the filter not working: 'set {My4Avg42TotEntryFlag, count(My4Avg42TotEntry equals 11, 1)}'

I cannot figure out what code is wrong in this line. It appears to me very similar to a following one ('set {My4Avg42TotExitFlag, count(My4Avg42TotExit equals 2, 1)}') which works fine.

Can someone help figuring out what I'm doing wrong?

Thanks for any help. Cheers from Italy. LP


Fetcher[
/* Interesting exchanges are NASDAQ and NYSE */
set {IsNSDQ, count(market is NASDAQ, 1)}
set {IsNYSE, count(market is NYSE, 1)}
set {ExchangeOfInterest, IsNSDQ + IsNYSE}

/* ETFs are identified */
set {IsETF, count(stock type is ETF, 1)}

/* Minimum and maximum close price and average volume of interest */
set {cnstMinPriceOK, 5.0}
set {cnstMaxPriceOK, 50.36}
set {cnstMinAvgVolOK, 500000}

/* Average Volume on the last 50 days */
set {MyAvgVolume, cma(volume, 50)}
set {MyAvgVolumeOK, count(MyAvgVolume > cnstMinAvgVolOK, 1)}


/* TC2000 - Code source of indicator */
/* Entry signal */
/*
AVGC4/AVGC42 > 1.01
AND AVGC4.1/AVGC42.1 < 1.01
AND AVGC4.2/AVGC42.2 < 1.01
AND AVGC4.3/AVGC42.3 < 1.01
AND AVGC4.4/AVGC42.4 < 1.01
AND AVGC4.5/AVGC42.5 < 1.01
AND AVGC4.6/AVGC42.6 < 1.01
AND AVGC4.7/AVGC42.7 < 1.01
AND AVGC4.8/AVGC42.8 < 1.01
AND AVGC4.9/AVGC42.9 < 1.01
AND AVGC4.10/AVGC42.10 < 1.01
*/

/* AVGC4, AVGC42 */
set {MyCloseAvg4, cma(close, 4)}
set {MyCloseAvg42, cma(close, 42)}

/* AVGC4/AVGC42 > 1.01 */
set {My4Avg42Ratio, MyCloseAvg4 / MyCloseAvg42}
set {My4Avg42Flag, count(My4Avg42Ratio > 1.01, 1)}

/* AVGC4.1/AVGC42.1 < 1.01 */
set {MyCloseAvg4D1, MyCloseAvg4 1 day ago}
set {MyCloseAvg42D1, MyCloseAvg42 1 day ago}
set {My4Avg42D1Ratio, MyCloseAvg4D1 / MyCloseAvg42D1}
set {My4Avg42D1Flag, count(My4Avg42D1Ratio < 1.01, 1)}

/* AVGC4.2/AVGC42.2 < 1.01 */
set {MyCloseAvg4D2, MyCloseAvg4 2 days ago}
set {MyCloseAvg42D2, MyCloseAvg42 2 days ago}
set {My4Avg42D2Ratio, MyCloseAvg4D2 / MyCloseAvg42D2}
set {My4Avg42D2Flag, count(My4Avg42D2Ratio < 1.01, 1)}

/* AVGC4.3/AVGC42.3 < 1.01 */
set {MyCloseAvg4D3, MyCloseAvg4 3 days ago}
set {MyCloseAvg42D3, MyCloseAvg42 3 days ago}
set {My4Avg42D3Ratio, MyCloseAvg4D3 / MyCloseAvg42D3}
set {My4Avg42D3Flag, count(My4Avg42D3Ratio < 1.01, 1)}

/* AVGC4.4/AVGC42.4 < 1.01 */
set {MyCloseAvg4D4, MyCloseAvg4 4 days ago}
set {MyCloseAvg42D4, MyCloseAvg42 4 days ago}
set {My4Avg42D4Ratio, MyCloseAvg4D4 / MyCloseAvg42D4}
set {My4Avg42D4Flag, count(My4Avg42D4Ratio < 1.01, 1)}

/* AVGC4.5/AVGC42.5 < 1.01 */
set {MyCloseAvg4D5, MyCloseAvg4 5 days ago}
set {MyCloseAvg42D5, MyCloseAvg42 5 days ago}
set {My4Avg42D5Ratio, MyCloseAvg4D5 / MyCloseAvg42D5}
set {My4Avg42D5Flag, count(My4Avg42D5Ratio < 1.01, 1)}

/* AVGC4.6/AVGC42.6 < 1.01 */
set {MyCloseAvg4D6, MyCloseAvg4 6 days ago}
set {MyCloseAvg42D6, MyCloseAvg42 6 days ago}
set {My4Avg42D6Ratio, MyCloseAvg4D6 / MyCloseAvg42D6}
set {My4Avg42D6Flag, count(My4Avg42D6Ratio < 1.01, 1)}

/* AVGC4.7/AVGC42.7 < 1.01 */
set {MyCloseAvg4D7, MyCloseAvg4 7 days ago}
set {MyCloseAvg42D7, MyCloseAvg42 7 days ago}
set {My4Avg42D7Ratio, MyCloseAvg4D7 / MyCloseAvg42D7}
set {My4Avg42D7Flag, count(My4Avg42D7Ratio < 1.01, 1)}

/* AVGC4.8/AVGC42.8 < 1.01 */
set {MyCloseAvg4D8, MyCloseAvg4 8 days ago}
set {MyCloseAvg42D8, MyCloseAvg42 8 days ago}
set {My4Avg42D8Ratio, MyCloseAvg4D8 / MyCloseAvg42D8}
set {My4Avg42D8Flag, count(My4Avg42D8Ratio < 1.01, 1)}

/* AVGC4.9/AVGC42.9 < 1.01 */
set {MyCloseAvg4D9, MyCloseAvg4 9 days ago}
set {MyCloseAvg42D9, MyCloseAvg42 9 days ago}
set {My4Avg42D9Ratio, MyCloseAvg4D9 / MyCloseAvg42D9}
set {My4Avg42D9Flag, count(My4Avg42D9Ratio < 1.01, 1)}

/* AVGC4.10/AVGC42.10 < 1.01 */
set {MyCloseAvg4D10, MyCloseAvg4 10 days ago}
set {MyCloseAvg42D10, MyCloseAvg42 10 days ago}
set {My4Avg42D10Ratio, MyCloseAvg4D10 / MyCloseAvg42D10}
set {My4Avg42D10Flag, count(My4Avg42D10Ratio < 1.01, 1)}

/* Single flags are added up */
/* When they're all valued 1, the 'Entry signal' is TRUE */
set {My4Avg42TotFlagTmp1, My4Avg42Flag + My4Avg42D1Flag}
set {My4Avg42TotFlagTmp2, My4Avg42TotFlagTmp1 + My4Avg42D2Flag}
set {My4Avg42TotFlagTmp3, My4Avg42TotFlagTmp2 + My4Avg42D3Flag}
set {My4Avg42TotFlagTmp4, My4Avg42TotFlagTmp3 + My4Avg42D4Flag}
set {My4Avg42TotFlagTmp5, My4Avg42TotFlagTmp4 + My4Avg42D5Flag}
set {My4Avg42TotFlagTmp6, My4Avg42TotFlagTmp5 + My4Avg42D6Flag}
set {My4Avg42TotFlagTmp7, My4Avg42TotFlagTmp6 + My4Avg42D7Flag}
set {My4Avg42TotFlagTmp8, My4Avg42TotFlagTmp7 + My4Avg42D8Flag}
set {My4Avg42TotFlagTmp9, My4Avg42TotFlagTmp8 + My4Avg42D9Flag}
set {My4Avg42TotEntry, My4Avg42TotFlagTmp9 + My4Avg42D10Flag}
/* SYNTAX ERROR? set {My4Avg42TotEntryFlag, count(My4Avg42TotEntry equals 11, 1)} */


/* TC2000 - Code source of indicator */
/* Exit signal */
/*
AVGC4/AVGC42 < 1.01
AND AVGC4.1/AVGC42.1 > 1.01
*/

/* AVGC4/AVGC42 < 1.01 */
set {My4Avg42ExitFlag, count(My4Avg42Ratio < 1.01, 1)}

/* AVGC4.1/AVGC42.1 > 1.01 */
set {My4Avg42D1ExitFlag, count(My4Avg42D1Ratio > 1.01, 1)}

/* Single flags are added up */
/* When they're all valued 1, the 'Exit signal' is TRUE */
set {My4Avg42TotExit, My4Avg42ExitFlag + My4Avg42D1ExitFlag}
set {My4Avg42TotExitFlag, count(My4Avg42TotExit equals 2, 1)}


/* Interesting stocks are filtered */
/* Exchanges of interest */
/**/
ExchangeOfInterest is above 0
/**/

/* ETFs are filtered out */
/**/
and IsETF equals 0
/**/

/* Close price constraints */
/**/
and close above cnstMinPriceOK
/**/
/*
and close below cnstMaxPriceOK
*/

/* Mean volume constraint */
/*
and MyAvgVolumeOK equals 1
*/


/* Condition for which the 'Entry signal' is TRUE */
/*
and My4Avg42TotEntryFlag equals 1
*/

/* Condition for which the 'Exit signal' is TRUE */
/*
and My4Avg42TotExitFlag equals 1
*/


add column My4Avg42TotEntry
/* SYNTAX ERROR? add column My4Avg42TotEntryFlag */
add column My4Avg42TotExitFlag

/* SYNTAX ERROR? draw My4Avg42TotEntryFlag */
draw My4Avg42TotExitFlag

do not draw ExchangeOfInterest
do not draw IsETF
do not draw cnstMinPriceOK
]




nibor100
1,031 posts
msg #160242
Ignore nibor100
4/3/2023 4:06:56 PM

It runs fine for me when I take off the Syntax Error comments on your 2 trouble lines, I have advanced subscription level.
Ed S.

lorypanna
19 posts
msg #160243
Ignore lorypanna
4/3/2023 5:38:43 PM

Thanks nibor100

I tried to remove the comments and still it doesn't work for me.
I get the following messages:
- "No Stocks Matched your filter."
- If I follow the link inside 'Click here to learn why' I see a triangle withan exclamation mark (should be the indication of a syntax error) near the following 3 lines:
-- set {My4Avg42TotEntryFlag, count(My4Avg42TotEntry equals 11, 1)}
-- add column My4Avg42TotEntryFlag
-- draw My4Avg42TotEntryFlag

Can you please confirm that you can successfully run the following code (same as before but with all cited commands uncommented)? It should return 4,488 stocks.

Thanks for your and others support. LP

Fetcher[

/* Interesting exchanges are NASDAQ and NYSE */
set {IsNSDQ, count(market is NASDAQ, 1)}
set {IsNYSE, count(market is NYSE, 1)}
set {ExchangeOfInterest, IsNSDQ + IsNYSE}

/* ETFs are identified */
set {IsETF, count(stock type is ETF, 1)}

/* Minimum and maximum close price and average volume of interest */
set {cnstMinPriceOK, 5.0}
set {cnstMaxPriceOK, 50.36}
set {cnstMinAvgVolOK, 500000}

/* Average Volume on the last 50 days */
set {MyAvgVolume, cma(volume, 50)}
set {MyAvgVolumeOK, count(MyAvgVolume > cnstMinAvgVolOK, 1)}


/* TC2000 - Code source of indicator */
/* Entry signal */
/*
AVGC4/AVGC42 > 1.01
AND AVGC4.1/AVGC42.1 < 1.01
AND AVGC4.2/AVGC42.2 < 1.01
AND AVGC4.3/AVGC42.3 < 1.01
AND AVGC4.4/AVGC42.4 < 1.01
AND AVGC4.5/AVGC42.5 < 1.01
AND AVGC4.6/AVGC42.6 < 1.01
AND AVGC4.7/AVGC42.7 < 1.01
AND AVGC4.8/AVGC42.8 < 1.01
AND AVGC4.9/AVGC42.9 < 1.01
AND AVGC4.10/AVGC42.10 < 1.01
*/

/* AVGC4, AVGC42 */
set {MyCloseAvg4, cma(close, 4)}
set {MyCloseAvg42, cma(close, 42)}

/* AVGC4/AVGC42 > 1.01 */
set {My4Avg42Ratio, MyCloseAvg4 / MyCloseAvg42}
set {My4Avg42Flag, count(My4Avg42Ratio > 1.01, 1)}

/* AVGC4.1/AVGC42.1 < 1.01 */
set {MyCloseAvg4D1, MyCloseAvg4 1 day ago}
set {MyCloseAvg42D1, MyCloseAvg42 1 day ago}
set {My4Avg42D1Ratio, MyCloseAvg4D1 / MyCloseAvg42D1}
set {My4Avg42D1Flag, count(My4Avg42D1Ratio < 1.01, 1)}

/* AVGC4.2/AVGC42.2 < 1.01 */
set {MyCloseAvg4D2, MyCloseAvg4 2 days ago}
set {MyCloseAvg42D2, MyCloseAvg42 2 days ago}
set {My4Avg42D2Ratio, MyCloseAvg4D2 / MyCloseAvg42D2}
set {My4Avg42D2Flag, count(My4Avg42D2Ratio < 1.01, 1)}

/* AVGC4.3/AVGC42.3 < 1.01 */
set {MyCloseAvg4D3, MyCloseAvg4 3 days ago}
set {MyCloseAvg42D3, MyCloseAvg42 3 days ago}
set {My4Avg42D3Ratio, MyCloseAvg4D3 / MyCloseAvg42D3}
set {My4Avg42D3Flag, count(My4Avg42D3Ratio < 1.01, 1)}

/* AVGC4.4/AVGC42.4 < 1.01 */
set {MyCloseAvg4D4, MyCloseAvg4 4 days ago}
set {MyCloseAvg42D4, MyCloseAvg42 4 days ago}
set {My4Avg42D4Ratio, MyCloseAvg4D4 / MyCloseAvg42D4}
set {My4Avg42D4Flag, count(My4Avg42D4Ratio < 1.01, 1)}

/* AVGC4.5/AVGC42.5 < 1.01 */
set {MyCloseAvg4D5, MyCloseAvg4 5 days ago}
set {MyCloseAvg42D5, MyCloseAvg42 5 days ago}
set {My4Avg42D5Ratio, MyCloseAvg4D5 / MyCloseAvg42D5}
set {My4Avg42D5Flag, count(My4Avg42D5Ratio < 1.01, 1)}

/* AVGC4.6/AVGC42.6 < 1.01 */
set {MyCloseAvg4D6, MyCloseAvg4 6 days ago}
set {MyCloseAvg42D6, MyCloseAvg42 6 days ago}
set {My4Avg42D6Ratio, MyCloseAvg4D6 / MyCloseAvg42D6}
set {My4Avg42D6Flag, count(My4Avg42D6Ratio < 1.01, 1)}

/* AVGC4.7/AVGC42.7 < 1.01 */
set {MyCloseAvg4D7, MyCloseAvg4 7 days ago}
set {MyCloseAvg42D7, MyCloseAvg42 7 days ago}
set {My4Avg42D7Ratio, MyCloseAvg4D7 / MyCloseAvg42D7}
set {My4Avg42D7Flag, count(My4Avg42D7Ratio < 1.01, 1)}

/* AVGC4.8/AVGC42.8 < 1.01 */
set {MyCloseAvg4D8, MyCloseAvg4 8 days ago}
set {MyCloseAvg42D8, MyCloseAvg42 8 days ago}
set {My4Avg42D8Ratio, MyCloseAvg4D8 / MyCloseAvg42D8}
set {My4Avg42D8Flag, count(My4Avg42D8Ratio < 1.01, 1)}

/* AVGC4.9/AVGC42.9 < 1.01 */
set {MyCloseAvg4D9, MyCloseAvg4 9 days ago}
set {MyCloseAvg42D9, MyCloseAvg42 9 days ago}
set {My4Avg42D9Ratio, MyCloseAvg4D9 / MyCloseAvg42D9}
set {My4Avg42D9Flag, count(My4Avg42D9Ratio < 1.01, 1)}

/* AVGC4.10/AVGC42.10 < 1.01 */
set {MyCloseAvg4D10, MyCloseAvg4 10 days ago}
set {MyCloseAvg42D10, MyCloseAvg42 10 days ago}
set {My4Avg42D10Ratio, MyCloseAvg4D10 / MyCloseAvg42D10}
set {My4Avg42D10Flag, count(My4Avg42D10Ratio < 1.01, 1)}

/* Single flags are added up */
/* When they're all valued 1, the 'Entry signal' is TRUE */
set {My4Avg42TotFlagTmp1, My4Avg42Flag + My4Avg42D1Flag}
set {My4Avg42TotFlagTmp2, My4Avg42TotFlagTmp1 + My4Avg42D2Flag}
set {My4Avg42TotFlagTmp3, My4Avg42TotFlagTmp2 + My4Avg42D3Flag}
set {My4Avg42TotFlagTmp4, My4Avg42TotFlagTmp3 + My4Avg42D4Flag}
set {My4Avg42TotFlagTmp5, My4Avg42TotFlagTmp4 + My4Avg42D5Flag}
set {My4Avg42TotFlagTmp6, My4Avg42TotFlagTmp5 + My4Avg42D6Flag}
set {My4Avg42TotFlagTmp7, My4Avg42TotFlagTmp6 + My4Avg42D7Flag}
set {My4Avg42TotFlagTmp8, My4Avg42TotFlagTmp7 + My4Avg42D8Flag}
set {My4Avg42TotFlagTmp9, My4Avg42TotFlagTmp8 + My4Avg42D9Flag}
set {My4Avg42TotEntry, My4Avg42TotFlagTmp9 + My4Avg42D10Flag}
set {My4Avg42TotEntryFlag, count(My4Avg42TotEntry equals 11, 1)}


/* TC2000 - Code source of indicator */
/* Exit signal */
/*
AVGC4/AVGC42 < 1.01
AND AVGC4.1/AVGC42.1 > 1.01
*/

/* AVGC4/AVGC42 < 1.01 */
set {My4Avg42ExitFlag, count(My4Avg42Ratio < 1.01, 1)}

/* AVGC4.1/AVGC42.1 > 1.01 */
set {My4Avg42D1ExitFlag, count(My4Avg42D1Ratio > 1.01, 1)}

/* Single flags are added up */
/* When they're all valued 1, the 'Exit signal' is TRUE */
set {My4Avg42TotExit, My4Avg42ExitFlag + My4Avg42D1ExitFlag}
set {My4Avg42TotExitFlag, count(My4Avg42TotExit equals 2, 1)}


/* Interesting stocks are filtered */
/* Exchanges of interest */
/**/
ExchangeOfInterest is above 0
/**/

/* ETFs are filtered out */
/**/
and IsETF equals 0
/**/

/* Close price constraints */
/**/
and close above cnstMinPriceOK
/**/
/*
and close below cnstMaxPriceOK
*/

/* Mean volume constraint */
/*
and MyAvgVolumeOK equals 1
*/


/* Condition for which the 'Entry signal' is TRUE */
/*
and My4Avg42TotEntryFlag equals 1
*/

/* Condition for which the 'Exit signal' is TRUE */
/*
and My4Avg42TotExitFlag equals 1
*/


add column My4Avg42TotEntry
add column My4Avg42TotEntryFlag
add column My4Avg42TotExitFlag

draw My4Avg42TotEntryFlag
draw My4Avg42TotExitFlag

do not draw ExchangeOfInterest
do not draw IsETF
do not draw cnstMinPriceOK
]



jimvin
173 posts
msg #160244
Ignore jimvin
4/3/2023 10:41:31 PM

At the most basic level of operational knowledge (which is proudly mine) have you tried StockFetcher's "Debug" function? It's helped me through a few (though not all) rough patches...

nibor100
1,031 posts
msg #160245
Ignore nibor100
4/4/2023 12:35:40 AM

Sorry, I missed one of the Syntax Error lines.

When I remove the Syntax Error from the first one and leave the last 2 commented out your filter runs in advanced subscription but if either of the other 2 are un-commented it fails so its a nesting problem.

There are some possible workarounds and i'll take a look at it later and see what I can come up with.

I use TC2000 also, is this from their Worden forum or your own PCF?

Thanks,
Ed S.

nibor100
1,031 posts
msg #160246
Ignore nibor100
4/4/2023 1:12:07 AM

In order to get your last posted filter to run I have to comment out the last 7 lines of the filter and then it returns 5,012 stocks.

To get rid of nesting and make your filter simpler I replace cma(4) and cma(42) in all occurences with ma(4) and ma(42) since your cma statements are taking a cma of the close price which is what the standard ma in SF does.

after doing all of those replacements the nesting is not as deep and all lines of your last filter run with those modifications and also returns 5,012 stocks.

I can't figure out how you get 4,488 stocks.

My modified filter is below.
Thanks,
Ed S.

Fetcher[
/* Interesting exchanges are NASDAQ and NYSE */
set {IsNSDQ, count(market is NASDAQ, 1)}
set {IsNYSE, count(market is NYSE, 1)}
set {ExchangeOfInterest, IsNSDQ + IsNYSE}

/* ETFs are identified */
set {IsETF, count(stock type is ETF, 1)}

/* Minimum and maximum close price and average volume of interest */
set {cnstMinPriceOK, 5.0}
set {cnstMaxPriceOK, 50.36}
set {cnstMinAvgVolOK, 500000}

/* Average Volume on the last 50 days */
set {MyAvgVolume, cma(volume, 50)}
set {MyAvgVolumeOK, count(MyAvgVolume > cnstMinAvgVolOK, 1)}


/* TC2000 - Code source of indicator */
/* Entry signal */
/*
AVGC4/AVGC42 > 1.01
AND AVGC4.1/AVGC42.1 < 1.01
AND AVGC4.2/AVGC42.2 < 1.01
AND AVGC4.3/AVGC42.3 < 1.01
AND AVGC4.4/AVGC42.4 < 1.01
AND AVGC4.5/AVGC42.5 < 1.01
AND AVGC4.6/AVGC42.6 < 1.01
AND AVGC4.7/AVGC42.7 < 1.01
AND AVGC4.8/AVGC42.8 < 1.01
AND AVGC4.9/AVGC42.9 < 1.01
AND AVGC4.10/AVGC42.10 < 1.01
*/

/* AVGC4, AVGC42 */
/*set {MyCloseAvg4, cma(close, 4)}
set {MyCloseAvg42, cma(close, 42)}*/

/* AVGC4/AVGC42 > 1.01 */
set {My4Avg42Ratio, ma(4) / ma(42)}
set {My4Avg42Flag, count(My4Avg42Ratio > 1.01, 1)}

/* AVGC4.1/AVGC42.1 < 1.01 */
set {MyCloseAvg4D1, ma(4) 1 day ago}
set {MyCloseAvg42D1, ma(42) 1 day ago}
set {My4Avg42D1Ratio, MyCloseAvg4D1 / MyCloseAvg42D1}
set {My4Avg42D1Flag, count(My4Avg42D1Ratio < 1.01, 1)}

/* AVGC4.2/AVGC42.2 < 1.01 */
set {MyCloseAvg4D2, ma(4) 2 days ago}
set {MyCloseAvg42D2, ma(42) 2 days ago}
set {My4Avg42D2Ratio, MyCloseAvg4D2 / MyCloseAvg42D2}
set {My4Avg42D2Flag, count(My4Avg42D2Ratio < 1.01, 1)}

/* AVGC4.3/AVGC42.3 < 1.01 */
set {MyCloseAvg4D3, ma(4) 3 days ago}
set {MyCloseAvg42D3, ma(42) 3 days ago}
set {My4Avg42D3Ratio, MyCloseAvg4D3 / MyCloseAvg42D3}
set {My4Avg42D3Flag, count(My4Avg42D3Ratio < 1.01, 1)}

/* AVGC4.4/AVGC42.4 < 1.01 */
set {MyCloseAvg4D4, ma(4) 4 days ago}
set {MyCloseAvg42D4, ma(42) 4 days ago}
set {My4Avg42D4Ratio, MyCloseAvg4D4 / MyCloseAvg42D4}
set {My4Avg42D4Flag, count(My4Avg42D4Ratio < 1.01, 1)}

/* AVGC4.5/AVGC42.5 < 1.01 */
set {MyCloseAvg4D5, ma(4) 5 days ago}
set {MyCloseAvg42D5, ma(42) 5 days ago}
set {My4Avg42D5Ratio, MyCloseAvg4D5 / MyCloseAvg42D5}
set {My4Avg42D5Flag, count(My4Avg42D5Ratio < 1.01, 1)}

/* AVGC4.6/AVGC42.6 < 1.01 */
set {MyCloseAvg4D6, ma(4) 6 days ago}
set {MyCloseAvg42D6, ma(42) 6 days ago}
set {My4Avg42D6Ratio, MyCloseAvg4D6 / MyCloseAvg42D6}
set {My4Avg42D6Flag, count(My4Avg42D6Ratio < 1.01, 1)}

/* AVGC4.7/AVGC42.7 < 1.01 */
set {MyCloseAvg4D7, ma(4) 7 days ago}
set {MyCloseAvg42D7, ma(42) 7 days ago}
set {My4Avg42D7Ratio, MyCloseAvg4D7 / MyCloseAvg42D7}
set {My4Avg42D7Flag, count(My4Avg42D7Ratio < 1.01, 1)}

/* AVGC4.8/AVGC42.8 < 1.01 */
set {MyCloseAvg4D8, ma(4) 8 days ago}
set {MyCloseAvg42D8, ma(42) 8 days ago}
set {My4Avg42D8Ratio, MyCloseAvg4D8 / MyCloseAvg42D8}
set {My4Avg42D8Flag, count(My4Avg42D8Ratio < 1.01, 1)}

/* AVGC4.9/AVGC42.9 < 1.01 */
set {MyCloseAvg4D9, ma(4) 9 days ago}
set {MyCloseAvg42D9, ma(42) 9 days ago}
set {My4Avg42D9Ratio, MyCloseAvg4D9 / MyCloseAvg42D9}
set {My4Avg42D9Flag, count(My4Avg42D9Ratio < 1.01, 1)}

/* AVGC4.10/AVGC42.10 < 1.01 */
set {MyCloseAvg4D10, ma(4) 10 days ago}
set {MyCloseAvg42D10, ma(42) 10 days ago}
set {My4Avg42D10Ratio, MyCloseAvg4D10 / MyCloseAvg42D10}
set {My4Avg42D10Flag, count(My4Avg42D10Ratio < 1.01, 1)}

/* Single flags are added up */
/* When they're all valued 1, the 'Entry signal' is TRUE */
set {My4Avg42TotFlagTmp1, My4Avg42Flag + My4Avg42D1Flag}
set {My4Avg42TotFlagTmp2, My4Avg42TotFlagTmp1 + My4Avg42D2Flag}
set {My4Avg42TotFlagTmp3, My4Avg42TotFlagTmp2 + My4Avg42D3Flag}
set {My4Avg42TotFlagTmp4, My4Avg42TotFlagTmp3 + My4Avg42D4Flag}
set {My4Avg42TotFlagTmp5, My4Avg42TotFlagTmp4 + My4Avg42D5Flag}
set {My4Avg42TotFlagTmp6, My4Avg42TotFlagTmp5 + My4Avg42D6Flag}
set {My4Avg42TotFlagTmp7, My4Avg42TotFlagTmp6 + My4Avg42D7Flag}
set {My4Avg42TotFlagTmp8, My4Avg42TotFlagTmp7 + My4Avg42D8Flag}
set {My4Avg42TotFlagTmp9, My4Avg42TotFlagTmp8 + My4Avg42D9Flag}
set {My4Avg42TotEntry, My4Avg42TotFlagTmp9 + My4Avg42D10Flag}
set {My4Avg42TotEntryFlag, count(My4Avg42TotEntry equals 11, 1)}


/* TC2000 - Code source of indicator */
/* Exit signal */
/*
AVGC4/AVGC42 < 1.01
AND AVGC4.1/AVGC42.1 > 1.01
*/

/* AVGC4/AVGC42 < 1.01 */
set {My4Avg42ExitFlag, count(My4Avg42Ratio < 1.01, 1)}

/* AVGC4.1/AVGC42.1 > 1.01 */
set {My4Avg42D1ExitFlag, count(My4Avg42D1Ratio > 1.01, 1)}

/* Single flags are added up */
/* When they're all valued 1, the 'Exit signal' is TRUE */
set {My4Avg42TotExit, My4Avg42ExitFlag + My4Avg42D1ExitFlag}
set {My4Avg42TotExitFlag, count(My4Avg42TotExit equals 2, 1)}


/* Interesting stocks are filtered */
/* Exchanges of interest */
/**/
ExchangeOfInterest is above 0
/**/

/* ETFs are filtered out */
/**/
and IsETF equals 0
/**/

/* Close price constraints */
/**/
and close above cnstMinPriceOK
/**/
/*
and close below cnstMaxPriceOK
*/

/* Mean volume constraint */
/*
and MyAvgVolumeOK equals 1
*/


/* Condition for which the 'Entry signal' is TRUE */
/*
and My4Avg42TotEntryFlag equals 1
*/

/* Condition for which the 'Exit signal' is TRUE */
/*
and My4Avg42TotExitFlag equals 1
*/


add column My4Avg42TotEntry
add column My4Avg42TotEntryFlag
add column My4Avg42TotExitFlag

draw My4Avg42TotEntryFlag
draw My4Avg42TotExitFlag

do not draw ExchangeOfInterest
do not draw IsETF
do not draw cnstMinPriceOK
]



lorypanna
19 posts
msg #160247
Ignore lorypanna
modified
4/4/2023 5:17:07 AM

Thanks again nibor100 and thanks jimvin too.

First thing I've to say it's that I'm just a beginner, both in using SF and both in trading / investing. At present I make very few trades and whenever possible I study [but with a full time job the time is limited; and many 'gray hair' on my head make my understanding much slower than some years ago ... No problem, I have time, every day a little step and, as we say in Italy, 'se son rose ... fioriranno' (don't know if the same expression in used in English: 'if they're roses ... they'll bloom')].

I'm interested in technical analysis and in ways to identify 'interesting' stocks with programming techniques. I like SF because it's very powerful but at the same time quite simple to learn, and at a cost for me affordable. I tried starting from raw data (Tiingo), but not much progress due too many components that have to be managed and my limitations.

I don't use TC2K (too expensive for what I need) but I started reading the blog https://stockbee.blogspot.com/ (the free version) where StockBee / @PradeepBonde makes extensive use of TC2K and its scans to explain the concepts and how he identifies his 'interesting' stocks.
And so I try to convert them into SF filters for trying to better understand the explained concepts and for seeing if I can use some of them in future for my trading.

This said, I come to the answers.

First reply for jimvin: yes I had tried it and it showed the same (syntax?) error that can be seen if using the link inside the string "Click here to learn why" that is available after the message "No Stocks Matched your filter". To be honest, I'm often not able to understand immediately where the error actually is analyzing the 'Debug' and/or the cited link ...

For nibor100:
1. I confirm that just uncommenting the (only probably wrong?) first line of the ORIGINAL filter, it works and I can use the variable / column 'My4Avg42TotEntry' to identify the 'interesting' stocks
2. Thanks for your updates to the filter code. Now it works as I originally wanted. In this moment in time (20230404, 10:55AM Italy time), the stocks returned by the filter are "4716 results from Monday April 3, 2023"
3. The filter is based on the following post in the above cited site: https://stockbee.blogspot.com/2011/06/q-with-pradeep-bonde.html (search for '401K mutual fund' to identify the section containing the TC2K scan). NOTE: I'm not interested in '401K mutual funds', I just tried to convert the scan to SF (as an exercise); anyway, it could be a useful filter for who is interested in that type of investment, read the post if that is the case
4. Because you use TC2K, if you have time and want to do it, can you confirm that similar results are returned from the scan (my objective is to check if I understood well the TC2K syntax and then if I implemented a 'good' similar filter in SF). But don't lose too much time in it, it's just a check if you are interested
5. Just for reference, I put below the final working version of the SF filter (the one which returnetd the number of stocks above cited)

Have a nice day and thanks for the support (and sorry for my poor English, likely full of errors and words used with the wrong meaning due to 'false friendship' with Italian ones). LP

Fetcher[
/**********************************************************************************************************/
/* StockBee - Scan For Mutual Funds Starting An Uptrend */
/* */
/* https://stockbee.blogspot.com/2011/06/q-with-pradeep-bonde.html - Search for string '401K mutual fund' */
/* */
/**********************************************************************************************************/

/* Interesting exchanges are NASDAQ and NYSE */
set {IsNSDQ, count(market is NASDAQ, 1)}
set {IsNYSE, count(market is NYSE, 1)}
set {ExchangeOfInterest, IsNSDQ + IsNYSE}

/* ETFs are identified */
set {IsETF, count(stock type is ETF, 1)}

/* Minimum and maximum close price and average volume of interest */
set {cnstMinPriceOK, 5.0}
set {cnstMaxPriceOK, 50.36}
set {cnstMinAvgVolOK, 500000}

/* Average Volume on the last 50 days */
set {MyAvgVolume, cma(volume, 50)}
set {MyAvgVolumeOK, count(MyAvgVolume > cnstMinAvgVolOK, 1)}


/* TC2000 - Code source of indicator */
/* Entry signal */
/*
AVGC4/AVGC42 > 1.01
AND AVGC4.1/AVGC42.1 < 1.01
AND AVGC4.2/AVGC42.2 < 1.01
AND AVGC4.3/AVGC42.3 < 1.01
AND AVGC4.4/AVGC42.4 < 1.01
AND AVGC4.5/AVGC42.5 < 1.01
AND AVGC4.6/AVGC42.6 < 1.01
AND AVGC4.7/AVGC42.7 < 1.01
AND AVGC4.8/AVGC42.8 < 1.01
AND AVGC4.9/AVGC42.9 < 1.01
AND AVGC4.10/AVGC42.10 < 1.01
*/

/* AVGC4, AVGC42 */
set {MyCloseAvg4, ma(4)}
set {MyCloseAvg42, ma(42)}

/* AVGC4/AVGC42 > 1.01 */
set {My4Avg42Ratio, MyCloseAvg4 / MyCloseAvg42}
set {My4Avg42Flag, count(My4Avg42Ratio > 1.01, 1)}

/* AVGC4.1/AVGC42.1 < 1.01 */
set {MyCloseAvg4D1, ma(4) 1 day ago}
set {MyCloseAvg42D1, ma(42) 1 day ago}
set {My4Avg42D1Ratio, MyCloseAvg4D1 / MyCloseAvg42D1}
set {My4Avg42D1Flag, count(My4Avg42D1Ratio < 1.01, 1)}

/* AVGC4.2/AVGC42.2 < 1.01 */
set {MyCloseAvg4D2, ma(4) 2 days ago}
set {MyCloseAvg42D2, ma(42) 2 days ago}
set {My4Avg42D2Ratio, MyCloseAvg4D2 / MyCloseAvg42D2}
set {My4Avg42D2Flag, count(My4Avg42D2Ratio < 1.01, 1)}

/* AVGC4.3/AVGC42.3 < 1.01 */
set {MyCloseAvg4D3, ma(4) 3 days ago}
set {MyCloseAvg42D3, ma(42) 3 days ago}
set {My4Avg42D3Ratio, MyCloseAvg4D3 / MyCloseAvg42D3}
set {My4Avg42D3Flag, count(My4Avg42D3Ratio < 1.01, 1)}

/* AVGC4.4/AVGC42.4 < 1.01 */
set {MyCloseAvg4D4, ma(4) 4 days ago}
set {MyCloseAvg42D4, ma(42) 4 days ago}
set {My4Avg42D4Ratio, MyCloseAvg4D4 / MyCloseAvg42D4}
set {My4Avg42D4Flag, count(My4Avg42D4Ratio < 1.01, 1)}

/* AVGC4.5/AVGC42.5 < 1.01 */
set {MyCloseAvg4D5, ma(4) 5 days ago}
set {MyCloseAvg42D5, ma(42) 5 days ago}
set {My4Avg42D5Ratio, MyCloseAvg4D5 / MyCloseAvg42D5}
set {My4Avg42D5Flag, count(My4Avg42D5Ratio < 1.01, 1)}

/* AVGC4.6/AVGC42.6 < 1.01 */
set {MyCloseAvg4D6, ma(4) 6 days ago}
set {MyCloseAvg42D6, ma(42) 6 days ago}
set {My4Avg42D6Ratio, MyCloseAvg4D6 / MyCloseAvg42D6}
set {My4Avg42D6Flag, count(My4Avg42D6Ratio < 1.01, 1)}

/* AVGC4.7/AVGC42.7 < 1.01 */
set {MyCloseAvg4D7, ma(4) 7 days ago}
set {MyCloseAvg42D7, ma(42) 7 days ago}
set {My4Avg42D7Ratio, MyCloseAvg4D7 / MyCloseAvg42D7}
set {My4Avg42D7Flag, count(My4Avg42D7Ratio < 1.01, 1)}

/* AVGC4.8/AVGC42.8 < 1.01 */
set {MyCloseAvg4D8, ma(4) 8 days ago}
set {MyCloseAvg42D8, ma(42) 8 days ago}
set {My4Avg42D8Ratio, MyCloseAvg4D8 / MyCloseAvg42D8}
set {My4Avg42D8Flag, count(My4Avg42D8Ratio < 1.01, 1)}

/* AVGC4.9/AVGC42.9 < 1.01 */
set {MyCloseAvg4D9, ma(4) 9 days ago}
set {MyCloseAvg42D9, ma(42) 9 days ago}
set {My4Avg42D9Ratio, MyCloseAvg4D9 / MyCloseAvg42D9}
set {My4Avg42D9Flag, count(My4Avg42D9Ratio < 1.01, 1)}

/* AVGC4.10/AVGC42.10 < 1.01 */
set {MyCloseAvg4D10, ma(4) 10 days ago}
set {MyCloseAvg42D10, ma(42) 10 days ago}
set {My4Avg42D10Ratio, MyCloseAvg4D10 / MyCloseAvg42D10}
set {My4Avg42D10Flag, count(My4Avg42D10Ratio < 1.01, 1)}

/* Single flags are added up */
/* When they're all valued 1, the 'Entry signal' is TRUE */
set {My4Avg42TotFlagTmp1, My4Avg42Flag + My4Avg42D1Flag}
set {My4Avg42TotFlagTmp2, My4Avg42TotFlagTmp1 + My4Avg42D2Flag}
set {My4Avg42TotFlagTmp3, My4Avg42TotFlagTmp2 + My4Avg42D3Flag}
set {My4Avg42TotFlagTmp4, My4Avg42TotFlagTmp3 + My4Avg42D4Flag}
set {My4Avg42TotFlagTmp5, My4Avg42TotFlagTmp4 + My4Avg42D5Flag}
set {My4Avg42TotFlagTmp6, My4Avg42TotFlagTmp5 + My4Avg42D6Flag}
set {My4Avg42TotFlagTmp7, My4Avg42TotFlagTmp6 + My4Avg42D7Flag}
set {My4Avg42TotFlagTmp8, My4Avg42TotFlagTmp7 + My4Avg42D8Flag}
set {My4Avg42TotFlagTmp9, My4Avg42TotFlagTmp8 + My4Avg42D9Flag}
set {My4Avg42TotEntry, My4Avg42TotFlagTmp9 + My4Avg42D10Flag}
set {My4Avg42TotEntryFlag, count(My4Avg42TotEntry equals 11, 1)}


/* TC2000 - Code source of indicator */
/* Exit signal */
/*
AVGC4/AVGC42 < 1.01
AND AVGC4.1/AVGC42.1 > 1.01
*/

/* AVGC4/AVGC42 < 1.01 */
set {My4Avg42ExitFlag, count(My4Avg42Ratio < 1.01, 1)}

/* AVGC4.1/AVGC42.1 > 1.01 */
set {My4Avg42D1ExitFlag, count(My4Avg42D1Ratio > 1.01, 1)}

/* Single flags are added up */
/* When they're all valued 1, the 'Exit signal' is TRUE */
set {My4Avg42TotExit, My4Avg42ExitFlag + My4Avg42D1ExitFlag}
set {My4Avg42TotExitFlag, count(My4Avg42TotExit equals 2, 1)}


/* Chart settings */
chart-type Candles
chart-time is 12 months


/* Interesting stocks are filtered */
/* Exchanges of interest */
/**/
ExchangeOfInterest is above 0
/**/

/* ETFs are filtered out */
/**/
and IsETF equals 0
/**/

/* Close price constraints */
/**/
and close above cnstMinPriceOK
/**/
/*
and close below cnstMaxPriceOK
*/

/* Mean volume constraint */
/*
and MyAvgVolumeOK equals 1
*/


/* Condition for which the 'Entry signal' is TRUE */
/*
and My4Avg42TotEntryFlag equals 1
*/

/* Condition for which the 'Exit signal' is TRUE */
/*
and My4Avg42TotExitFlag equals 1
*/


add column My4Avg42TotEntryFlag
add column My4Avg42TotExitFlag

draw My4Avg42TotEntryFlag
draw My4Avg42TotExitFlag

do not draw ExchangeOfInterest
do not draw IsETF
do not draw cnstMinPriceOK
]



nibor100
1,031 posts
msg #160248
Ignore nibor100
4/5/2023 1:18:58 AM

When I run the entry PCF in TC200 Version20 I get 137 stocks, when I run your last posted filter in SF limiting the add column for entry to > 0 I get 147 results.

matching symbol sorts shows that some of the stocks found in SF are not in the database for TC2000 and other 10 stocks or so, that I checked, were in both. So your implementation is probably working as expected.

Ed S.

PS. It appears that blogger is recommending that scan for mutual funds only....though I'm not sure why that limitation as rationale seems to be missing.

lorypanna
19 posts
msg #160252
Ignore lorypanna
4/5/2023 5:56:10 PM

Thanks nibor100 for you checks and your support.
I cannot explain why the blogger limits this 'strategy' to mutual funds only.
Have a nice evening. Cheers from Italy

StockFetcher Forums · General Discussion · Help for 'strange' syntax error<< >>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.