Gary, and others ...
I am trying to write a scan which can tell me when a security has reached a certain level. In the following scan I am trying to find when the close bar made a max and/or a min for a selected list of symbols.
// ---- WhenMinMax scan Input = "SBP.lst"; Output = "WhenMaxMin.lst"; Integer d, e, mindate, maxdate; Float maxbar, minbar; for d = -20 to -2 step 1 do if cci(d) < -100 and cci(d) > -999999.00 and cci(d) > cci(d-1) then maxbar := max(0, d+2, cl); minbar := min(0, d+2, cl); mindate := d; maxdate := d; for e = d to 0 step 1 do if close(d) >= maxbar then maxdate := e; e := 0; endif; if close(d) <= minbar then mindate := e; e := 0; endif; next e; println symbol, ",", date(d), ",", d, ",", open(d+1):8:2, ",", date(maxdate), ",", max(0,d+2,cl), ",", maxbar, ",", max(0,d+2,cl)/open(d+1):5:2, ",", date(mindate), ",", minbar, ",", min(0,d+2,cl), ",", min(0,d+2,cl)/open(d+1):5:2; endif; next d; // --- end WhenMinMax scan
While running this, mindate and maxdate are never initialized with another value than d, so the conditions (close >= maxbar and close <= minbar) are never met, although the for ... next must come accross such a value. It seems impossible to store the result of a max/min statement and find out when this value was reached.
Does anyone know of a way to make this work with QP2 ?
Alain Joaris |