One-time buy Signal at System Start

Viewing 15 posts - 16 through 30 (of 46 total)
  • Author
    Posts
  • #239794 quote
    JS
    Participant
    Senior

    When I use 10k units, it works well …?

    Scherm­afbeelding-2024-10-30-om-14.44.32.png Scherm­afbeelding-2024-10-30-om-14.44.32.png
    #239797 quote
    stalba
    Participant
    New
    Really sorry, I have no clue why but my backtest doesn’t match yours… it misses a signal and I get stopped out.
    backtest-code.png backtest-code.png
    #239800 quote
    JS
    Participant
    Senior
    I think I know why this happens. When the first position is opened, and within 36 units an opposite position should be opened by the indicator, it goes wrong because the indicator hasn’t had time to configure itself yet. You can solve this by using the period of the supertrend (36 units) as “PreLoadBars.” So use: DefParam PreLoadBars=36
    stalba thanked this post
    Scherm­afbeelding-2024-10-30-om-15.18.14.jpg Scherm­afbeelding-2024-10-30-om-15.18.14.jpg
    #239804 quote
    stalba
    Participant
    New
    This fixed it – thanks a lot 🙏🏼 been looking for a solution for this for a while now!
    JS thanked this post
    #239962 quote
    stalba
    Participant
    New
    I’ve tried this code now with (DEMO) auto trading, but it doesn’t open a position, not on the system start, not the next day, also not the day after… does anyone know what the reason could be? When i use this code for backtesting, it works fine!
    // Set code parameters
    DEFPARAM PreLoadBars = 100
    DEFPARAM CumulateOrders = False // Prevents multiple entries
     
    ONCE EntryFlag = 0  // Initialization for one-time entry
    superTrendValue = SuperTrend[5.4,36]
     
    // Check if there is no position at the start and EntryFlag is 0
    IF NOT ONMARKET AND EntryFlag = 0 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
     
    // Long Conditions
    IF NOT LONGONMARKET and close CROSSES OVER superTrendValue THEN
    BUY 1 CONTRACT AT MARKET // Long Entry
    EntryFlag = 1  // Set the flag to avoid re-triggering
    ELSIF LONGONMARKET and close CROSSES UNDER superTrendValue THEN
    SELL AT MARKET // Long Exit
    EntryFlag = 1 // Set the flag to avoid re-triggering
    ENDIF
     
    // Short Conditions
    IF NOT SHORTONMARKET AND close CROSSES UNDER superTrendValue THEN
    SELLSHORT 1 CONTRACT AT MARKET // Short Entry
    EntryFlag = 1  // Set the flag to avoid re-triggering
    ELSIF SHORTONMARKET and  close CROSSES OVER superTrendValue THEN
    EXITSHORT AT MARKET // Short Exit
    EntryFlag = 1 // Set the flag to avoid re-triggering
    ENDIF
    #239963 quote
    PeterSt
    Participant
    Master
    Undoubtedly PreLoadBars. It would be the only thing that matters for Backtest vs Demo (or Live for that matter). Hence, your SuperTrend can’t cope with the 100 bars 0nly. ?   PS: I see that JS already gave the same response to earlier posts. Still I think my text applies.
    stalba thanked this post
    #239966 quote
    stalba
    Participant
    New
    Hi Peter, with JS the last solution was to use at least PreLoadBars = 36, I’ve increased it to 100 for backtesting, it works. I have tested the system now with 1000 bars, in a 5 min. timeframe (in hope to see sooner results if the position would be opened at the next bar) but nothing happens (screenshot attached). As I am a very beginner at this, it might just be a basic setting but I just can’t figure it out.
    autotrading.jpg autotrading.jpg
    #239968 quote
    stalba
    Participant
    New
    Just to clarify my goal here: I’m aiming for an immediate entry into a long or short position (I’d adjust the code accordingly) as soon as I start the auto trading system, without having to wait for the next signal. We’ve only increased the PreLoadBars to ensure that the first signals from the SuperTrend indicator are accurately interpreted AFTER the immediate entry.
    #239969 quote
    GraHal
    Participant
    Master
    I’m aiming for an immediate entry into a long or short position
    Below on Lines 9,10 and 11 of the most recent posted code will (should?) give you above (you adjust for Short or Long as you think fit when you start your Algo). Tell us what is not happening if not above?
    IF NOT ONMARKET AND EntryFlag = 0 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    stalba thanked this post
    #239973 quote
    stalba
    Participant
    New
    Yes that’s what the code SHOULD do, and it works when I do backtesting but when I start auto trading (in Demo mode), nothing happens – no matter what timeframe i use, no positions are being opened (see screenshot attached). The system was also active for a couple of days with a 1 day timeframe, in case it opens a position at the next candle/day, but still nothing happened.
    GraHal thanked this post
    autotrading-1.jpg autotrading-1.jpg
    #239975 quote
    GraHal
    Participant
    Master
    I will try it on my Demo and Ill report back.
    stalba thanked this post
    #239976 quote
    GraHal
    Participant
    Master
    I started it on DJI on 1 min TF and 2 bars have formed, but no position opened so I confirm / supprt what you are saying. I will make a change to see if I can get it going.
    stalba thanked this post
    #239977 quote
    GraHal
    Participant
    Master
    Below works … see attached. Maybe somebody can tell us why??
    // Set code parameters
    DEFPARAM PreLoadBars = 100
    DEFPARAM CumulateOrders = False // Prevents multiple entries
     
    ONCE EntryFlag = 0  // Initialization for one-time entry
    superTrendValue = SuperTrend[5.4,36]
     
    // Check if there is no position at the start and EntryFlag is 0
    IF EntryFlag =0 THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    Screenshot-2024-11-05-111722.png Screenshot-2024-11-05-111722.png
    #239978 quote
    JS
    Participant
    Senior
    Hi, “PreLoadBars” does not determine the number of bars over which the backtest is conducted, but rather the number of bars loaded before the backtest is performed. (The number of bars for your backtest is determined by the amount of “units” in your chart) If you use “PreLoadBars=36” as discussed, it should work fine… Opening the first position depends on your timeframe: if you use 1 day, the first position will open after 1 day, and if you use a 5-minute timeframe, then after 5 minutes…
    inverse thanked this post
    #239981 quote
    GraHal
    Participant
    Master
    Thanks JS, but first position didn’t open at all (see my ss) until I deleted ‘Not onmarket’ as  I posted.
Viewing 15 posts - 16 through 30 (of 46 total)
  • You must be logged in to reply to this topic.

One-time buy Signal at System Start


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
stalba @stalba Participant
Summary

This topic contains 45 replies,
has 6 voices, and was last updated by PeterSt
1 year, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/29/2024
Status: Active
Attachments: 20 files
Logo Logo
Loading...