StockFetcher Forums · Filter Exchange · Trend Trader Strategy<< >>Post Follow-up
txraddoc
1 posts
msg #158384
Ignore txraddoc
modified
1/11/2022 2:31:22 PM

I've searched a bit through the forums and have not been able to find anything like this. I'm wondering how difficult it would be to code this for Stock Fetcher. It's called Trend Trader Strategy from Andrew Abraham in 1988.

https://c.mql5.com/forextsd/forum/89/trading_the_trend_-_andrew_abraham.pdf

Based on my VERY limited knowledge of Stockfetcher coding, I threw together this. If someone could turn this into working Stochfetcher code I would be eternally grateful.

set{todayrange, high - low}
set{highclose, high - close yesterday}
set{todaylow, low - close yesterday }

set{tts, highest of the three above}
set{ttsavg, (ema(21) of the ttsavg variable) * 3 }

plot tts avg

I've looked at an implementation of this on TradingView and it looks much more complicated than this. Not sure if its possible here.

Mactheriverrat
3,157 posts
msg #158385
Ignore Mactheriverrat
modified
1/11/2022 5:30:58 PM

I know this isn't what your looking for but it may be a start. SPY and NGL . NGL is what I'm in right now.

Submit
Fetcher[
SYMLIST(spy, ngl)
set{upper,ma(20) * 1.05}
set{lower,ma(20) * 0.95}
draw ma(20)
draw upper on plot close
draw lower on plot close

/* ma20 is number of consecutive days ma(20) above (+)/below(-) previous MA(20) */
set{ma2020b,days( ma(20) is above MA(20) one day ago ,250)}
set{ma2020a,days( ma(20) is below MA(20) one day ago ,250)}
set{ma2020, ma2020a - ma2020b} and add column ma2020 {ma2020}
do not Draw ma2020
Set{cntma2020,count( ma(20) > ma(20) one day ago ,1)}
draw cntma2020
Set{cntma2020b,count( ma(20) < ma(20) one day ago ,1)}
draw cntma2020b

]



nibor100
1,046 posts
msg #158392
Ignore nibor100
1/13/2022 11:50:00 AM

@txraddoc,

I think the filter below gets you close to what you want.
Ed S.

Fetcher[
close > 10

set{highclose, close 21 day high 1 day ago} add column highclose
set{lowclose, close 21 day low 1 day ago} add column lowclose
set{ttsavg, 3 * cwma(atr(1),21) } add column ttsavg
set{prehilimit, highclose - ttsavg}
set{prelolimit, lowclose + ttsavg}
set{hiclose, count(close > prehilimit,1)}
set{loclose, count(hiclose < 1,1)}
set{trendlinea, prehilimit * hiclose}
set{trendlineb, prelolimit * loclose}
set{trendline, trendlinea + trendlineb} add column trendline draw trendline on plot close
]



push5280
201 posts
msg #158446
Ignore push5280
modified
1/23/2022 6:51:37 PM

I think I have the IF, ELSEIF,ELSE part figured out but I'm at what I think is the last line and it breaks.

I think my logic is correct in the IF, ELSEIF, ELSE parts but I need some help from SF coders who are better than me.
Any help is appreciated!



/*1)avrTR = weightedaverage[Length](AverageTrueRange[1](close))
2)highestC = highest[Length](high)
3)lowestC = lowest[Length](low)
4)hiLimit = highestC[1]-(avrTR[1]*Multiplier)
5)lolimit = lowestC[1]+(avrTR[1]*Multiplier)
6)if(close > hiLimit AND close > loLimit) THEN
7) ret = hiLimit
8)ELSIF (close < loLimit AND close < hiLimit) THEN
9) ret = loLimit
10)ELSE
11) ret = ret[1]
12)ENDIF
13)RETURN ret coloured(238,238,0) as "Trend Trader"*/
Fetcher[
/*avrTR = weightedaverage[Length](AverageTrueRange[1](close))*/
set{avrTR_multiplier, Weighted ATR(21) 1 day ago * 3}
draw avrTR_multiplier
/* highestC = highest[Length](high) */
set{highestC, close 21 day high}
draw highestC
/* lowestC = lowest[Length](low) */
set{lowestC, close 21 day low}
draw lowestC
/* hiLimit = highestC[1]-(avrTR[1]*Multiplier)*/
set{hiLimit, close 21 day high 1 day ago - avrTR_multiplier}
draw hiLimit
/*lolimit = lowestC[1]+(avrTR[1]*Multiplier) */
set{loLimit, close 21 day low 1 day ago + avrTR_multiplier}
draw loLimit
/* if(close > hiLimit AND close > loLimit) */
/* we need to find if this condition is satisfied */
set{if_1, count(close > hiLimit, 1)}
set{if_2, count(close > loLimit, 1)}
set{if_3, if_1 + if_2}
set{if_3_count, count(if_3 > 1, 1)}
draw if_3_count
/*ELSIF (close < loLimit AND close < hiLimit) */
/* we need to find if this condition is satisfied */
set{elseif_1, count(close < loLimit, 1)}
set{elseif_2, count(close < hiLimit, 1)}
set{elseif_3, elseif_1 + elseif_2}
set{elseif_3_count, count(elseif_3 > 1,1)}
draw elseif_3_count
/*ELSE */
/* we need to find if this condition is satisfied */
set{else_1, if_3_count + elseif_3_count}
set{else_1_count, count(else_1 < 1, 1)}
draw else_1_count

/* set the values for TrendTrader Indicator calculations */
set{hiLimit_val, hiLimit * if_3_count}
set{loLimit_val, loLimit * elseif_3_count}
draw hiLimit_val
draw loLimit_val
set{lolimit_1, loLimit_val 1 day ago}
draw lolimit_1 on plot loLimit
/*set{hilimit_1, hiLimit_val 1 day ago}
draw hilimit_1 on plot hiLimit */
set{HandL_val, hilimit_1 + lolimit_1 }
add column HandL_val
draw HandL_val
set{handl_1, HandL_val 1 day ago}
draw handl_1
set{return_val, else_1_count * handl_1}
draw return_val


close > 1
]

