;       fubar5x7.ini 
;	Tom Tsao
;	12/03/05

;MMCFSig.ini...5/28/06...dab
;tweaked 7 parameters..05/01/06..dab
;eliminated bearx..05/28/06..dab

;	//IO:	Fitness: (car*.99^trades)/mdd
;	//IO:	SenOptGoalPct: 85
;	//IO:	FitnessTime: 900
;	dates:  01/05/96 to 11/07/05
;	trading dfscx
;
;	result #1: Ann: 31.7 Cdd: 18.3; generations: 204; fitness: 2.951 (trading mmcfx)
;	result #2: Ann: 32.9 Cdd: 16.4; generations: 219; fitness: 2.948 (trading mmcfx)

[Expression]

PcntChg = -2.7

;;mmcfx = Edit(Shift(mmcfx, -1), 12/31/10, Last(mmcfx) * (1 + PcntChg/100))

;;chartdays       = 500
;;mday            = Sum(Irate(0)/Irate(0))
;;editday         = Last(mday - 1 - chartdays)

RsiFund         = RUT-I  
RsiStop         = 33 ;32                      ;dab chg
RsiDays         = 14 ;29                      ;dab chg

bt_level        = 85 ;83                      ;dab chg
bt_period       = 10 ;42                      ;dab chg

;bearx used for buys only.

;Compute ema crossovers

fastma1         = 30 ;33;                     ;dab chg
deltama1        = 37                  
slowma1		= fastma1 + deltama1

fastma2         = 04
deltama2        = 08
slowma2	= 	fastma2 + deltama2

fastma3         =  0 ;29;                   ;dab chg
deltama3        =  0 ;212;                  ;dab chg
slowma3		= fastma3 + deltama3
                                        
fusema.Buy 	= Signal(Ema(mmcfx,fastma1) - Ema(mmcfx,slowma1)) 
fusemc.Sell 	= Signal(Ema(mmcfx,fastma2) - Ema(mmcfx,slowma2)) 

fuseme.Buy      = Signal(Ema(mmcfx,fastma3))  ; - Ema(mmcfx,slowma3))

;WriteFile(fusema, fusema)
;WriteFile(fusemc, fusemc)
;WriteFile(fuseme, fuseme)

;Compute mmcfx macd histogram 
fund 		= mmcfx
shortma         = 20
longma          = 82
signalma        = 22
buylevel 	= 0
selllevel 	= 0
macd 		= Ema(fund, shortma) - Ema(fund, longma)
signalline 	= Ema(macd, signalma)
macdhisto 	= macd - signalline
mhf 		= macdhisto
macdsig.Buy 	= Signal(macdhisto - buylevel)
macdsig.Sell 	= Signal(macdhisto - selllevel)

emamacd.Buy     = macdsig Or (fusemc And macdsig) ; added by TT on 7/14/05
emamacd.Sell	= fusemc Or macdsig
;WriteFile(macdsig, macdsig)
;WriteFile(emamacd, emamacd)

;Compute mmcfx stochastic histogram
fund 		= mmcfx
Average         = 66
Smooth          = 8  ;09                  ;dab chg
Trigger         = 96
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   
histof 		= histogram
buystate 	= (histogram - Buyvalue) And (Buyvalue - Shift(histogram, 1))
sellstate 	= (Sellvalue - histogram) And (Shift(histogram, 1) - Sellvalue)

stochsig.Buy 	= Signal(buystate)
stochsig.Sell 	= Signal(-sellstate)

;Compute bearx stochastic histogram
fund            = Warp(rut-i, -1, 0) 
Average         = 80                       ;dab chg
Smooth          = 13                       ;dab chg
Trigger         = 18                       ;dab chg
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   
histob 		= histogram
buystate 	= (histogram - Buyvalue) And (Buyvalue - Shift(histogram, 1))
sellstate 	= (Sellvalue - histogram) And (Shift(histogram, 1) - Sellvalue)

brxsto.Buy 	= Signal(buystate)
brxsto.Sell 	= Signal(-sellstate)

;Construct fubar5 sig
;--------------------
                                      
fubar5.Buy	= emamacd And Not(brxsto)  Or (fusema And fuseme)

fubar5.Sell	= fusemc And stochsig

