Use of BArindex

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

    Hello

    I have been struggling with BARINDEX and its interpretation, as far as I am aware it will tell me how many bars are loaded since the beginning of an automated strategy so the very first bar in a strategy should be 0.

    I have a piece of code below where I would like to enter the position under certain circumstances and when BARINDEX = 0.  But it never enters the initial position so the automated strategy wont get going.

    Am I misunderstanding BARINDEX or  is the code below wrong?

    ARC = 3* averagetruerange[7](close)
    
    IF BARINDEX = 0 THEN
    inithigh = highest[7](close)
    initlow = lowest[7](close)
    STARB1 = inithigh - ARC[0]
    STARS1 = initlow + ARC[0]
    IF close[0] > STARB1 then
    buy 3 contracts at market
    ELSIF close[0] < STARS1  then
    sellshort 3 contracts at market
    ENDIF
    ENDIF
    #6689 quote
    NicolasNicolas
    Keymaster
    Legend

    The online prorealtime documentation of the site :

    BARINDEX : Return the number of bars since the beginning of data loaded (in a chart in the case of a ProBuilder indicator of for a trading system in the case of ProBacktest or ProOrder)

    In your code, if barindex=0, there are no way to calculate 7 previous bar of the very first one 🙂

    #6710 quote
    IGOSNELLIGOSNELL
    Participant
    Average

    Hello Nicolas

    Thanks but you have lost me.

    Regards

    Ian

    #6716 quote
    NicolasNicolas
    Keymaster
    Legend

    In your first condition you are trying to find the highest and lowest values from the 7 previous periods, but it’s not possible since you are trying to do this at the first bar (barindex=0). So you need to wait until you are at least at the 7th bar of loaded history to find these values.

    #6876 quote
    IGOSNELLIGOSNELL
    Participant
    Average

    Thanks Nicolas

    Makes perfect sense, I did not see the woods for the trees.

    Regards

    Ian

Viewing 5 posts - 1 through 5 (of 5 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

Use of BArindex


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
IGOSNELL @igosnell Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by IGOSNELLIGOSNELL
10 years, 4 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/10/2016
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...