Calling an indicator

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #243745 quote
    kanonmicke
    Participant
    New

    Im new to the coding language in prorealtime and hope somebody could give me a hint on this issue.

    I have an indicator that draw stochastic divergence lines, see below.
    From an automatic trading robot I know I can CALL this indicator by:

    
    myStoch, my0 = CALL "mydivergence4"[14, 1, 3, 100]
    

    In my trading system that calls the indicator, how can I know exactly when a divergence line is drawn so I can make a decision if I want to buy or sell.
    Is it possible to find out from the myStoch variable that is returned in the CALL request, or, do I have to incorporate the indicator code into my trading robot and do SELL or BUY instead of drawsegment?

    
    StochPrd = 9 
    KPrd = 1 
    DPrd = 3 
    N = 100
     
    StochD = Stochasticd[StochPrd,KPrd,DPrd](close)
    Offset = .01
    IF (BarIndex > 10+1+N) THEN
    // short
    IF (StochD[1]>StochD AND StochD[1]>StochD[2]) THEN
    extremum2=StochD[1]
    extremum1=highest[N](StochD)
    preciomax2=close[1]
    preciomax=Highest[N](close)
    IF(extremum2<extremum1 AND preciomax2>preciomax[1]) THEN
    for i=1 to N
    if StochD[i]=extremum1 then
    zz=i
    drawsegment (barindex[1], StochD[1]+Offset, barindex[zz], StochD[zz]+Offset) coloured(200,0,0)
    endif
    next
    endif
    endif
    // long
    IF (StochD[1]<StochD AND StochD[1]<StochD[2]) THEN
    extremum22=StochD[1]
    extremum11=lowest[N](StochD)
    preciomin2=close[1]
    preciomin=lowest[N](close)
    IF(extremum22>extremum11 AND preciomin2<preciomin[1]) THEN
    for i2=1 to N
    if StochD[i2]=extremum11[1] then
    zz2=i2
    drawsegment(barindex[1], StochD[1]-Offset, barindex[zz2], StochD[zz2]-Offset) coloured(0,200,0)
    endif
    next
    ENDIF
    ENDIF
    endif
    return StochD as "Stoch", 0 as "0"
    
    #243747 quote
    robertogozzi
    Moderator
    Master

    Use this modified version:

    StochPrd = 9
    KPrd = 1
    DPrd = 3
    N = 100
     
    StochD = Stochasticd[StochPrd,KPrd,DPrd](close)
    Offset = .01
    Signal = 0
    IF (BarIndex > 10+1+N) THEN
    // short
    IF (StochD[1]>StochD AND StochD[1]>StochD[2]) THEN
    extremum2=StochD[1]
    extremum1=highest[N](StochD)
    preciomax2=close[1]
    preciomax=Highest[N](close)
    IF(extremum2<extremum1 AND preciomax2>preciomax[1]) THEN
    for i=1 to N
    if StochD[i]=extremum1 then
    Signal = -1
    zz=i
    drawsegment (barindex[1], StochD[1]+Offset, barindex[zz], StochD[zz]+Offset) coloured(200,0,0)
    endif
    next
    endif
    endif
    // long
    IF (StochD[1]<StochD AND StochD[1]<StochD[2]) THEN
    extremum22=StochD[1]
    extremum11=lowest[N](StochD)
    preciomin2=close[1]
    preciomin=lowest[N](close)
    IF(extremum22>extremum11 AND preciomin2<preciomin[1]) THEN
    for i2=1 to N
    if StochD[i2]=extremum11[1] then
    Signal = 1
    zz2=i2
    drawsegment(barindex[1], StochD[1]-Offset, barindex[zz2], StochD[zz2]-Offset) coloured(0,200,0)
    endif
    next
    ENDIF
    ENDIF
    endif
    return StochD as "Stoch", 0 as "0",Signal AS "Signal"

    then modify the calling line into:

    myStoch, my0, mySignal = CALL "mydivergence4"[14, 1, 3, 100]

    then use mySignal to know when a Divergence occurred (1=bullish,  -1=bearish).

    Iván González thanked this post
    #243749 quote
    kanonmicke
    Participant
    New

    Thank you very much!

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

Calling an indicator


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
kanonmicke @kanonmicke Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by kanonmicke
1 year ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 02/12/2025
Status: Active
Attachments: No files
Logo Logo
Loading...