barindex problems, strategy starting trade from the first candle?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #89674 quote
    WHYWHYWHY
    Participant
    New

    why I set the system to start trading if barindex > 100 but it keeps starting trade from the first candle???

    where’s the problem??

    DEFPARAM CumulateOrders = False
    
    RSII = RSI[5](close)
    MA = Average[100](close)
    
    //long
    long = (BarIndex > 100 and RSII <= 30 and close > MA)
    short = (BarIndex > 100 and RSII >= 70 and close < MA)
    if long then
    buy 1 contracts at market
    endif
    
    //short
    if short then
    sellshort 1 contracts at market
    endif
    
    
    
    
    //exit
    
    SET STOP PTRAILING 50
    
    USDJPY-1-分钟.png USDJPY-1-分钟.png
    #89677 quote
    GraHal
    Participant
    Master

    Try below, the default preload bars is 200

    Let us know how you get on?

    DEFPARAM Preloadbars = 0
    

    PS I guess we can expect a few more WHY’s from you? 🙂 Catchy and memorable username!  🙂

    #89679 quote
    GraHal
    Participant
    Master

    Couldn’t resist a tweak … tried a few and ended up at below to keep it simple.

    Results attached with  spread = 4.

    Need to do some Walk Forward testing, but I’m setting it going on Demo Forward Test as is anyway.

    //https://www.prorealcode.com/topic/barindex-problems/
    
    DEFPARAM CumulateOrders = False
     
    RSII = RSI[8](close)
    MA = Average[90](close)
     
    //long
    long = (RSII <= 30 and close > MA)
    short = (RSII >= 70 and close < MA)
    if long then
    buy 1 contracts at market
    SET STOP PLOSS 250
    endif
     
    //short
    if short then
    sellshort 1 contracts at market
    SET STOP PLOSS 250
    endif
    
    WHY.jpg WHY.jpg WHY-2.jpg WHY-2.jpg
    #90321 quote
    WHYWHYWHY
    Participant
    New

    thanks for your advice, but i have another problem

    i supposed it will buy a contract at the first bar but it didn’t.

    WHY?

    once trend = 0
    
    
    IF NOT LongOnMarket AND trend = 0 THEN
    BUY 1 CONTRACTS AT MARKET
    trend = 1
    ENDIF
    
    #90322 quote
    Nicolas
    Keymaster
    Master

    Try your code without “NOT LONGONMARKET”.

    #90323 quote
    WHYWHYWHY
    Participant
    New

    tried, not work

    #90324 quote
    Nicolas
    Keymaster
    Master

    If you want to buy on first bar of the strategy, try with “if barindex<=1”

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

barindex problems, strategy starting trade from the first candle?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by Nicolas
7 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/26/2019
Status: Active
Attachments: 3 files
Logo Logo
Loading...