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

Re: Paint Bar code



PureBytes Links

Trading Reference Links

>     Does anyone know how to code a divergence signal for a Paint Bar
> on TS between  Stochastics and a bar chart on prices?  I'm trying to
> formulate a code that will paint the bar red when there is a bearish
> divergence and blue when there is a bullish divergence. 
>     I know this can be done. I'm just having trouble doing it.

It can be done.  It's just very messy.

You have to decide how you want to define your divergences.  Do 
the price and stoch have to peak on the same bar?  Probably not.  
Probably what you want to do is look at the peak values 
(SwingHigh or SwingLow) of price and stoch, and compare values 
that happen within a few bars.  So e.g. if you're running 5min 
bars, and the price peaks on one bar, maybe you use the value of 
stoch that peaks within 1-2 bars of the price peak.  Or maybe you 
use the stoch value on the bar where the price peaks.  Decide how 
you want to define the divergence and you're halfway there.

If you want to use the stoch value on the price-peak bar, then 
you just have to detect price peaks (using SwingHigh/Low), record 
the price and stoch value at that bar in an array so you can 
refer back a few swings (or maybe just in ThisSwing and LastSwing 
variables, if you only want to look back at the last two peaks), 
then compare the price values to the stoch values to detect your 
divergences.

Gary