New to PRT and PBC, so be firm and fair…

Viewing 15 posts - 16 through 30 (of 45 total)
  • Author
    Posts
  • #246715 quote
    NeoTrader
    Participant
    New

    Okey Dokey….
    So, code runs 👍

    and here come the questions….

    See attached image…
    1.It looks like I have two live trades, I think ?
    2.The orange and blue arrows – I cant find the legend to understand what they represent, or how to change the colours ?
    3.My code isn’t performing correctly, as aligning the range period with the test output (best period = chart period), my code is entering and exiting trades days after or days before !

    Any guidance, is very much appreciated during these very early days of PRT and the use of PBC (ProBuilderCode) 👍👍
    NT

    PRT-PBC-Screenshot-2025-05-02-180252.png PRT-PBC-Screenshot-2025-05-02-180252.png
    #246716 quote
    GraHal
    Participant
    Master

    No image attached in above post.

    NeoTrader thanked this post
    #246718 quote
    NeoTrader
    Participant
    New

    One of those defrost moments 😕

    #246720 quote
    GraHal
    Participant
    Master

    It’s much easier to show positions as in attached.

    Click on your System / Algo title top left of equity curve > Configure > enable Positions Indicator.

    NeoTrader thanked this post
    Tzd0UHUDI6.png Tzd0UHUDI6.png
    #246723 quote
    NeoTrader
    Participant
    New

    It’s much easier to show positions as in attached.

    Click on your System / Algo title top left of equity curve > Configure > enable Positions Indicator.

    Got that…
    But the positions graph for trade entry / exit, do not line up with the indicator and the crossover/under entry trigger (As coded)

    Also, how do I change the orange and blue colours, still not finding that one. <<< SOLVED 👍

    And what do the numbers mean 2 or 4 by the arrows?
    (It looks like I am entering two trades or even four trades at a time)

    PRT-PBC-Screenshot-2025-05-02-180252-1.png PRT-PBC-Screenshot-2025-05-02-180252-1.png
    #246725 quote
    GraHal
    Participant
    Master

    If you put the positions Indicator (as my screenshot) on your Chart you will see clearer.  I’m so used to seeing the Positions Indicator.
    Your colours don’t seem logical? It looks like you have closed a Long at a loss of 445 and then also opened a Short ?

    I take it this is on a Demo Account with virtual money … as you are testing code and getting used to the Platform etc?

    NeoTrader thanked this post
    #246727 quote
    NeoTrader
    Participant
    New

    Yep. My coding is useless, it is opening a trade, and the closing it, at the same time… which is pointless….

    The code is supposed to do the following…

    Trade entry logic (as a test)
    ——————————–
    Long: DM+ cross over DM-

    Short: DM- cross over DM+

    Trade Exit Logic
    ——————–
    1. stop loss hit
    2. opposite signal triggered. Where the open trade is closed and the opposite signal trade is entered.

    Looking at the output, that isn’t the case 😱

    I could really do with code correction advice….

    #246728 quote
    GraHal
    Participant
    Master
    Attached shows where colours for trading icons are set

    This is your working code:

    Are you using the Roberto provided code? Also, are you incorporating Roberto suggestion re MyMACD etc.
    Roberto will help I’m sure. Asking 1 or 2  specific questions / problems at a time is best.

    NeoTrader thanked this post
    Bbq8jJQHD4.png Bbq8jJQHD4.png
    #246731 quote
    NeoTrader
    Participant
    New
    Attached shows where colours for trading icons are set

    This is your working code:

    Are you using the Roberto provided code? Also, are you incorporating Roberto suggestion re MyMACD etc.

    Roberto will help I’m sure. Asking 1 or 2 specific questions / problems at a time is best.

    Got that… thank you…

    Yes, using Roberto’s code and the my* code handling, which is now amended… well, it is working better, but not resolved as per the entry and exit logic…

    Trade entry logic (as a test)
    ——————————–
    Long: DM+ cross over DM-

    Short: DM- cross over DM+

    Trade Exit Logic
    ——————–
    1. stop loss hit (OR)
    2. opposite signal triggered. Where the open trade is closed and the opposite signal trade is entered.

    Here is the revised code, any assistance to rectify the process is very much appreciated.

    // ========================================================================
    // STRATEGY: DMI-ADX Crossover with Stop Loss + Opposite Signal Exit + Delayed Re-entry
    // ========================================================================

    // === INPUTS ===
    DMIperiod = DMIPeriod // optimize from 1 to 20
    ATRperiod = 14
    ATRmultiplier = 2.5
    PositionSize = 10

    // === INDICATORS ===
    myDIplus = DIPLUS[DMIperiod]
    myDIminus = DIMINUS[DMIperiod]
    ATR = ATR[ATRperiod]

    // === SIGNALS ===
    LongSignal = myDIplus CROSSES OVER myDIminus
    ShortSignal = myDIminus CROSSES OVER myDIplus

    // === STOP LOSS DISTANCE ===
    StopLossDistance = ATR * ATRmultiplier

    // === STATE FLAGS ===
    reverseToLong = 0
    reverseToShort = 0

    // === POSITION MANAGEMENT ===
    IF LongOnMarket THEN
    // 1. Check stop loss
    IF low <= (tradeprice(1) – StopLossDistance) THEN
    SELL AT MARKET
    // 2. Check for reversal
    ELSIF ShortSignal THEN
    SELL AT MARKET
    reverseToShort = 1
    ENDIF
    ENDIF

    IF ShortOnMarket THEN
    // 1. Check stop loss
    IF high >= (tradeprice(1) + StopLossDistance) THEN
    EXITSHORT AT MARKET
    // 2. Check for reversal
    ELSIF LongSignal THEN
    EXITSHORT AT MARKET
    reverseToLong = 1
    ENDIF
    ENDIF

    // === ENTRY WHEN FLAT ===
    IF NOT LongOnMarket AND NOT ShortOnMarket THEN
    IF reverseToLong THEN
    BUY PositionSize SHARES AT MARKET
    reverseToLong = 0
    ELSIF reverseToShort THEN
    SELLSHORT PositionSize SHARES AT MARKET
    reverseToShort = 0
    ELSE
    IF LongSignal THEN
    BUY PositionSize SHARES AT MARKET
    ELSIF ShortSignal THEN
    SELLSHORT PositionSize SHARES AT MARKET
    ENDIF
    ENDIF
    ENDIF

    summary output…
    “Date” “Type” “Price” “Qty” “Value”
    “9 Jan 2020, 05:00:00” “Sell (entry)” “3,972.3” “-10” “39,723.00”
    “14 Jan 2020, 05:00:00” “Buy (exit)” “4,013.8” “10” “40,138.00”
    “26 Feb 2020, 05:00:00” “Sell (entry)” “4,241.9” “-10” “42,419.00”
    “18 Mar 2020, 04:00:00” “Buy (exit)” “4,053.6” “10” “40,536.00”
    “23 Mar 2020, 04:00:00” “Sell (entry)” “3,451.0” “-10” “34,510.00”
    “31 Mar 2020, 05:00:00” “Buy (exit)” “3,843.0” “10” “38,430.00”
    “2 Apr 2020, 05:00:00” “Sell (entry)” “3,522.3” “-10” “35,223.00”
    “7 Apr 2020, 05:00:00” “Buy (exit)” “3,839.0” “10” “38,390.00”
    “9 Apr 2020, 05:00:00” “Sell (entry)” “3,838.1” “-10” “38,381.00”
    “13 Apr 2020, 05:00:00” “Buy (exit)” “4,000.4” “10” “40,004.00”
    “16 Apr 2020, 05:00:00” “Sell (entry)” “3,635.8” “-10” “36,358.00”
    “21 May 2020, 05:00:00” “Buy (exit)” “3,359.1” “10” “33,591.00”
    “26 May 2020, 05:00:00” “Sell (entry)” “3,351.1” “-10” “33,511.00”
    “27 May 2020, 05:00:00” “Buy (exit)” “3,441.2” “10” “34,412.00”
    “12 Jun 2020, 05:00:00” “Sell (entry)” “3,283.2” “-10” “32,832.00”
    “6 Jul 2020, 05:00:00” “Buy (exit)” “3,204.3” “10” “32,043.00”

    #246750 quote
    robertogozzi
    Moderator
    Master

    Try this one (I am also attaching the ITF file):

    DEFPARAM FlatAfter = 160000
    /*
    DETrade entry logic (as a test)
    ——————————-
    Long: DM+ cross over DM-
    
    Short: DM- cross over DM+
    
    Trade Exit Logic
    ——————-
    1. stop loss hit (OR)
    2. opposite signal triggered. Where the open trade is closed and the opposite signal trade is entered.
    
    Here is the revised code, any assistance to rectify the process is very much appreciated.
    */
    
    // ========================================================================
    // STRATEGY: DMI-ADX Crossover with Stop Loss + Opposite Signal Exit + Delayed Re-entry
    // ========================================================================
    
    // === INPUTS ===
    DMIperiod     = 14 // optimize from 1 to 20
    ATRperiod     = 14
    ATRmultiplier = 2.5
    PositionSize  = 1//10
    
    // === INDICATORS ===
    myDIplus  = DIPLUS[DMIperiod]
    myDIminus = DIMINUS[DMIperiod]
    ATR       = AverageTrueRange[ATRperiod]
    
    // === SIGNALS ===
    LongSignal  = myDIplus  CROSSES OVER myDIminus
    ShortSignal = myDIminus CROSSES OVER myDIplus
    
    // === STOP LOSS DISTANCE ===
    StopLossDistance = ATR * ATRmultiplier
    // === STATE FLAGS ===
    reverseToLong  = 0
    reverseToShort = 0
    // === POSITION MANAGEMENT ===
    IF LongOnMarket THEN
    // 1. Check stop loss AND reverse
    IF low <= (tradeprice(1) - StopLossDistance) THEN
    // SHORT reversal
    SELLSHORT PositionSize SHARES AT MARKET
    ENDIF
    ELSIF ShortOnMarket THEN
    // 1. Check stop loss AND reverse
    IF high >= (tradeprice(1) + StopLossDistance) THEN
    // LONG  reversal
    BUY PositionSize SHARES AT MARKET
    ENDIF
    ELSE
    // === ENTRY WHEN FLAT ===
    IF LongSignal THEN
    BUY PositionSize SHARES AT MARKET
    ELSIF ShortSignal THEN
    SELLSHORT PositionSize SHARES AT MARKET
    ENDIF
    ENDIF
    // debugging data
    graph myDIplus  CROSSES OVER myDIminus        AS "LongSignal"   coloured("Green")
    graph myDIminus CROSSES OVER myDIplus         AS  "ShortSignal" coloured("Red")
    graphonprice TradePrice(1) - StopLossDistance AS "LONG sl"      coloured("Red")
    graphonprice TradePrice(1) + StopLossDistance AS "SHORT sl"     coloured("Blue")
    GraHal and NeoTrader thanked this post
    #246763 quote
    GraHal
    Participant
    Master

    open trade is closed and the opposite signal trade is entered.

    Try adding below at Line 39 in Roberto code posted above.

    reverseToLong  = 1
    reverseToShort = 1
    If ShortonMarket and LongSignal and reversetolong = 1 Then
    ExitShort at Market
    Endif
    
    If LongonMarket and ShortSignal and reversetoShort = 1 Then
    Sell at Market
    Endif
    robertogozzi and NeoTrader thanked this post
    #246764 quote
    GraHal
    Participant
    Master

    Tip for Neo  / Anybody … if you pres Ctrl + F5 BEFORE starting to type then you will / should see the blue ‘Insert PRT Code’ as shown at red arrowhead in attached.

    Click the blue ‘Insert PRT Code’ when you are ready to enter code (use only for code) and then your code will appear formatted as shown in my post above … so much easier to read and understand as code.

    robertogozzi thanked this post
    CycTz3ZFqX.png CycTz3ZFqX.png
    #246770 quote
    robertogozzi
    Moderator
    Master

    Try adding below at Line 39 in Roberto code posted above.

    I actually forgot to remove lines 39 and 40, as those two variables are no longer set and used.

    If you add those lines, though, the two variables will ALWAYS be true and the following instructions executed no matter what! So you have to clear them initially, then decide when they are to be set to TRUE. But, if I coded the TS correctly as planned, your suggested lines shouldn’t be needed.

    GraHal and NeoTrader thanked this post
    #246780 quote
    NeoTrader
    Participant
    New

    Try this one (I am also attaching the ITF file):

    Hi there Roberto.
    Sorry, I’ve been away the weekend…
    Thank you for the code update, just putting it through a test…

    I have amended this bit…
    DMIperiod = DMIperiod // 14 optimize from 1 to 20 [Which was // DMIperiod = 14 // optimize from 1 to 20]
    Amended as the optimisation wont run!

    NT

    #246781 quote
    NeoTrader
    Participant
    New

    Just tested the file….
    The output is blank, not sure why.

    I’ll have a go at solving now…
    And any guidance you/anyone can give is much appreciated.

    NT

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

New to PRT and PBC, so be firm and fair…


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
NeoTrader @neotrader Participant
Summary

This topic contains 44 replies,
has 6 voices, and was last updated by NeoTrader
9 months, 2 weeks ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/01/2025
Status: Active
Attachments: 9 files
Logo Logo
Loading...