barindex trouble
Forums › ProRealTime English forum › ProOrder support › barindex trouble
- This topic has 16 replies, 5 voices, and was last updated 7 years ago by
jebus89.
-
-
12/05/2017 at 9:06 PM #54821
Im not understanding the barindex command. What am i doing wrong here?
Just want to learn to i figured i would buy if:
Close > moving average 10
+
Close > highest high past 20 candles
123456789101112131415161718192021222324// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedfastma = average[10]// Conditions to enter long positionsif barindex = 0 thenbuy1 = highest[20](close)sell1 = lowest[20](close)buysignal = buy1 > fastmasellsignal = sell1 < fastmaif close > buysignal thenbuy 1 contract at marketelsif close < sellsignal thensellshort 1 contract at marketendifendifc1 = close[2] < closeif c1 thensell at marketendif12/05/2017 at 9:47 PM #5482412/05/2017 at 10:08 PM #54827Lines 11-12 assign boolean values (0-1) to variables, then at lines 13 and 15 you compare them with prices. That would yield really odd trades, if any (see what Despair said)!
Anyway BARINDEX is zero when you first launch your strategy, then it is incremented by 1 at each new bar/candlestick.
Roberto
12/06/2017 at 8:10 AM #54848What do you want to achieve with this “barindex if-loop”? Take it away otherwise you won’t get any trades.
Lol, i tried to look at what other systems where doing, i have no clue man!
Sorry for being such a noob
12/06/2017 at 9:32 AM #5486112/06/2017 at 10:48 AM #54870Sounds like you should read the manual.
yea that was my last chance, figured id ask here first though. Not everything in that manual is written for newbs like me 😀 (meaning i dont always understand what it says in the manual 😛 )
12/06/2017 at 12:53 PM #54888if barindex = 0 then ?????
So your code is only working at the first candle… after that your code is not doing anything
I learn to code just by reading the Manuals since the firs page and practizing chapter by chapter… so Keep Calm and Keep reading!
12/06/2017 at 1:06 PM #54893If ther’s room for some more questions here:
if intradaybarindex=0 thentrading=1What exactly does that mean? I dont understand the barindex command at all.
In general the “If barindex = 0 then…” command, what does it mean? i dont get why so many people use it. Would love to understand 🙂how would you rewrite my code in post 1, to make it actually trade if the close[0] > highest high in past 20 candles?
12/06/2017 at 1:26 PM #54897BARINDEX is the number of bars elapsed since your strategy has been launched.
TRADEINDEX is the number of bars elapsed since your trade was opened.
INTRADAYBARINDEX is the number of intraday bars elapsed since the beginning of the day and is reset daily to zero.
To reset some variables at the beginning of each day you may want to write:
12345IF IntraDayBarIndex THEN.. //here you know a new day has just begun.ENDIFTo check how many bars have elapsed since your trade was opend you may write:
1234IF (BarIndex - TradeIndex) >= x THEN //close after x bars have elapsedSELL AT MARKETEXITSHORT AT MARKETENDIFI also suggest that you use the search box to find all occurrences of keywords you don’t feel at ease with. You’ll find documentation and plenty of examples to study.
12/06/2017 at 10:39 PM #54929TRADEINDEX is the number of bars elapsed since your trade was opened.
Sorry robertogozzi but I think you got this bit wrong?
An Index is an Index! Everything is given a number so that you can find it again. The first bar on a chart is 1, the second bar is 2 and so on. If you want to use information from the 29th bar then look at Barindex[29]. TradeIndex is the number of the bar on the chart when the last trade was opened. So it could be Barindex 29 and Trade Index 25 which means that you have 29 bars on the chart and opened a trade on the 25th bar. So BarIndex – TradeIndex = 4… so you opened the last trade four bars ago..
12/07/2017 at 12:41 AM #54932Sorry Vonasi, you are absolutely right! I wrote the wrong explanation using a correc example.
12/07/2017 at 12:42 PM #54973I think the barindex=1 is the first data loaded since we use DEFPARAM preloadbars=1000
then the first BARINDEX when your System was activated is 1001.
Anyway…
I use a lot BARINDEX in my codes because I use it to Figur out symmetries, triangles, etc.
12/07/2017 at 12:45 PM #54974if intradaybarindex=0 then trading=1 What exactly does that mean? I dont understand the barindex command at all.
BARINDEX and INTRADAYBARINDEX are different, in your example as robertogozzi says is for reseting variables
but in your code you have use: totally different
// Conditions to enter long positions
if barindex = 0 then
buy1 = highest[20](close)
12/07/2017 at 12:47 PM #54975Sorry for my incorrect example, it should read:
12345IF IntraDayBarIndex = 0 THEN //reset to ZERO each day.. //here you know a new day has just begun.ENDIF12/07/2017 at 12:49 PM #54976i dont get why so many people use it
Then simple: do not use it until !!! you copy things to your code without knowing… that dangerous.
have look, test it and tell us your results:
1234567891011121314151617181920212223// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivatedDEFPARAM preloadbars=100fastma = average[10]// Conditions to enter long positionsbuy1 = highest[20](close)sell1 = lowest[20](close)buysignal = buy1 > fastmasellsignal = sell1 < fastmaif buysignal thenbuy 1 contract at marketelsif sellsignal thensellshort 1 contract at marketendifc1 = close[2] < closeif c1 thensell at marketendif -
AuthorPosts
Find exclusive trading pro-tools on