[Expression]
;Sob1.ini by Dave Serbin 09/04/2007
;This is a first stab at the SerbinBurger Oracle Bellwether Omen.
;As a stand alone "omen" it makes a lousey sig, but may give some
;heads up on market reversals. It's a strict combination of two
;sigs...3xnsl, which is based on Nasdaq new lows and
;3xadv, based on Nasdaq advancing issues.

;Compute advq ema crossover
fund = advq
advema = Signal(Ema(fund,21) - Ema(fund,377))
WriteFile(advema,advema)

;Compute advq macd histogram
shortma = 89
longma = 377
signalma = 34
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 advq stochastic histogram
Average = 377
Smooth =  89
Trigger = 55
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 3xadv sig  
WriteFile(advema And macdfib And stochfib,3xadv)

;Compute nsnlq ema crossover
fund = nsnlq
nslema = Signal(Ema(fund,13) - Ema(fund,144))
WriteFile(nslema,nslema)

;Compute nsnlq macd histogram
shortma = 55
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, macdfib, "")

;Compute nsnlq stochastic histogram
Average = 233
Smooth =  55
Trigger = 34
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 3xnsl sig  
WriteFile(Not(nslema And macdfib And stochfib),3xnsl)

;Construct sob1 Omen
WriteFile(3xadv And 3xnsl,sob1)

[SignalPairTrade]
Fund = ryotx
Index = vmfxx
StartDate = 1/1/02
Signal = sob1
;HoldMinDays = 10
;HistoryDays=1
FnuFile = rsob1

[Expression]
emafam = Family(rsob1)
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*ui, "UI", 100*ann, "AnnRet",
mdays, "MDays")
x = 0.01
cddx = ((peak - fund)/peak) - x 
cdd = (Pow(Pow(cddx,2),0.5) + cddx)/2 
ui = Last(Pow(Sum(Pow(cdd, 2))/mdays, .5))
ann = Pow(10, Log(Last(fund)/First(fund))/(Last(mdays)/252.6))-1
upi1 = (ann - .054)/ui
x = 0.02
cddx = ((peak - fund)/peak) - x 
cdd = (Pow(Pow(cddx,2),0.5) + cddx)/2 
ui = Last(Pow(Sum(Pow(cdd, 2))/mdays, .5))
ann = Pow(10, Log(Last(fund)/First(fund))/(Last(mdays)/252.6))-1
upi2 = (ann - .054)/ui
x = 0.03
cddx = ((peak - fund)/peak) - x 
cdd = (Pow(Pow(cddx,2),0.5) + cddx)/2 
ui = Last(Pow(Sum(Pow(cdd , 2))/mdays, .5))
ann = Pow(10, Log(Last(fund)/First(fund))/(Last(mdays)/252.6))-1
upi3 = (ann - .054)/ui
x = 0.04
cddx = ((peak - fund)/peak) - x 
cdd = (Pow(Pow(cddx,2),0.5) + cddx)/2 
ui = Last(Pow(Sum(Pow(cdd , 2))/mdays, .5))
ann = Pow(10, Log(Last(fund)/First(fund))/(Last(mdays)/252.6))-1
upi4 = (ann - .054)/ui
x = 0.05
cddx = ((peak - fund)/peak) - x 
cdd = (Pow(Pow(cddx,2),0.5) + cddx)/2 
ui = Last(Pow(Sum(Pow(cdd , 2))/mdays, .5))
ann = Pow(10, Log(Last(fund)/First(fund))/(Last(mdays)/252.6))-1
upi5 = (ann - .054)/ui

FamPrint (Sort (upi1),"UPI1",(upi2),"UPI2",(upi3),"UPI3",
(upi4),"UPI4",(upi5),"UPI5")
fund = rsob1
mdays = Sum(fund/fund)
peak = Max(fund, mdays)
cdd = (peak - fund)/peak
Print (cdd*100, "%DD of roytx")
Print("UPI is the standard calc. UPI1 is UPI when 1% drawdowns are ignored,
UPI2 ignores 2% drawdowns, etc.")

Print(3xnsl, "3xnsl")
Print(3xadv, "3xadv")
Print(sob1, "sob1 (strict combo of 3xnsl and 3xadv)")