;ds36 by Dave Serbin 8/19/2006
;Combo of ds28 and ts22a


;ts22a.ini (fixed)
;by Josef Porinchak, 03/03/2005

;Signal generated is
;same as ts22 except for "no sell" filter being 5/21 Ema crossover
;of odmax.

[Expression]
BT = 100*Ema(nsnhq / (nsnhq + nsnlq), 8)
bthrust= Signal(bt -  85)      
WriteFile(bthrust, NSNH1, "NSNH1 Signal")
;WriteFile(FamAvg(Family(prcgx,prcgx,ucpix)),prhdg)
;WriteFile(all-eq FamAndNot bd-all FamAndNot cap-big,allnobd)
;Compute the difference between NS advancing issues and
;declining issues
NS_AD = (advq - declq) / 100
;Compute the NS advance decline summation
NS_Advance_Decline = Sum(NS_AD) + 500
;Compute modified McClellan oscillator and summation
NS_McClellan_Osc = 100 * (Ema(NS_AD, 21) - Ema(NS_AD, 34))
NS_McClellan_Sum = Sum(NS_McClellan_Osc) - 6639.9823
WriteFile(NS_Advance_Decline, nsad)
WriteFile(NS_McClellan_Osc, nsmco)
WriteFile(NS_McClellan_Sum, nsmcs)

;Compute nsmcs macd histogram
[Expression]
fund = nsmcs
shortma =  55
longma =   89
signalma = 21 
buylevel =  0
selllevel = 0
macd = Ema(fund, shortma) - Ema(fund, longma)
signalline = Ema(macd, signalma)
macdhisto = macd - signalline
macdsig.Buy = Signal(macdhisto - buylevel)
macdsig.Sell = Signal(macdhisto - selllevel)
WriteFile(macdsig, nsmcsmd, "")


;Compute pfgax ema crossover
fund = pfgax
pfema = Signal(Ema(fund,13) - Ema(fund,34)) 
WriteFile(pfema,pfema)
Delete(pfema)

;Compute pfgax macd histogram
shortma = 13
longma = 34
signalma = 8
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, "")
Delete(macdfib)

;Compute pfgax stochastic histogram
Average = 89
Smooth =  34
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")
Delete(stochfib)

;Construct 3Xpf11 sig  
3Xpfg.Buy = pfema And macdfib And stochfib
3Xpfg.Sell= pfema And macdfib And stochfib
WriteFile(3Xpfg, 3Xpf11,"Combo of ema and histogram sigs of pfgax")
Delete(3Xpfg)

;Compute hrtvx ema crossover
fund = hrtvx
hrema = Signal(Ema(fund,5) - Ema(fund,34))
WriteFile(hrema,hrema)
Delete(hrema)

;Compute hrtvx macd histogram
shortma = 34
longma = 55
signalma =13
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, "")
Delete(macdfib)

;Compute hrtvx stochastic histogram
Average = 55
Smooth =  34
Trigger = 21
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")
Delete(stochfib)

;Construct 3Xhrt sig  
3Xhrt.Buy = hrema And macdfib And stochfib
3Xhrt.Sell= hrema And macdfib And stochfib
WriteFile(3Xhrt, 3Xhrt,"Combo of ema and histogram sigs of hrtvx")
Delete(3Xhrt)

;Compute odmax ema crossover
fund = odmax
odema = Signal(Ema(fund,3) - Ema(fund,13))
WriteFile(odema,odema)
Delete(odema)

;Compute odmax macd histogram
shortma = 34
longma = 233
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, odmacd, "")
Delete(macdfib)

;Compute odmax stochastic histogram
Average = 34
Smooth =  13
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, odmsto, 
 "Stochastic Histogram")
Delete(stochfib)

;Construct 3Xodm sig  
3Xodm.Buy = odema And odmacd And odmsto
3Xodm.Sell= odema And odmacd And odmsto
WriteFile(3Xodm, 3Xodm,"Combo of ema and histogram sigs of odmax")
Delete(3Xodm)

