;ts6.ini Josef Porinchak 31/7/04
;This is a combination signal using an average of funds.

[Expression]
WriteFile(FamAvg(Family(rylpx,tcsvx,mmcfx,prsvx,aemgx,sksex,pennx,hrtvx,
odmax,odmax,odmax,prcgx,mmeyx,gemax,gemax,ryotx)), smavg)

;Compute smavg ema crossover
fund = smavg
smema = Signal(Ema(fund,3) - Ema(fund,21))
Print ((Ema(fund,3) - Ema(fund,21)), "Crossover in ts6")
WriteFile(smema,smema)

;Compute smavg macd histogram
shortma = 34
longma = 144
signalma = 21
buylevel =  0
selllevel = 0
macd = Ema(fund, shortma) - Ema(fund, longma)
signalline = Ema(macd, signalma)
macdhisto = macd - signalline
macdfib.Buy = Signal(macdhisto - buylevel)
macdfib.Sell = Signal(macdhisto - selllevel)
WriteFile(macdfib, macdfib, "")
Print (macdhisto, "macdhisto in ts6")
;Delete (macdefib)

;Compute smavg stochastic histogram
Average = 144
Smooth =  21
Trigger = 13
Buyvalue = 0
Sellvalue = 0
stoch = 100 * (fund - Min(fund, Average)) /
 (Max(fund, Average) - Min(fund, Average))
stoch = Ema(stoch, Smooth) 
average = Ema(stoch, Trigger)  
histogram = stoch - average   
buystate = (histogram - Buyvalue) 
 And (Buyvalue - Shift(histogram, 1))
sellstate = (Sellvalue - histogram) 
 And (Shift(histogram, 1) - Sellvalue)
stochfib.Buy = Signal(buystate)
stochfib = Edit(stochfib, 9/1/88, Buy)
stochfib.Sell = Signal(-sellstate)
WriteFile(stochfib, stochfib, "Stochastic Histogram")
Print (histogram, "stochisto in ts6")
;Delete(stochfib)

;Construct ts6 sig  
ts6 = smema And macdfib And stochfib
ts6 = Edit(ts6, 9/1/88, Buy)
WriteFile(ts6, ts6,"Combo of ema and histogram sigs of smavg")
Print (smema, "smema in ts6")
Print (macdfib, "macdfib in ts6")
Print (stochfib, "stochfib in ts6")

[SignalPairTrade]
Fund = hrtvx
Index = vmfxx
StartDate = 1/20/98
Signal = ts6
HoldMinDays = 30
;HistoryDays=1
FnuFile = hrts6

[Expression]
emafam = Family (hrts6)
fund = emafam
mdays = Sum(fund/fund)
peak = Max(fund, mdays)
cdd = (peak - fund)/peak
ui = Last(Pow(Sum(Pow(cdd, 2))/mdays, .5))
ann = Pow(10, Log(Last(fund)/First(fund))/(Last(mdays)/252.6))-1
upi = (ann - .054)/ui
mdd = Last(Max(cdd, mdays))
FamPrint (Sort (upi),"UPI",(-100*mdd), "Mdd", 100*ann, "AnnRet",
mdays, "MDays")
Print(100*cdd, "%DD hrts6")
Print(ts6, "ts6 (smallcap avg sig)")