ProOrder backtest opens trade late

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #58690 quote
    wolf
    Participant
    Junior

    Hello, I’m BackTesting with some Exponential moving averages, and the backtest often opens a trade a candle or 2 after the first candle after the EMA cross. Making the results inaccurate. Using a slightly faster EMA to compensate is what I’ve been doing, but that creates other problems.

    My code is very basic and is just calculating EMA on the close of the candle, and so is my indicator on the chart. So nothing wrong there.

    Attached is an example.

    Any ideas on how to fix this?

    temp-stock.png temp-stock.png
    #58695 quote
    Nobody
    Participant
    Veteran

    If you actually just have the 2 averages that constitute your signal we might be able to see exactly what you are describing but with 4 averages i am clueless to what you are actually describing   ? Ambiguity isnt helping here , Clarity makes it much easier  …

    #58698 quote
    robertogozzi
    Moderator
    Master

    You should post your complete code for anyone to be of help.

    Roberto

    #58705 quote
    Nicolas
    Keymaster
    Master
    1. A cross between 2 lines is confirmed at Close
    2. Code is read at Close and orders are launched at next bar Open
    #58709 quote
    Nobody
    Participant
    Veteran
    1. A cross between 2 lines is confirmed at Close
    2. Code is read at Close and orders are launched at next bar Open

    which in effect is a lag of what really should be 1 tick .

    a signal during bar is useless thats why it is done this way  ,  only once a bar is complete can a signal truly be verified

    #58778 quote
    wolf
    Participant
    Junior

    Hi, here’s my code.  It’s very basic, so hopefully theres nothing wrong there.

    EMA1 = ExponentialAverage[25](close)
    EMA2 = ExponentialAverage[100](close)
    
    cBuy = (EMA1 crosses over EMA2)
    cSell = (EMA1 CROSSES under EMA2)
    
    set stop %loss 0.5
    
    IF cBuy THEN
    BUY 1 Contract AT Market
    ENDIF
     
    IF cSell THEN
    SELLSHORT 1 Contract AT Market
    ENDIF
    
    #58780 quote
    wolf
    Participant
    Junior

    Sorry, I thought circling the only cross near the backtest order would be clear enough.

    #58781 quote
    wolf
    Participant
    Junior

    So to get ProOrder to execute when I want it, should I change by indicator/code to calculate on the open instead of the close? Because when I do so, it still opens the trade ‘late’.

     

    The pictures attachted are with the code calculating the EMA on ‘open’ instead of ‘close’

    sbry.png sbry.png stan.png stan.png
    #58782 quote
    Vonasi
    Moderator
    Master

    You need to move your set stop %loss 0.5 down to the last line of code. Code is read from top to bottom at the close of each candle and so you will have to wait for a candle to pass after opening trades before it is read. At the bottom below the buy/sells it will put an order to the market just after buying or selling.

    #58785 quote
    wolf
    Participant
    Junior

    Thanks I’ve moved the stop loss to the bottom. Is there anyway to get my code to execute when I want it too? i.e. open of first candle after EMA cross

    #58798 quote
    Vonasi
    Moderator
    Master

    No all decisions are made at the close of a candle and new position are opened at the open of the next – so be aware of markets with big gaps!

    The only way to open a position mid candle is to set market stop and limit orders at a chosen price but these orders will once again not be placed until the current candle has closed.

    #58805 quote
    wolf
    Participant
    Junior

    So, I guess I have to use a faster EMA in the ProOrder code, which is annoying since it stops me from being able to fully trust the data.

    #58812 quote
    Vonasi
    Moderator
    Master

    If PRT was able to check for MA crosses mid candle then I think that you would get many false signals anyway when markets are going sideways.

    #58813 quote
    wolf
    Participant
    Junior

    I get that, but in my case I dont want to open mid candle as soon as the EMAs cross, I want to open on the open of the first candle after the cross happens. This works fine in real time trading since the EMAs move, visually, on the open of a new candle(even if counting from ‘close’) but it backtesting they work differently it seems.

    #58814 quote
    Vonasi
    Moderator
    Master

    I dont want to open mid candle as soon as the EMAs cross, I want to open on the open of the first candle after the cross happens.

    When a candle closes PRT will just check that a cross has occurred at that point in time (I guess it just compares the MA positions from this close to the previous close). It then opens a position at the next open. So it is doing what you want. I have to confess that I am struggling to see the problem at the moment 🙂

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

ProOrder backtest opens trade late


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
wolf @wolf Participant
Summary

This topic contains 17 replies,
has 5 voices, and was last updated by Nicolas
8 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/09/2018
Status: Active
Attachments: 4 files
Logo Logo
Loading...