Backtesting: Buy order Problem ie BarIndex

Forums ProRealTime English forum ProOrder support Backtesting: Buy order Problem ie BarIndex

Viewing 5 posts - 1 through 5 (of 5 total)
  • #141242

    So I am still learning Pro Real Code syntax. I have a successful trading system i been using for years but finally want to get into automated trading and i want to do some back testing first.

    So the system consist of 3 different conditions

    1. Todays close –  The 10 day Moving Average of the close.
    2. Todays 10 day Moving Average – The 10 day Moving Average from 10 days ago
    3. Todays close – the close from 40 days ago.

    if all three conditions are met (count = 3) then i want to buy 1 contract and go long. if all 3 conditions are not met (countb= -3) then  i want to sell 1 contract. once we get long (or short) we tighten or loosen the stop depending on what the condition count (or count b) is at +3 +2 +1 -1 -2 -3.

    I use daily (time frame) and regardless of the units (i use 200 units). Starting the backtest i need to skip the first 40 days of the data as all three of the conditions have not had time to be tested yet. I would assume i can use the “bar index” to determine when i can finally activate buy or selling but the system just doesn’t seem to work as I thought. If you use AMD you can see in my screen shot that the first buy signal is at 50 days  it it should be may 18th on the 40th day. So my question is how do I use bar index or some other code to ensure that the buying and selling happens after the first 40 days?

     

    Any help would be greatly appreciated.

    #141252

    Todays close – the close from 40 days ago.

    If TF = Daily then below code will satisfy condition.

    PreLoad Bars are a default of 2000 so why wait 40 days using bar index?

     

     

    #141256

    Sorry for my inexperience, but I am not sure what the “TF” means?

    I attached another screen shot. the first arrow shows a 3+ condition. that should have been my first purchase not 10 days later. I just dont know why my code is not making the first purchase on the correct day. Clearly the indicator at the bottom says its a +3 day just not sure why the backtest is not picking it up correctly.

    #141273

    TF means Timeframe which is the time required for one bar to complete and then a new bar starts.

    #141274

    Because your code is waiting for barindex to be more than 40 bars, while it is not needed because history is preloaded and your MA and daily Close are already known at first bar when you launch the strategy. Try with this modified code:

     

Viewing 5 posts - 1 through 5 (of 5 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login