!WEEKLY & DAILY MACD !Author: Vitali Apirine, TASC Dec 2017 !Coded by: Richard Denning 10/13/17 !www.TradersEdgeSystems.com !INPUTS: S is 12. L is 25. EMA1 is expavg([Close],S). EMA2 is expavg([Close],L). EMA3 is expavg([Close],S*5). EMA4 is expavg([Close],L*5). MACD is EMA1 - EMA2. MACDW is EMA3 - EMA4. rdMACD is MACD + MACDW.
Category Archives: Stocks & Commodities traders tips
System Development Using Artificial Intelligence
Are humans or computers better at trading? This question has been around on many fronts since the era of punch cards, and as technology advances, you question whether machines have limits. It’s the same with trading, and here’s an algorithm that may shed some light on which performs better…
!ARTIFICAL INTELLIGENCE FOR SYSTEM DEVELOPMENT !Authors: Domenico D'Errico & Giovanni Trombetta, TASC August 2017 !Coded by: Richard Denning, 6/08/2017 !www.TradersEdgeSystems.com !INPUTS: O is [open]. C is [close]. H is [high]. L is [low]. exitBars is 8. exitBarsP is 6. enterGap is -0.08. !CODE: AvgP is (O+C+H+L)/4. MedP is (H+L)/2. MedB is (O+C)/2. AvgP1 is valresult(AvgP,1). AvgP2 is valresult(AvgP,2). AvgP3 is valresult(AvgP,3). MedP1 is valresult(MedP,1). MedP2 is valresult(MedP,2). MedP3 is valresult(MedP,3). MedP4 is valresult(MedP,4). MedB1 is valresult(MedB,1). MedB2 is valresult(MedB,2). MedB3 is valresult(MedB,3). MedB4 is valresult(MedB,4). !ENTRY & EXIT RULESl Gandalf if (AvgP1exitBars-1) or ({position days}>=exitBars-1) or ({position days}>=exitBarsP-1 and (C-{position entry price}>0)). EntryPr is min(val([low],1) + enterGap,[open]). Buy if Gandalf and [low] <= EntryPr.
Detecting Swings
The AIQ code based on Domenico D’Errico’s article in the May 2017 issue of Stoks Commodities, “Detecting Swings,” is provided below.
I tested the author’s four systems using the NASDAQ 100 list of stocks on weekly bars, as did the author, from 3/16/2005 through 3/14/2017. Figure 7 shows the comparative metrics of the four systems using the four-week exit. The results were quite different than the author’s, probably due to a different test portfolio and also a 10-year test period rather than the author’s 20-year period. In addition, my test results show longs only, whereas the author’s results are the average of both the longs and shorts.
The Bollinger Band (Buy2) system showed the worst results, whereas the author’s results showed the Bollinger Band system as the best. The pivot system (Buy1) showed the best results, whereas the author’s results showed the pivot system as the worst. I am not showing here the comparative test results for the Sell1 thru Sell4 rules, as all showed an average loss over this test period.
!DECTECTING SWINGS !Author: Domenico D'Errico, TASC May 2017 !Coded by: Richard Denning, 3/15/17 !www.TradersEdgeSystems.com !Set to WEEKLY in properties Low is [low]. Low1 is valresult(Low,1). Low2 is valresult(Low,2). High is [high]. High1 is valresult(High,1). High2 is valresult(High,2). PivotLow if Low1 < Low2 and Low1 < Low. PivotHigh if High1 > High2 and High1 > High. Buy1 if PivotLow. Sell1 if PivotHigh. !Set parameter for bollinger bands to 12 with 2 sigma (weekly) in charts: Buy2 if [close] > [Lower BB] and valrule([close] <= [Lower BB],1). Sell2 if [close] < [Upper BB] and valrule([close] >= [Upper BB],1). !Set parameter for Wilder RSI to 5 (weekly) in charts: Buy3 if [RSI Wilder] > 40 and valrule([RSI Wilder] <= 40,1). Sell3 if [RSI Wilder] < 60 and valrule([RSI Wilder] >= 60,1). Buy4 if [RSI Wilder] < 40 And Low > Low1. Sell4 if [RSI Wilder] > 60 And High < High1. Exit if {position days} >= 4.
Exponential Standard Deviation Bands
The AIQ code based on Vitali Apirine’s article in the 2017 issue of Stocks & Commodities magazine, “Exponential Standard Deviation Bands”
Editor note: “Author Vitali Apirine presented a method intended to help traders see volatility while a stock is trending. These bands, while similar to Bollinger Bands, are calculated using exponential moving averages rather than simple moving averages. Like Bollinger Bands, they widen when volatility increases and narrow as volatility decreases. He suggests that the indicator can be used as a confirming indication along with other indicators such as the ADX. Here’s an AIQ Chart with the Upper, Lower and Middle Exponential SD added as custom indicators.”
- Buy when there is an uptrend and the close crosses over the upper band. An uptrend is in place when the middle band is higher than it was one bar ago.
- Sell when the low is less than the lower band.
and is also shown here:
!Author: Vitali Apirine, TASC February 2017
!Coded by: Richard Denning 12/11/2016
!www.TradersEdgeSystems.com!INPUT:
xlen is 20.
numSD is 2.
!INDICATOR CODE:
ExpAvg is expavg([close],xlen).
Dev is [close] – ExpAvg.
DevSqr is Dev*Dev.
SumSqr is sum(DevSqr,xlen).
AvgSumSqr is SumSqr / xlen.
ExpSD is sqrt(AvgSumSqr).
!UPPER EXPONENTIAL SD BAND:
UpExpSD is ExpAvg + numSD*ExpSD. !PLOT ON CHART
!LOWER EXPONENTIAL SD BAND:
DnExpSD is ExpAvg – numSD*ExpSD. !PLOT ON CHART
!MIDDLE EXPONENTIAL SD BAND:
MidExpSD is ExpAvg.
!BOLLINGER BANDS FOR COMPARISON:
DnBB is [Lower BB]. !Lower Bollinger Band
UpBB is [Upper BB]. !Upper Bollinger Band
MidBB is simpleavg([close],xlen). !Middle Bollinger Band
!REPORT RULE TO DISPLAY VALUES:
ShowValures if 1.
!TRADING SYSTEM USING EXPPONENTIAL SD BANDS:
UpTrend if MidExpSD > valresult(MidExpSD,1).
BreakUp if [close] > UpExpSD.
BuyExpSD if UpTrend and BreakUp and valrule(Breakup=0,1).
ExitExpSD if [Low] < DnExpSD. ! or UpTrend=0.
!TRADING SYSTEM USING BOLLINGER BANDS:
UpTrendBB if MidBB > valresult(MidBB,1).
BreakUpBB if [close] > UpBB.
BuyBB if UpTrendBB and BreakUpBB and valrule(BreakupBB=0,1).
ExitBB if [Low] < DnBB. ! or UpTrend=0.
Zero In On The MACD
! ZERO IN ON THE MACD ! Author: Barbara Star, TASC May 2016 ! Coded by: Richard Denning 3/14/16 ! www.TradersEdgeSystems.com ! INPUTS: macd1 is 12. macd2 is 26. macdSig is 1. ! INDICATORS: emaST is expavg([Close],macd1). emaLT is expavg([Close],macd2). MACD is emaST - emaLT. ! MACD line SigMACD is expavg(MACD,macdSig). ! MACD Signal line MACDosc is MACD - SigMACD. ! MACD Oscillator HD if hasdatafor(macd2) = macd2. MACDhist is MACD. ! plot as historigram MACDblue if MACDhist > 0. ! use these rules to color MACDhist MACDred if MACDhist < 0. ! use these rules to color MACDhist MACDcolor is iff(MACDblue and HD,"Blue",iff(MACDred and HD,"Red","White")). !for report list List if 1. !ALERTS: EMA1 is expavg([close],34). EMA2 is expavg([close],55). xupEMA1 if [close] > EMA1 and valrule([close] < EMA1,1). xdnEMA1 if [close] < EMA1 and valrule([close] > EMA1,1). xupEMA2 if [close] > EMA2 and valrule([close] < EMA2,1). xdnEMA2 if [close] < EMA2 and valrule([close] > EMA2,1). xupMACD if MACDhist > 0 and valrule(MACDhist < 0,1). xdnMACD if MACDhist < 0 and valrule(MACDhist > 0,1). UpAlerts is iff(xupEMA1,"xupEMA1",iff(xupEMA2,"xupEMA2",iff(xupMACD,"xupMACD"," "))). DnAlerts is iff(xdnEMA1,"xdnEMA1",iff(xdnEMA2,"xdnEMA2",iff(xdnMACD,"xdnMACD"," "))).