nibor100
1,046 posts
msg #158456
Ignore nibor100
1/24/2022 12:37:07 PM

@push5280,

Below is the most of your filter that I get to work before it runs into a SF too complex to run issue at the line "add column handl_val 1 day ago " due to more levels of set variable nesting that SF will allow for a filter to run.

Normally to get around this one combines statements or actions where possible to reduce the number of set statements relying on a prior set variable.

However, offhand I don't see any easy changes to make it work....
Ed S.

PS. if you want to have your posted filters be clickable in SF you have to get rid of all of the bracket symbols i.e. " [ "," ] " in your comment lines as those symbols are reserved for the SF clickable command '
Fetcher[ .... ]

'

Fetcher[
/*1)avrTR = weightedaverage(AverageTrueRange<1>(close))
2)highestC = highest(high)
3)lowestC = lowest(low)
4)hiLimit = highestC<1>-(avrTR<1>*Multiplier)
5)lolimit = lowestC<1>+(avrTR<1>*Multiplier)
6)if(close > hiLimit AND close > loLimit) THEN
7) ret = hiLimit
8)ELSIF (close < loLimit AND close < hiLimit) THEN
9) ret = loLimit
10)ELSE
11) ret = ret<1>
12)ENDIF
13)RETURN ret coloured(238,238,0) as "Trend Trader"*/

/*avrTR = weightedaverage(AverageTrueRange<1>(close))*/
set{avrTR_multiplier, Weighted ATR(21) 1 day ago * 3}
draw avrTR_multiplier
/* highestC = highest(high) */
set{highestC, close 21 day high}
draw highestC
/* lowestC = lowest(low) */
set{lowestC, close 21 day low}
draw lowestC
/* hiLimit = highestC<1>-(avrTR<1>*Multiplier)*/
set{hiLimit, close 21 day high 1 day ago - avrTR_multiplier}
draw hiLimit
/*lolimit = lowestC<1>+(avrTR<1>*Multiplier) */
set{loLimit, close 21 day low 1 day ago + avrTR_multiplier}
draw loLimit
/* if(close > hiLimit AND close > loLimit) */
/* we need to find if this condition is satisfied */
set{if_1, count(close > hiLimit, 1)}
set{if_2, count(close > loLimit, 1)}
set{if_3, if_1 + if_2}
set{if_3_count, count(if_3 > 1, 1)}
draw if_3_count
/*ELSIF (close < loLimit AND close < hiLimit) */
/* we need to find if this condition is satisfied */
set{elseif_1, count(close < loLimit, 1)}
set{elseif_2, count(close < hiLimit, 1)}
set{elseif_3, elseif_1 + elseif_2}
set{elseif_3_count, count(elseif_3 > 1,1)}
draw elseif_3_count
/*ELSE */
/* we need to find if this condition is satisfied */
set{else_1, if_3_count + elseif_3_count}
set{else_1_count, count(else_1 < 1, 1)}
draw else_1_count

/* set the values for TrendTrader Indicator calculations */
set{hiLimit_val, hiLimit * if_3_count}
set{loLimit_val, loLimit * elseif_3_count}
draw hiLimit_val
draw loLimit_val
set{lolimit_1, loLimit_val 1 day ago}
draw lolimit_1 on plot loLimit
set{hilimit_1, hiLimit_val 1 day ago}
draw hilimit_1 on plot hiLimit
set{HandL_val, hilimit_1 + lolimit_1 }
add column hilimit_1 1 day ago
draw HandL_val
/*add column handl_val 1 day ago
set{handl_1, HandL_val 1 day ago}
draw handl_1
set{return_val, else_1_count * handl_1}
draw return_val*/


close > 1
]



push5280
201 posts
msg #158809
Ignore push5280
3/13/2022 11:36:01 PM

Nibor100,

"Below is the most of your filter that I get to work before it runs into a SF too complex to run issue at the line "add column handl_val 1 day ago " due to more levels of set variable nesting that SF will allow for a filter to run. "
*********************************************************************************************************
I have an Advanced Subscription, I thought that was supposed to eliminate these nesting issues?

What is Advanced Filter Support?

In short, Advanced Filter Support is related to the number of nested set{} statements or custom variables used within a StockFetcher filter. Once StockFetcher determines that a filter has reached this complexity, Advanced Filter Support is required to complete the filter. There is not a specified number of custom variables that flags a filter as "advanced". StockFetcher takes into consideration the complexity of the underlying measures, in addition to the number of variables.

At the standard subscription level, StockFetcher filters can certainly take advantage of custom variables; however, if your filter exceeds the complexity level required for an "advanced" filter, you will see a message indicating that the filter could not complete.

For nearly all filters, Advanced Filter Support is not required. Additionally, if you do experience this issue as a basic subscriber, typically there are work-arounds. If you are unable to find a work-around, you can upgrade your subscription at anytime to support the advanced filters.

Still need help?





nibor100
1,046 posts
msg #158814
Ignore nibor100
3/14/2022 11:16:17 AM

Advanced subscription allows us to run some filters that are too complex for basic subscription level but SF puts further complexity limits that advanced level can’t run.
Very annoying,
Ed S

StockFetcher Forums · Filter Exchange · Trend Trader Strategy<< >>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.