Trade not being entered

Forums ProRealTime English forum ProOrder support Trade not being entered

Viewing 11 posts - 1 through 11 (of 11 total)
  • #250955

    Hi guys, probably really stupid but – Why is this code not entering a trade? i’m using a daily chart of US Tech 100:

    DEFPARAM CumulateOrders = true

    once initialTrade = 0

    IF initialTrade = 0 THEN
    BUY 1 CONTRACT AT MARKET
    initialTrade = 1
    ENDIF

    #250959

    It’s weird, you can use this version, though:

     

     

    1 user thanked author for this post.
    #250963

    Perfect, thanks for that – I’ll try it when I’m back at my computer 👍

    #250974

    The problem is that the backtester loads and performs calculations even before the first candle is seen. This causes the initialTrade variable to already be equal to 1 when the backtesting starts.

    Why does Roberto’s code work? Basically because initialTrade changes state only when the first buy is executed, and that actually happens on the first visible candle.

    1 user thanked author for this post.
    #251045

    You could also set “preloadbars” to 1000, for example, and not do any calculation of buy/sell trigger variables before bar No. 1000.

    This solves the problem that normally, all variables will be calculated beginning from bar 1.

     

    DEFPARAM preloadbars = 1000

    DEFPARAM CumulateOrders = true

    once initialTrade = 0

    IF initialTrade = 0 and barindex > 1000 THEN
    BUY 1 CONTRACT AT MARKET
    initialTrade = 1
    ENDIF

    2 users thanked author for this post.
    #251046

    I just checked in demo mode : we need to say “if barindex >= 1000”, not “if barindex > 1000”

     

    DEFPARAM preloadbars = 1000

    DEFPARAM CumulateOrders = true

    once initialTrade = 0

    IF initialTrade = 0 and barindex >= 1000 THEN
    BUY 1 CONTRACT AT MARKET
    initialTrade = 1
    ENDIF

    #251047

    @XORANDNOT has the best solution sofar. But the real solution encapsulates the whole code for its logic in that If. Thus, see 1st screenshot and assume that PreLoadBars was made equal to DefParamPreloadbars (which in itself is also a must to be obtained), then in the 2nd screenshot you see the very end of the program.

    Do it like this and you simply cannot make mistakes, but notice that above this main If only ONCE commands are allowed.

    1 user thanked author for this post.
    #251051

    As I said, you need to say :

     

    If barindex >= preloadedbars then

     

     

    If you say

    If barindex > preloadedbars then

     

     

    no position will be opened in the first bar of the really started system.

    1 user thanked author for this post.
    #251056

    Yes, I understand that. But I don’t see where that matters ? To my understanding :

    In my case  I set PreLoadBars to 100, just because it requires that command or else nothing works as intended. I could also have made that 99 or 101 or 50 or 200. Even if you have bars of 1 day, it still does not matter that I can see. True, it would require one more day to preload with 100 and your system starting at day 101 for real. But this is only virtual and nothing starts later. Really all what happens is that one more bar/day is loaded ahead of the sequence of bars.

    What one should use the PreLoadBars for is the knowledge of averages and all which require x bars to calculate. Thus, using an average of 100 on 2 bars really does not work. Do you need 100 bars for that ? then the system should start at bar 101 or else it is not complete. Maybe on bar 100 … but this is all not important.

    Superfluously : if the time is now 17:22:01 and PreloadBars is 100 or 50 or 200 etc. and I start the system *now* and it goes Long immediately, then with a TF of 1 minute at 17:23 it will have taken a position.
    Would this be a backtest, then I can imagine that with 1M bars you will lose 100 (or 101 etc.) bars of precious backtest data. This is not important, right ?

    So now I am curious what you mean ? 🙂

    #251064

    It matters when you start a system on any timescale. For example, in a 1 hour chart, no position will be opened at the beginning of the bar after you started the system, but only one hour later, at the second bar. The same for any other timescale.

     

    “if the time is now 17:22:01 and PreloadBars is 100 or 50 or 200 etc. and I start the system *now* ” —– it will NOT go Long immediately, but at 17:24 at the earliest, in case you write  ” barindex > preloadbars “.

    It will go long at 17:23 when you write ” barindex >= preloadbars ”

    Does not sound logical, but it is so. Just try it out in demo, in a 10 second chart, for example.

    1 user thanked author for this post.
    #251066

    I did not know that. Thank you !

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

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