Hello,
my code gets AT MARKET and AT LIMIT entry orders: how to report (could be using print) the amount of each in a backtest?
is there a special command which directly states the entry type? (and similarly for the exits)
thank you
I moved your topic from the French forum to the English forum, as you used the English language. Please stick to the correct language or to the correcty forum. Thanks 🙂
The PRT language only reports if either a LONG or a SHORT trade has been triggered, so you have to code it yourself.
Luckily this is not too difficult.
- You have to set a variable in one of the initial lines (after any DEFPARAM… you may be using);
- let’s name it TradeType, assigning it 1 when it’s a trade opened AT MARKET or, say, 2 if it was a PENDING order;
- use IF..ENDIF to detect which type it was and process it before that variable is cleared for future trades;
- clear the variable, setting it to 0 (zero);
- set the variable to 1 or 2 whenever you open a trade AT MARKET or place a PENDING order.
This is a sample code:
ONCE TradeType = 0 // used to tell a type from another
ONCE PendingCount = 0 // used to tally pending trades (stop or limit)
ONCE MarketCount = 0 // used to tally market orders
// --- detect the type of trade entered
IF TradeType = 1 THEN
MarketCount = MarketCount + 1
ELSIF TradeType = 2 THEN
IF LongTriggered OR ShortTriggered THEN
PendingCount = PendingCount + 1
ENDIF
ENDIF
TradeType = 0 // clear it before a new market trade is entered or a pending order is placed
//
myLongMarketConditions = close CROSSES OVER average[21,0](close)
myShortMarketConditions = close CROSSES UNDER average[21,0](close)
myLongPendingConditions = Rsi[14] CROSSES OVER 50
myShortPendingConditions = Rsi[14] CROSSES UNDER 50
//
IF myLongMarketConditions AND Not OnMarket THEN
BUY 1 CONTRACT AT MARKET
TradeType = 1 // it's a market order
SET STOP pLOSS 50
SET TARGET pPROFIT 200
ELSIF myShortMarketConditions AND Not OnMarket THEN
SELLSHORT 1 CONTRACT AT MARKET
TradeType = 2
SET STOP pLOSS 50
SET TARGET pPROFIT 200
TradeType = 1 // it's a market order
ELSIF myLongPendingConditions AND Not OnMarket THEN
myLongPrice = high * 1.01 // enter at high + 1%
BUY 1 CONTRACT AT myLongPrice STOP
TradeType = 2 // it's a pending order
SET STOP pLOSS 50
SET TARGET pPROFIT 200
ELSIF myShortPendingConditions AND Not OnMarket THEN
myShortPrice = low * 0.99 // enter at low - 1%
SELLSHORT 1 CONTRACT AT myShortPrice STOP
TradeType = 2 // it's a pending order
SET STOP pLOSS 50
SET TARGET pPROFIT 200
ENDIF
//
graph PendingCount AS "Pending Orders" coloured("Cyan")
graph MarketCount AS "MarketOrders" coloured("Fuchsia")