barindex trouble

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #54821 quote
    jebus89
    Participant
    Master

    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

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    
    
    fastma = average[10]
    // Conditions to enter long positions
    if barindex = 0 then
    buy1 = highest[20](close)
    sell1 = lowest[20](close)
    buysignal = buy1 > fastma
    sellsignal = sell1 < fastma
    if close > buysignal then
    buy 1 contract at market
    elsif close < sellsignal then
    sellshort 1 contract at market
    endif
    endif
    
    c1 = close[2] < close
    
    if c1 then
    sell at market
    endif
    
    

     

     

    #54824 quote
    Despair
    Blocked
    Master

    What do you want to achieve with this “barindex if-loop”? Take it away otherwise you won’t get any trades.

    #54827 quote
    robertogozzi
    Moderator
    Master

    Lines 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

     

    #54848 quote
    jebus89
    Participant
    Master
    What 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!

     

    If im asking for “high[7]” (or “highest[20]”?) will it check for the highest point in the last 7 candles, or only the high from the 7th candle? 

     

    Sorry for being such a noob

    #54861 quote
    Despair
    Blocked
    Master

    It will check for the highest value of the last 7 or 20 candles. Sounds like you should read the manual. 😉 

    #54870 quote
    jebus89
    Participant
    Master
    Sounds 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 😛  ) 

    #54888 quote
    Leo
    Participant
    Veteran
    if 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!
    #54893 quote
    jebus89
    Participant
    Master

     If ther’s room for some more questions here: 

    if intradaybarindex=0 then
    trading=1

    What 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?
    #54897 quote
    robertogozzi
    Moderator
    Master

    BARINDEX 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:

    IF IntraDayBarIndex THEN
       .
       .         //here you know a new day has just begun
       .
    ENDIF

    To check how many bars have elapsed since your trade was opend you may write:

    IF (BarIndex - TradeIndex) >= x THEN   //close after x bars have elapsed
       SELL      AT MARKET
       EXITSHORT AT MARKET
    ENDIF

    I 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.

    #54929 quote
    Vonasi
    Moderator
    Master
    TRADEINDEX 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..
    #54932 quote
    robertogozzi
    Moderator
    Master

    Sorry Vonasi, you are absolutely right! I wrote the wrong explanation using a correc example.

    #54973 quote
    Leo
    Participant
    Veteran
    I 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.
    #54974 quote
    Leo
    Participant
    Veteran
    if 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)
    #54975 quote
    robertogozzi
    Moderator
    Master

    Sorry for my incorrect example, it should read:

    IF IntraDayBarIndex = 0 THEN  //reset to ZERO each day
       .
       .         //here you know a new day has just begun
       .
    ENDIF
    #54976 quote
    Leo
    Participant
    Veteran
    i 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:
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated 
    DEFPARAM preloadbars=100
     
    fastma = average[10]
    // Conditions to enter long positions
    buy1 = highest[20](close)
    sell1 = lowest[20](close)
    
    buysignal = buy1 > fastma
    sellsignal = sell1 < fastma
    if buysignal then
    buy 1 contract at market
    elsif sellsignal then
    sellshort 1 contract at market
    endif
    
     
    c1 = close[2] < close
     
    if c1 then
    sell at market
    endif
    
    
Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.

barindex trouble


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
jebus89 @jebus89 Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/05/2017
Status: Active
Attachments: No files
Logo Logo
Loading...