Tradeprice query
Forums › ProRealTime English forum › ProOrder support › Tradeprice query
- This topic has 1 reply, 2 voices, and was last updated 2 hours ago by
Iván.
-
-
10/08/2025 at 10:04 AM #252332
I want to code an application building up a short position (sellshort) to say CountOfPosition = 5.
Position 1 opened at start of application the subsequent trades opened following an increment above Tradeprice.
So far so good.
If the market falls the short positions are scaled out of incrementally (Exitshort).
New short positions are entered if the market rises again again an increment above Tradeprice.
My query.
If there has been an ExitShort (and this is the last most recent action) is TradePrice readjusted to this level (of the Exitshort) or does it stay at the level of the
previous Sellshort.A broader question is how possible is it to “watch” variables as the code is executing to see how the variables are changing.
Thank you.
10/13/2025 at 4:23 PM #252554Following up on your questions about POSITIONPRICE and how to monitor variables, sometimes the best way to understand the concepts is with a complete, practical code example.
The code below is a full trading system for a LONG position that scales into the trade on pullbacks. Although it’s a long strategy, you can apply the exact same principles in reverse to build the SHORT system you described.
How the Code Works:
1)Initial Entry: The system enters a buy order only on the bar where the ema20 crosses over the ema100.
2)Static Levels: At the moment of entry, it calculates all future entry and exit levels based on the ATR (E1-E4, TP1-TP4, stoploss). These levels remain fixed for the entire duration of the trade.
3)Scaling-In: If the price pulls back to the predefined entry levels (E1, E2, etc.), the system adds more contracts to the position.
4)State Management: A variable n is used to count how many contracts have been added, ensuring the scaling-in happens in an orderly manner.Key Takeaways for Your Questions
This example directly demonstrates the solutions to your original queries:
1)How to “Watch” Variables: The code uses graphonprice to draw all the calculated price levels and graph n to plot the number of open contracts. This is the most effective way to visualize your system’s internal logic and debug it.
2)POSITIONPRICE Behavior: We’ve specifically included the line graphonprice positionprice …. When you apply this to a chart, you will see a fuchsia line representing the average position price. Notice that this line only moves when a new buy order is executed.1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677// --- INDICATORS ---ema20 = average[20,1](close)ema100 = average[100,1](close)// --- STRATEGY LOGIC ---// Initial entry conditionif not onmarket and ema20 crosses over ema100 then// Calculate all levels ONCE at the time of entryatr = averagetruerange[14](close)stoploss = close - 5 * atrE1 = close - 1 * atrE2 = close - 2 * atrE3 = close - 3 * atrE4 = close - 4 * atrtakeprofit = close + 5 * atrTP1 = close + 4 * atrTP2 = close + 3 * atrTP3 = close + 2 * atrTP4 = close + 1 * atr// Execute first trade and set initial stops/targetsbuy 1 contract at marketset stop price stoplossset target price takeprofit// Initialize state countern = 1elsif not onmarket then// Reset counter if not in a traden = 0endif// Scaling-in logic when a position is already openif onmarket thenif n = 1 and close < E1 thenbuy 1 contract at marketn = 2set target price TP1 // Adjust targetelsif n = 2 and close < E2 thenbuy 1 contract at marketn = 3set target price TP2elsif n = 3 and close < E3 thenbuy 1 contract at marketn = 4set target price TP3elsif n = 4 and close < E4 thenbuy 1 contract at marketn = 5set target price TP4endifendif// --- VISUALIZATION (DEBUGGING) ---// Draw the average position price on the chartif onmarket thengraphonprice positionprice as "position price" coloured("fuchsia")endif// Draw all calculated entry and exit levelsgraphonprice takeprofit as "take profit" coloured("blue")graphonprice TP1 as "TP1" coloured("blue",200)graphonprice TP2 as "TP2" coloured("blue",160)graphonprice TP3 as "TP3" coloured("blue",120)graphonprice TP4 as "TP4" coloured("blue",90)graphonprice stoploss as "Stop Loss" coloured("red")graphonprice E1 as "E1" coloured("orange",200)graphonprice E2 as "E2" coloured("orange",160)graphonprice E3 as "E3" coloured("orange",120)graphonprice E4 as "E4" coloured("orange",90)// Plot the number of open contracts in a separate panelgraph n as "Contracts (n)" -
AuthorPosts
Find exclusive trading pro-tools on