;Construct odemc sig
WriteFile(Signal(Ema(odmax,5) - Ema(odmax,89)),odemc)

;Construct nspf11 sig
nspf11.Buy = nsnh1 
nspf11.Sell = nsnh1 And Not(3xpf11)
WriteFile(nspf11,nspf11, "Conf 1 of nsnh1 and reverse 3xpf11")
Delete(nspf11)

;Compute mmeyx stochastic histogram
fund = mmeyx
Average = 144
Smooth =  55
Trigger = 8
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")
WriteFile(stochfib,mmesto)
Delete(stochfib)


ts21.Buy = (3xhrt Or 3xodm) And mmesto 
ts21.Sell = 3xhrt Or 3xodm Or nspf11 Or nsmcsmd
WriteFile(ts21,ts21)
Delete(ts21)

ts22.Buy = (3xhrt Or 3xodm)  
ts22.Sell = 3xhrt Or 3xodm Or nspf11 Or nsmcsmd Or odemc
WriteFile(ts22,ts22)
Delete(ts22)

;Construct odemc sig
WriteFile(Signal(Ema(odmax,5) - Ema(odmax,21)),odeme)
ts22.Buy = (3xhrt Or 3xodm); And mmesto 
ts22.Sell = (3xhrt Or 3xodm Or nspf11 Or nsmcsmd Or odemc) And odeme
WriteFile(ts22,ts22a)
Delete(ts22)

fund = odmax
odema = Signal(Ema(fund,8) - Ema(fund,34))
WriteFile(odema,odema)

;Compute odmax macd histogram
shortma = 34
longma = 144
signalma = 13
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, "")

;Compute odmax stochastic histogram
Average = 144
Smooth =  55
Trigger = 8
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")

;Construct 3Xodm2 sig  
3Xodm2.Buy = odema And macdfib And stochfib
3Xodm2.Sell= odema And macdfib And stochfib
WriteFile(3Xodm2, 3Xodm2,"Combo of ema and histogram sigs of odmax")

;Construct ds28 sig
WriteFile(Signal(Ema(odmax,3) - Ema(odmax,89)),odemc)

combo.Buy = 3xodm2; Or (3xodm2 And Not(odemc))
combo.Sell = (3xodm2 Or odemc)
WriteFile(combo, ds28)

combo.Buy = ds28
combo.Sell = ts22a Or ds28
WriteFile(combo, ds36)

SumNL = 58
DS36a.Buy = combo
DS36a.Sell = combo And Signal(SumNL - Ema(nsnlq+$nynl, 19))
DS36a.Sell = DS36a And BTCOMBO
WriteFile (DS36a, DS36a, "DS36 with no sell conditions")


[SignalPairTrade]
Fund = mmeyx
Index = mucax
StartDate = 1/3/97
Signal = ds36
HoldMinDays = 60
;HistoryDays=1
FnuFile = mme36

[SignalPairTrade]
Fund = mmeyx
Index = mucax
StartDate = 1/3/97
Signal = ds36a
HoldMinDays = 60
;HistoryDays=1
FnuFile = mme36

[SignalPairTrade]
Fund = odmax
Index = ousgx
StartDate = 1/3/97
Signal = ds36
HoldMinDays = 30
;HistoryDays=1
FnuFile = ods36

[SignalPairTrade]
Fund = odmax
Index = ousgx
StartDate = 1/3/97
Signal = ds36a
HoldMinDays = 30
;HistoryDays=1
FnuFile = ods36

[Expression]
WriteFile(FamAvg(Family(ods36,ods36,mme36)),mix36)
emafam = Family (mme36,ods36,mix36)
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")
fund = ods36
mdays = Sum(fund/fund)
peak = Max(fund, mdays)
cdd = (peak - fund)/peak
Print(cdd*100, "%DD ods36")
Print(ts22a, "ts22a")
Print(ds28, "ds28 (Combo sig for odmax)")
Print(ds36,"ds36 (Combo of ts22a and ds28)")