Strategy work in back test but not in DEMO

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #211159 quote
    Aragorna
    Participant
    Junior

    Hello everyone,

    I’m trying a simple autotrading strategy with PRT Bands, just to test it (I’m using IB), but I don’t understand why it works correctly in backtest but not in DEMO. In Demo it doesn’t open positions, anyone can help me why, please? I’ve got a strategy on gold that works, now I’m testing the strategy on large stocks (Tesla and Nvidia) , but for some reason it doesn work. I’m thinking if the problem is the fact it buys at market and not with limit order?

    thank’s anyone in advance who can help me.

    //-------------------------------------------------------------------------
    // Main code : Nuovo3
    //-------------------------------------------------------------------------
    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Conditions to enter long positions
    EXP1 = ExponentialAverage[1](close)
    up = PRTBANDSUP
    dn = PRTBANDSDOWN
    
    EXP50 = ExponentialAverage[50](close)
    EXP100 = ExponentialAverage[100](close)
    c2 = (EXP50 >= EXP100)
    c3 = (EXP100 >= EXP50)
    if close crosses over up and trend<=0 then //prezzo supera banda superiore
    trend=1
    elsif close crosses under dn and trend>=0 then //prezzo ribassa banda inferiore
    trend=-1
    ENDIF
    c4 = trend<>trend[1]
    //condizione per entrare Long
    IF NOT longonmarket and Trend=1 and c2  and c4 then
    BUY 10 SHARES AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    
    IF longonmarket and TREND=-1 and c4  THEN
    SELL AT MARKET
    ENDIF
    
    
    
    // Stops and targets
    SET STOP pLOSS 4
    #211160 quote
    Aragorna
    Participant
    Junior

    I want to specify that the working strategy on gold is not the same.

    #211161 quote
    PeterSt
    Participant
    Master

    I’m thinking if the problem is the fact it buys at market and not with limit order?

    I think you showed the wrong code because it shows with Market Orders ?

    With Demo you mean the PaperTrading option at startup ?

    #211165 quote
    Nicolas
    Keymaster
    Master

    Might be a margin requirement? 10 shares of large stocks could be too much for your account size/margin

    #211179 quote
    Aragorna
    Participant
    Junior

    Yes I mean paper trading. ISn’t correct to use Market order in DEMO? I saw it works for gold (but it’s another strategy). by the way my doubt was another one. Since that during pre market and after market you can enter long only with limit order, is it correct to use “Buy at Market” ? I don’t think that is the problem because I verified that the condition to enter was activeted during regular hours.

    #211180 quote
    Aragorna
    Participant
    Junior

    Hi Nicolas,

    my DEMO account has 25K.  10 shares of a stock whose value is 150 $, I don’t believe that could be a problem. COuld be because IB does work only in a limited choiches so far?

    #211181 quote
    JS
    Participant
    Senior

    What kind of time frame do you use for this code?

    I don’t know how long you ran this code in demo but it may take a while for a position to open…

    #211236 quote
    Aragorna
    Participant
    Junior
    I use 1H timeframe. For example yesterday should be have gone long but it didn’t. in my backtest it did (in attachment)
    #211240 quote
    JS
    Participant
    Senior

    In your attachment (pdf) a position was opened on March 2… (a week ago)…?

    #211277 quote
    Aragorna
    Participant
    Junior
    strategy was lunched on 4th of march, in attachment you see the chart of the strategy where there are no positions open, on the right chart the backtest. As you can see a position should be opened but there is nothing. I cannot explain. someone can understand why?
    #211311 quote
    GraHal
    Participant
    Master
    Are you using the same value for Spread in the Backtest as will be used during Live running?
    #211477 quote
    Aragorna
    Participant
    Junior
    thank you Graha, that could be problem in fact
    GraHal thanked this post
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

Strategy work in back test but not in DEMO


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Aragorna @aragorna Participant
Summary

This topic contains 11 replies,
has 5 voices, and was last updated by Aragorna
2 years, 11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/09/2023
Status: Active
Attachments: 3 files
Logo Logo
Loading...