Coding help required using oscillator for price action trading

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #32880 quote
    ck1066
    Participant
    Average

    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)

    1. current price is in the oversold area of the oscillator
    2. current price is higher than the previous oversold area

    Downtrend (lower highs and lower lows)

    1. Current price is in the overbought area of the oscillator
    2. current prices is lower than the previous overbought area

    See attached image which illustrates the above for an uptrend.

    #32970 quote
    Nicolas
    Keymaster
    Master

    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?

    #33007 quote
    ck1066
    Participant
    Average

    Hi,

    I want the indicator to display the result as follows:

    0=no alert

    1=uptrend

    -1=downtrend

    #33013 quote
    Nicolas
    Keymaster
    Master

    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
    #33467 quote
    Francesco78
    Participant
    Master

    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
    1. there are 2 higher highs in the last x days period.
    2. there are 2 higher lows in the last x days periods
    • definition of a downtrend scenario
    1. there are 2 lower  highs in the last x days period.
    2. there are 2 lower lows in the last x days periods

    Thak you very much

    Francesco

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Coding help required using oscillator for price action trading


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
ck1066 @ck1066 Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by Francesco78
8 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 04/21/2017
Status: Active
Attachments: 2 files
Logo Logo
Loading...