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
and also i do not know how many candles are in between candle number 1 and 2.
thank you
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.
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]”.
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
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
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.