barindex code trouble

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #162078 quote
    kevin12345
    Participant
    Average

    hi,

    i am having some trouble to barindex code. please see picture. lets just say i am at candle number 2 marked on the picture. forget the rest of the candles that come after it. i want to sell 2 contracts at candle number 2 when the difference of (close[candle number 1] – close[which is the latest candle] > 30 pips). please help.

    period = 10
    buyindex = 0
    n = 0
    if not longconditions[1] then
    for a = 0 to period -1
    IF longconditions and not onmarket then
    buyindex = barindex[a]
    break
    ENDIF
    next
    endif
    
    if (close[barindex - buyindex]- close >0.0030)  then
    sellshort 2 contracts at market
    endif
    Capture2.png Capture2.png
    #162080 quote
    kevin12345
    Participant
    Average

    and also i do not know how many candles are in between candle number 1 and 2.

    thank you

    #162081 quote
    robertogozzi
    Moderator
    Master

    Try replacing line 6 with:

    IF longconditions[a] and not onmarket[a] then

    To see what’s the barindex number in ProBackTest you can append this line to your code:

    GRAPH BarIndex

    which will show you the value BARINDEX retains each bar, in the variable window of ProBackTest.

    To know how many bars there are between the two candles you need to know the BARINDEX value of candle 1 (you can use a variable to store that value), then calculate the difference.

     
    #162082 quote
    kevin12345
    Participant
    Average

    i have done what you have suggested and the barindex graph showed an increase of 1 on every candle.  Can you correct me if  i have stored the barindex at candle number 1 correctly? it is line number 7 “buyindex = barindex[a]”.

    #162084 quote
    robertogozzi
    Moderator
    Master

    Yes, that’s correct.

    #162086 quote
    kevin12345
    Participant
    Average

    thanks!

    #162155 quote
    kevin12345
    Participant
    Average

    hi,

    how do i change the period so that it is equal to the barindex of the recent longconditions? and when the line number 12,13,14 is satisfied the period stops.

    period = 15
    buyindex = 0
    n = 0
    if not longconditions[1] then
    for a = 0 to period -1
    IF  longconditions[a] and not onmarket[a] then
    buyindex = barindex[a]
    break
    ENDIF
    next
    endif
    if (close[barindex - buyindex]- close >0.0030) then
    sellshort 2 contracts at market
    endif
    
    #162159 quote
    Vonasi
    Moderator
    Master

    I’m not sure that I fully understand what you are trying to do but:

    period = 15
    buyindex = 0
    n = 0
    if not longconditions[1] then
    for a = 0 to period -1
    IF  longconditions[a] and not onmarket[a] then
    if (close[a]- close >0.0030) then
    sellshort 2 contracts at market
    endif
    break
    ENDIF
    next
    endif
    
    #162163 quote
    Vonasi
    Moderator
    Master

    kevin12345 – You started another topic about exactly the same piece of code being discussed here. Please avoid double posting as per the forum rules as it just leads to confusion and wasted time. I also noticed that you posted this first topic in the wrong forum. I have moved it to the right forum (ProOrder as you are discussing strategy code) and merged your second post (because I had already replied to it) on exactly the same topic with this first one.

    Please read and stick to the forum rules with all future posts to save moderators from having to do a lot of tidying up for you.

    Post your topic in the correct forum:
    _ ProRealTime Platform Support: only platform related issues.
    _ ProOrder: only strategy topics.
    _ ProBuilder: only indicator topics.
    _ ProScreener: only screener topics
    _ General Discussion: any other topics.
    _ Welcome New Members: for new forum members to introduce themselves.

    • Do not double post. Ask your question only once and only in one forum. All double posts will be deleted anyway so posting the same question multiple times will just be wasting your own time and will not get you an answer any quicker. Double posting just creates confusion in the forums.
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

barindex code trouble


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
kevin12345 @kevin12345 Participant
Summary

This topic contains 8 replies,
has 3 voices, and was last updated by Vonasi
5 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/20/2021
Status: Active
Attachments: 1 files
Logo Logo
Loading...