barindex code trouble
Forums › ProRealTime English forum › ProOrder support › barindex code trouble
- This topic has 8 replies, 3 voices, and was last updated 3 years ago by Vonasi.
-
-
02/20/2021 at 9:12 AM #162078
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.
123456789101112131415period = 10buyindex = 0n = 0if not longconditions[1] thenfor a = 0 to period -1IF longconditions and not onmarket thenbuyindex = barindex[a]breakENDIFnextendifif (close[barindex - buyindex]- close >0.0030) thensellshort 2 contracts at marketendif02/20/2021 at 9:16 AM #162080and also i do not know how many candles are in between candle number 1 and 2.
thank you
02/20/2021 at 10:28 AM #162081Try replacing line 6 with:
1IF longconditions[a] and not onmarket[a] thenTo see what’s the barindex number in ProBackTest you can append this line to your code:
1GRAPH BarIndexwhich 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.
02/20/2021 at 10:47 AM #162082i 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]”.
02/20/2021 at 11:07 AM #162084Yes, that’s correct.
02/20/2021 at 11:39 AM #16208602/21/2021 at 9:07 AM #162155hi,
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.
1234567891011121314period = 15buyindex = 0n = 0if not longconditions[1] thenfor a = 0 to period -1IF longconditions[a] and not onmarket[a] thenbuyindex = barindex[a]breakENDIFnextendifif (close[barindex - buyindex]- close >0.0030) thensellshort 2 contracts at marketendif02/21/2021 at 10:08 AM #162159I’m not sure that I fully understand what you are trying to do but:
12345678910111213period = 15buyindex = 0n = 0if not longconditions[1] thenfor a = 0 to period -1IF longconditions[a] and not onmarket[a] thenif (close[a]- close >0.0030) thensellshort 2 contracts at marketendifbreakENDIFnextendif02/21/2021 at 10:19 AM #162163kevin12345 – 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.
-
AuthorPosts
Find exclusive trading pro-tools on