SI
SI
discoversearch

We've detected that you're using an ad content blocking browser plug-in or feature. Ads provide a critical source of revenue to the continued operation of Silicon Investor.  We ask that you disable ad blocking while on Silicon Investor in the best interests of our community.  If you are not using an ad blocker but are still receiving this message, make sure your browser's tracking protection is set to the 'standard' level.
Strategies & Market Trends : TA-Quotes Plus -- Ignore unavailable to you. Want to Upgrade?


To: Craig DeHaan who wrote (7289)10/20/1998 5:22:00 PM
From: Nine_USA  Read Replies (1) | Respond to of 11149
 
Craig,

<<a more elegant way to avoid divide by zero errors caused by NegMF summation in MRatio other than my rig-o-rama>>

Financial models should replace the divide functions provided by
their programming language with an alternate divide which
will test for zero denominators and return 0 in such cases.

I doubt if there are many customers here who would prefer scans
to crash rather than use the 0 result in such cases.



To: Craig DeHaan who wrote (7289)10/20/1998 8:12:00 PM
From: Bob Jagow  Read Replies (2) | Respond to of 11149
 
That's not Wilder's RSI on Vol, Craig, but it guess it doesn't matter as long as Equis blessed it.
Re the div by0, its probably safe to do as they did -- simply ignore the possibility of NegMF being zero because its rather unlikely that the vol won't increase for 14 consecutive days.
Might want to file away for another time the workaround that follows -Bob
----------------------
print symbol,",",close(0):8:2;
if NegMF < .0001 then
MFI:= 100-100/(1+PosMF/.0001);
print ",","MFI is < ",MFI;
else
MRatio:=PosMF/NegMF;
MFI:=100- 100/(1+MRatio);
print",","MFI: ",MFI:8:4;
endif;
println ",",PosMF:8:4,",",NegMF:8:4;



To: Craig DeHaan who wrote (7289)10/21/1998 3:07:00 AM
From: Bob Jagow  Read Replies (1) | Respond to of 11149
 
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;