How to get or determine the barIndex or number by the cross point

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #264992 quote
    thomas2004chthomas2004ch
    Participant
    Senior

    Assumed 6 days ago and 12 days ago there were MACD crossover. How can I get or determine their barIndex, so I can get the value of the MACD Line?

    cross.png cross.png
    #264994 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Use BarsSince (https://www.prorealcode.com/documentation/barssince/):

    CrossOver  = MACD[12,26,9](close) crosses over 0
    CossingBar = BarsSince(CrossOver)
    

    CossingBar contains the bar ID where the crossover occurred.



    thomas2004ch thanked this post
    #265000 quote
    thomas2004chthomas2004ch
    Participant
    Senior


    robertogozzi wrote: Use BarsSince (https://www.prorealcode.com/documentation/barssince/): CrossOver = MACD[12,26,9](close) crosses over 0 CossingBar = BarsSince(CrossOver) Copy CossingBar contains the bar ID where the crossover occurred. thomas2004ch thanked this post

    Many thanks!


    I simply use the example code here: https://www.prorealcode.com/documentation/barssince/


    But how can I understand the values? Here is a screenshot. The “previous occurrence” is 5 and the “last occurrence” is 0. By the second screenshot, the “previous occurrence” is 8 and the “last occurrence” is still 0

    RSI_Crossover.png RSI_Crossover.png RSI_Crossover_2.png RSI_Crossover_2.png
    #265002 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    I can’t figure out why your data seem to be wrong.

    Mine are correct as you can see from my attached picture.

    I remind you that 0 is the current bar, 1 is the first bar preceding the current bar, …. 7 is the seventh bar prior to the current one. So 0 means the crossover occurred on the CURRENT bar.



    x-1.jpg x-1.jpg
    #265004 quote
    thomas2004chthomas2004ch
    Participant
    Senior


    robertogozzi wrote: I can’t figure out why your data seem to be wrong. Mine are correct as you can see from my attached picture. I remind you that 0 is the current bar, 1 is the first bar preceding the current bar, …. 7 is the seventh bar prior to the current one. So 0 means the crossover occurred on the CURRENT bar.

    Ok, now I got it. Many thanks!

    robertogozzi thanked this post
    RSI_Crossover-1.png RSI_Crossover-1.png
    #265017 quote
    thomas2004chthomas2004ch
    Participant
    Senior

    Now I want print the value on the cross point. But I got error.


    here is my code.

    MyMACDLine = MACDline[12,26,9](close)
    MyMACDSignal = MACDSignal[12,26,9](close)
    
    MACDCrossOverSignal = MyMACDLine crosses over MyMACDSignal
    
    testMACDCrossOverSignalFirst = BarsSince(MACDCrossOverSignal)
    
    div1 = MyMACDLine[testMACDCrossOverSignalFirst]
    
    //return testMACDCrossOverSignalFirst COLOURED(255,0,0) as "first occurrence"
    return div1
    



    error.png error.png
    #265026 quote
    NicolasNicolas
    Keymaster
    Legend

    Try this version to avoid the negative integer error:

    MyMACDLine = MACDline[12,26,9](close)
    MyMACDSignal = MACDSignal[12,26,9](close)
    
    
    MACDCrossOverSignal = MyMACDLine crosses over MyMACDSignal
    
    
    testMACDCrossOverSignalFirst = max(0,BarsSince(MACDCrossOverSignal))
    
    
    div1 = MyMACDLine[testMACDCrossOverSignalFirst]
    
    
    //return testMACDCrossOverSignalFirst COLOURED(255,0,0) as "first occurrence"
    return div1
    
    #265027 quote
    thomas2004chthomas2004ch
    Participant
    Senior


    Nicolas wrote: Try this version to avoid the negative integer error: MyMACDLine = MACDline[12,26,9](close) MyMACDSignal = MACDSignal[12,26,9](close) MACDCrossOverSignal = MyMACDLine crosses over MyMACDSignal testMACDCrossOverSignalFirst = max(0,BarsSince(MACDCrossOverSignal)) div1 = MyMACDLine[testMACDCrossOverSignalFirst] //return testMACDCrossOverSignalFirst COLOURED(255,0,0) as “first occurrence” return div1 Collapse Copy thomas2004ch thanked this post

    wonderful! Many thanks!

    #265029 quote
    NicolasNicolas
    Keymaster
    Legend

    BarsSince: If the condition has never been true, the function returns -1.

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

How to get or determine the barIndex or number by the cross point


ProScreener: Market Scanners & Detection

New Reply
Author
Summary

This topic contains 8 replies,
has 3 voices, and was last updated by NicolasNicolas
1 month, 2 weeks ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 09/08/2026
Status: Active
Attachments: 6 files
ProRealCode ProRealCode
Loading...