Price level at which the Nth last order was executed.
Syntax:
1 |
TRADEPRICE(N) |
Example:
Example of a simple trading strategy using MACD crossing above and below the zero line with adding orders while the price continue to get higher.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
myMACD = MACD[12,26,9](close) long = myMACD crosses over 0 exit = myMACD crosses under 0 //first order IF NOT LongOnMarket AND long THEN BUY 1 CONTRACTS AT MARKET ENDIF If LongOnMarket AND exit THEN SELL AT MARKET ENDIF //let's add another order while price continue to get higher (more than 10 points) than the last order taken with a condition of 5 bars elapsed since then IF BARINDEX-TRADEINDEX(1)>5 AND Close-TRADEPRICE(1)>10 AND LongOnMarket THEN BUY 1 CONTRACTS AT MARKET ENDIF //trailing stop for the whole orders SET STOP %TRAILING 1.5 |
Can TRADEPRICE be used in some way to differentiate between the Nth long or Nth short trade? Eg. backtest/strategy placing both a long and short trade at the same time then wanting to ‘manage them’ independently (mindistance to close/grid ordering etc.)
Because it is not possible to trade long and short positions at the same time in the same strategy, you could retrieve easily what was the last order type, because it was triggered by the code itself.
Thanks Nicolas – did not realise not possible to have opposing trades running in the same strategy…
I found this in the forum which looks a good method to determine Nth previous trade ‘type’
https://www.prorealcode.com/topic/distinguishing-between-long-and-short-trades-and-long-and-short-exits/
Is there anyway to graph/print the tradeprice to the live window?
I know that PRT already displays tradeprice but I’ve worked out a way to calculate the spread of a trade but I can only display it theoretically with GRAPH in the backtest. If only there was a way to graph/print to the live window.
let the backtest run during your live session, it will continue in real time until you stop it.
I guess so – this is sort of a solution.