A final try at all 3, Craig. 1) Should have rearranged MFI from the start: MFI:= 100 -100/(1+NegMF/PosMF) = 100 -100*NegMF/(NegMF+PosMF); no div by 0 and calc may be faster -- see below.
2)diddling the for loop and stepping thru [as I suggested for tsf] would be a pain for SMA but great for EMA. See EMA code below.
3) Is okay but I changed it to ----------- typPr:= high(i)+low(i)+close(i); ptypPr:= high(i-1)+low(i-1)+close(i-1); if typPr < ptypPr then NegMF:= NegMF + typPr*vol(i)/3; endif; if typPr != ptypPr then Denom:= Denom + typPr*vol(i)/3; endif; ------------ for the rearranged MFI. [I'm more than ready to switch to the TF+ version ;)]: (V*((H+L+C)-TY1)U2*(H+L+C))F&1*100/(V*((H+L+C)-TY1)U1U0*(H+L+C))F&1 -Bob ------------- //--MoneyFlow Index-- // Change to eMFI to enable stepping thru a back test input = "250vol.lst"; output = "mfixx.lst"; issuetype common; integer i, lenMFI, bar, first, last; //add backtest vars float typPr, ptypPr, PosMF, NegMF, eMFI, peMFI, Denom; lenMFI:= 14; // Length of MFI EMA Set this to 27? ****** first:= 0; last:= 0; // Set these neg for BT ****** Daystoload = 1 +3*lenMFI -first; // should settle EMA down enough DaysRequired = 1 +3*lenMFI -first; // Now calc starting MFI PosMF:=0; NegMF:=0; Denom:= 0.0001; // precompile div by 0 for i = first - 3*lenMFI to first -1 do // could reduce 3 to 1.5 typPr:= high(i)+low(i)+close(i); ptypPr:= high(i-1)+low(i-1)+close(i-1); if typPr < ptypPr then NegMF:= NegMF + (typPr*vol(i)/3 -NegMF)*2/(lenMFI+1); endif; if typPr != ptypPr then Denom:= Denom + (typPr*vol(i)/3 -Denom)*2/(lenMFI+1); endif; //eATR:= eATR + (tr-eATR)*2/(lenATR+1); next i; peMFI:= 100 -100*NegMF/Denom; // Now into "Backtesting loop for bar = first to last do // now typPr:= high(bar)+low(bar)+close(bar); ptypPr:= high(bar-1)+low(bar-1)+close(bar-1); if typPr < ptypPr then NegMF:= NegMF + (typPr*vol(bar)/3 -NegMF)*2/(lenMFI+1); endif; if typPr != ptypPr then Denom:= Denom + (typPr*vol(bar)/3 -Denom)*2/(lenMFI+1); endif; eMFI:= 100 -100*NegMF/Denom; if eMFI > peMFI then println symbol,",",date(bar),",",close(Bar):8:2,",", peMFI:8:4,",",eMFI:8:4; endif; peMFI:= eMFI; // for next bar next bar; |