fubar5.Sell 	= fubar5 And Signal(Ema(100*nsnhq/(nsnhq+nsnlq), bt_period) - bt_level)

fubar5.Sell 	= fubar5 Or Signal(Rsi(rsifund,rsidays) - rsistop)

;fund = rut-i
;stoploss = 3.8
;days =     1
;cdd = 100*(Max(fund, days+1) - fund) / Max(fund, days+1)
;Print(-cdd, "1 mDay Cdd\nStopLoss = -3.8%\n")

;fubar5.Sell = fubar5 Or Signal(stoploss - cdd)

fubar5.Sell = Stretch(fubar5, 13) 


WriteFile(fubar5, MMCFSig, "(Combo of mmcfx and r-rut histograms from fubar5x)")

Print(
      	emamacd,  	" mmcfx EmaMacd ",
        brxsto,         " r-rut StochSig",
	stochsig, 	" mmcfx StochSig"
)
Print(
;;        fubar5x,        " Fubar5x  Signal",
        mmcfsig,         "  MMCFSig Signal"
)

Print(
"	**********************************************************************	 
	 Buy on: emamacd (mmcfx macdH) and Not(brxsto) Or (fusema And fuseme)\n
        Sell on: fusemc and mmcfx Stoch Histo And NSNH<85 Or Rsi14 of rut-i<33
	**********************************************************************"
)

Print(
	mmcfx, 						"mmcfx Price",
     	mmcfx - Shift(mmcfx, 1), 			"mmcfx PtChg\n",
        rut-i,                                          "RUT-I Price",
        rut-i - Shift(rut-i, 1),                        "RUT-I PtChg\n",
     	mhf, 						"mmcfx Macd Histogram",
        histob,                                         "R-RUT Stoch Histogram",
	Ema(mmcfx,fastma1) - Ema(mmcfx,slowma1), 	"FUSEMA",
	Ema(mmcfx,fastma3) - Ema(mmcfx,slowma3),	"FUSEME\n",
     	Ema(mmcfx,fastma2) - Ema(mmcfx,slowma2), 	"FUSEMC",
     	histof, 					"mmcfx Stoch Histogram\n",
        Ema(100*nsnhq/(nsnhq+nsnlq),bt_period),         "NSNHOsc, NoSell > 85\n",
        Rsi(rsifund, rsidays),                          "RUT Rsi14\nStoploss < 33\n",
        Days(mmcfsig),                                  "MktDays this Signal\nHoldMin = 13 MktDays")


[SignalPairTrade]

Delay           = 1
Fund            = RYOTX;RYMCX;PRCGX;DFSCX ;FKASX ;RCMCX ;gssmx ;tavfx ;dfscx
Index           = FDRXX
Signal          = MMCFSig  ;fub5x7
;Signal        = rutmc2x
StartDate       = 1/3/95
;;StartDate       = 7/6/94 ;ok to here
HoldMinDays     = 20 ;Iterate(1..30) ;1 or 20
;;HistoryDays     = 252
FnuFile         = MM01

[SignalPairTrade]
Signal = mmcfsig
Fund = MM01
Index = MM01
StartDate = 12/30/05
HistoryDays = 0
FnuFile = MM02

[Expression]

F = MM02
Print(-100*(Max(f,Sum(f/f)) - f)/ Max(f,Sum(f/f)), "Current %DD\n",
MM02/10 - 100, "YTD %Chg\n", 
100*Roc(f,1), "1d %Chg",
100*Roc(f,5), "5d %Chg",
100*Roc(f,21), "1mo %Chg",
100*Roc(f,63), "3mo %Chg",
100*Roc(f,126), "6mo %Chg",
100*Roc(f,189), "9mo %Chg",
100*Roc(f,252), "1yr %Ann",
100*(Pow((Roc(f,504) + 1), 1/2) - 1), "2yr %Ann", 
100*(Pow((Roc(f,756) + 1), 1/3) - 1), "3yr %Ann",
100*(Pow((Roc(f,1260) + 1), 1/5) - 1), "5yr %Ann",
100*(Pow((Roc(f,2772) + 1), 1/11) - 1), "11yr %Ann")

 Print(mmcfsig, "MMCFSig Signal")