[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Color on Histogram solution comments



PureBytes Links

Trading Reference Links

Dans un courrier daté du 07/11/98 13:13:25 Heure d1iver Pari25 Madrid,
he96@xxxxxxxxxxxxxx a écrit :

> 
>  Pierre, thanks very much for some of the last posts with intersting lessons
> in EL  and TS - good thing that we have solved the Y2k patch problem
discussion, 
> with  OR finally coming out of the woods and giving us a rest till next
summer.
>  

I hope so.
Discussing EL isues on Omega List could also be of inerest to some readers,
that we may not forget.

>  
>  PO ecrit on some date somewhere in Paris: (free translation from
AOLfrench):
>  > When updating every tick, TS calculates and plot the considered value
like
>  > if the last tick of the "underconstruction bar" was closed with a close
>  > value that is precisely the last tick value. The above  quoted statement
>  > is true  only for systems ( where update every tick is impossible)
>  > 
>  > No need of  global variable DLL or repainting with the background color.
>  > Suffice to think on how TS works: The code is executed from top to end.
>  > The idea it to plot ( plot1 and 2) first with a zero value. Then plot
>  > again  (plot1 and 2) the colored histogram with the real value MACDD that
>  > will be updated on every tick, and that will plot over a 0 amplitude
>  > histogram ( e.g on a clear background).
>  > 
>  > Here is the  TS code:
>  > 
>  > {
>  > MaxBarsBack set to 1 ( yes!)
>  
>  Is that a MUST here ?
>  
It's not a must, but a hint.
Keeping MBBack to a minimum value speeds up the code ( Ts do not have to carry
from bar to bar a MBB window with previous values that will never be used).
Considering that MACDD  uses only Xaverages, and that the advantage of them is
to use only the previous value of itself, no need to keep references before 1
bar from currentbar.

>  
>  > Plot1: green histogram
>  > plot2: red histogram
>  > }
>  > 
>  > Inputs: FastMA(12),SlowMA(26),MacdMA(9);
>  > 
>  >
value1=MACD(Close,FastMA,SlowMA)-(XAverage(MACD(Close,FastMA,SlowMA),MacdM
>  > A)); { Note that the MACD calculation here is not optimized for speed. It
>  > should be... }
>  
>  
>  Can you elaborate about the "need for speed optimization". What happens if 
> not   optimized ? As we all have "powerfull" pcs with lots of rams isnt it
simple 
> enough   to be done straight ?.....what happens with LARGE, heavy codes ?
Will it 
> delay   the display of the PRICE and the INDICATOR ? Something which allways
>  bugged me: If I have lots of pages open AND lots of indicators on lots of 
>  different symbols - DO I see everything "5 seconds" or so later than just 
> open a  single QUOTE PAGE ????
>  
As I challenged someone in a previous post about optimizing EL code, this was
a safeguard warning regarding to my own pretentious comments and to avoid any
remark: (Hi Pierre, your MACDD was El pig coded).
The above code caluculated MACD(Close,FastMA,SlowMA) two times , what is
uncecessary.
It was used like this because the Xaverage function do not accept variables as
inputs.
Enbedding the Xaverage of Xaverage solves for it, but it's not good
programming.

To solve this, we need to use the alternate Xaverage ( as provided  by Bob
Fulks or myself in some previous post).

{Xavg user funtion as a replacement of Xaverage
=================================}

inputs : Price(NumericSeries),Length(NumericSimple);
vars   : Factor(0),xavg0(0);

if Length + 1 <> 0 
then begin
	if CurrentBar <= 1 
	then begin
		XAvg0 = Price;
	end
	else  
		Factor = 2 / (Length + 1);
		XAvg0= Factor * Price + (1 - Factor) * XAvg0;
end;
xavg=xavg0;

{End of code}

Now, we can write a clever MACDD

Value0=xavg(close,FastMA)- xavg(close,SlowMA);  {This is MACD}
Value1= Value0-xavg(Value1,MacdMA);			    {This is MACDD}.

You will remark that we call THREE  Xavg functions in this code , instead of
FIVE in the original example ( each MACD function calls  Xaverage  TWO times).
The new  MACDD code sould bee faster in a 5/3 ratio. 	

This will be sensible whan you optimize trading systems.
The problem is not Ram size or CPU performance.
For a smple code like this one, the difference will not be noticeable as both
are very simple.
But when using larger code, this kind of optimization is very valuable.
The delay when realtime is not noticeable ,as TS updates the last bar only.
However, when opening a page where several codes like this one are present,
you may observe a noticeable difference in speed, because TS calclates on all
the available historical  data.
As a conclusion, faster PC cas  superficially solve such errors by hidding
them by mean of  brute speed, but it still remains CPU time wasting for
nothing in any case.


>   > plot1(0,"+");
>  > plot2(0,"-");     <======reset plot values to 0 before plotting  the
MACDD
>  > values ( erases last bar value)
>  > 
>  > if value1>value1[1] then begin
>  >  plot1(value1,"+");   <=========plots according to MACD climbing
>  >  end else begin
>  >  plot2(value1,"-");    <=========plots according to MACD falling
>  > end;
>  
>  1) I plot this a bit different (and thats how I understood the ORIGINAL 
> question) 
>  to see just a NEGATIVE or POSITIVE value better and clearer I plot:
>  
>  if value1 > 0 then begin   <== just plots if its ABOVE or BELOW
>  Plot1(value1,"+");
>  end else begin
>  plot2(value1,"-");
>  end;
>  
Yes, but it'snot the original question.
Your MACDD histogram will change colors whe above or below  zero.
The original question was  to change the color of the histogram when value1
was increasing or decreasing ( the reason why I use  a if value1>value1[1]
condition).

Your  if value1 > 0 then begin   <== just plots if its ABOVE or BELOW
Do not plot just if it's above or below.
First part of the statement plot if it's positive.
Second part plots if it's zero or negative.

If you really want to avoid this you need to add:

if value1 <> 0 then begin
 if value1 > 0 then begin   <== just plots if its ABOVE or BELOW
  Plot1(value1,"+");
  end else begin
  plot2(value1,"-");
  end;
end;

>  2) isnt MY stuff more difficult to get colours ok ? - its weekend and I
cant 
> test   REALTIME :-(((

First, you will not have the same color change (see above).
Second, you will probably exerience  repainting problems when updating every
tick.
I think that uou will need the dual plot repainting technique.

>  
>  3) Also Im suprised about using the plot statements twice - havent read
that 
> in   OMEGA manual (have I ever read it ? <g>) - is that "common practice" ?
>  

It's not provided in the manual.
When I' faced to a problem like this, I try the idea ( provided that I have
one).
Either its accepted by EL, and after verification, and  I store it in my own
EL manual addendum.
Or I forget the  proven dummy solution ( that I store into a separate EL
manual).

>  4) THANKS
>  rgds hans
>  

4 bis:
You're welcome

Sincerely,

-Pierre Orphelin   

Most of this kind of concepts should be now  familiar to TS EXPRESS readers.
A good chance to visit Bill Brower (Editor) web site:
<A HREF="http://www.insideedgesystems.com";>http://www.insideedgesystems.com
</A>