New to PRT and PBC, so be firm and fair…
Forums › ProRealTime English forum › ProOrder support › New to PRT and PBC, so be firm and fair…
- This topic has 44 replies, 6 voices, and was last updated 1 month ago by
NeoTrader.
-
-
05/02/2025 at 6:04 PM #246715
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) 👍👍
NT05/02/2025 at 6:06 PM #24671605/02/2025 at 6:08 PM #24671805/02/2025 at 6:49 PM #24672005/02/2025 at 8:10 PM #246723It’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)05/02/2025 at 8:20 PM #246725If 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?
1 user thanked author for this post.
05/02/2025 at 8:30 PM #246727Yep. 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….
05/02/2025 at 8:42 PM #246728Attached shows where colours for trading icons are setThis 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.1 user thanked author for this post.
05/02/2025 at 9:37 PM #246731Attached shows where colours for trading icons are setThis 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
ENDIFIF 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
ENDIFsummary 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”05/03/2025 at 3:16 PM #246750Try this one (I am also attaching the ITF file):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566DEFPARAM 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 20ATRperiod = 14ATRmultiplier = 2.5PositionSize = 1//10// === INDICATORS ===myDIplus = DIPLUS[DMIperiod]myDIminus = DIMINUS[DMIperiod]ATR = AverageTrueRange[ATRperiod]// === SIGNALS ===LongSignal = myDIplus CROSSES OVER myDIminusShortSignal = myDIminus CROSSES OVER myDIplus// === STOP LOSS DISTANCE ===StopLossDistance = ATR * ATRmultiplier// === STATE FLAGS ===reverseToLong = 0reverseToShort = 0// === POSITION MANAGEMENT ===IF LongOnMarket THEN// 1. Check stop loss AND reverseIF low <= (tradeprice(1) - StopLossDistance) THEN// SHORT reversalSELLSHORT PositionSize SHARES AT MARKETENDIFELSIF ShortOnMarket THEN// 1. Check stop loss AND reverseIF high >= (tradeprice(1) + StopLossDistance) THEN// LONG reversalBUY PositionSize SHARES AT MARKETENDIFELSE// === ENTRY WHEN FLAT ===IF LongSignal THENBUY PositionSize SHARES AT MARKETELSIF ShortSignal THENSELLSHORT PositionSize SHARES AT MARKETENDIFENDIF// debugging datagraph 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")05/04/2025 at 2:38 PM #246763open trade is closed and the opposite signal trade is entered.
Try adding below at Line 39 in Roberto code posted above.
123456789reverseToLong = 1reverseToShort = 1If ShortonMarket and LongSignal and reversetolong = 1 ThenExitShort at MarketEndifIf LongonMarket and ShortSignal and reversetoShort = 1 ThenSell at MarketEndif2 users thanked author for this post.
05/04/2025 at 2:44 PM #246764Tip 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.
1 user thanked author for this post.
05/04/2025 at 5:31 PM #246770Try adding below at Line 39 in Roberto code posted above.
123456789reverseToLong = 1reverseToShort = 1If ShortonMarket and LongSignal and reversetolong = 1 ThenExitShort at MarketEndifIf LongonMarket and ShortSignal and reversetoShort = 1 ThenSell at MarketEndifI 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.
05/04/2025 at 7:37 PM #246780Try this one (I am also attaching the ITF file):
Press CTRL+C to Copy, CTRL+V to Paste123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566DEFPARAM 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 20ATRperiod = 14ATRmultiplier = 2.5PositionSize = 1//10// === INDICATORS ===myDIplus = DIPLUS[DMIperiod]myDIminus = DIMINUS[DMIperiod]ATR = AverageTrueRange[ATRperiod]// === SIGNALS ===LongSignal = myDIplus CROSSES OVER myDIminusShortSignal = myDIminus CROSSES OVER myDIplus// === STOP LOSS DISTANCE ===StopLossDistance = ATR * ATRmultiplier// === STATE FLAGS ===reverseToLong = 0reverseToShort = 0// === POSITION MANAGEMENT ===IF LongOnMarket THEN// 1. Check stop loss AND reverseIF low <= (tradeprice(1) – StopLossDistance) THEN// SHORT reversalSELLSHORT PositionSize SHARES AT MARKETENDIFELSIF ShortOnMarket THEN// 1. Check stop loss AND reverseIF high >= (tradeprice(1) + StopLossDistance) THEN// LONG reversalBUY PositionSize SHARES AT MARKETENDIFELSE// === ENTRY WHEN FLAT ===IF LongSignal THENBUY PositionSize SHARES AT MARKETELSIF ShortSignal THENSELLSHORT PositionSize SHARES AT MARKETENDIFENDIF// debugging datagraph 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”)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
05/04/2025 at 7:40 PM #246781 -
AuthorPosts
Find exclusive trading pro-tools on