Hi,
How do I use an oscillator (stochastic or CCI) to determine a trend using price action.
I need help coding the following, ideally based on 5m or 15m charts:
Uptrend (higher lows and higher highs)
- current price is in the oversold area of the oscillator
- current price is higher than the previous oversold area
Downtrend (lower highs and lower lows)
- Current price is in the overbought area of the oscillator
- current prices is lower than the previous overbought area
See attached image which illustrates the above for an uptrend.
For an uptrend, a rough idea would be to store the lowest low of price within last X periods when the oscillator leave its oversold area and then compare this value with the previous stored one.
How do you want to display this information? uptrend=1 if new value is superior to the last one?
Hi,
I want the indicator to display the result as follows:
0=no alert
1=uptrend
-1=downtrend
That’s fine, I quickly code something that should be relevant to your query (an example of how it looks is attached). Here is the code:
sto = stochastic[8,3]
x = 8 //lookback period for find the lastest highest high or lowest low
hh = highest[x](high)
ll = lowest[x](low)
signal=0
if sto crosses over 20 then
if ll>lastll then
signal=1
else
signal=signal[1]
endif
lastll = ll[1]
endif
if sto crosses under 80 then
if hh<lasthh then
signal=-1
else
signal=signal[1]
endif
lasthh = hh[1]
endif
return signal
Nicolas, I had a look at your code, and it is great, I was wondering though if it would be possible to code the following:
- definition of a uptrend scenario
- there are 2 higher highs in the last x days period.
- there are 2 higher lows in the last x days periods
- definition of a downtrend scenario
- there are 2 lower highs in the last x days period.
- there are 2 lower lows in the last x days periods
Thak you very much
Francesco