Here is a new list of instructions specific to order management in automatic trading, which should greatly improve your programming.
Largely inspired by the many support requests and remarks gleaned over the years on the forum, I’m sure you’ll appreciate these, so much they will simplify the setting of breakeven or the placement of stops for example.
I’ve been testing them for a few weeks in beta and it works very well 🙂
Here is the list:
- ShortTriggered[N] / LongTriggered[N] : Allows to know if a Short / Long position has been opened on the candlestick N (optional N by default at 0)
Useful to know when an order has been opened and its stop / profit has been triggered on the same candlestick, especially in the case of a WO position opening.
- Set Stop Breakeven : Allows you to set a protective stop at the entry price of the current position, avoids the use of a closing WO.
- Set Stop Price X : Allows to set a stop at a price X defined directly by the user and not in relation to the entry price of the position.
- Set Stop pProfit/%Profit/$Profit/Profit X : Allows to set a stop at X points / % / € / unit above the entry price of the position.
- Set target Breakeven : Allows to set a profit limit at the entry price of the current position, avoids the use of closing WO.
- Set target Price X : Allows to set a profit limit at a price X defined directly by the user and not in relation to the entry price of the position.
- Set target ploss/%loss/$loss/loss X : Allows to set a limit at X points / % / € / unit below the entry price of the position.
(WO states for Working Orders, also known as “pending orders”)
All these instructions are now available for any version of the platform, enjoy!
ShortTriggered[N] / LongTriggered[N] examples:
Orders count, limit orders to X for today:
once MaxOrders = 5
//reset orders count
if intradaybarindex=0 then
orderscount=0
endif
//check if an order has opened in the current bar
if longtriggered then
orderscount=orderscount + 1
endif
if not longonmarket and orderscount<MaxOrders then
buy 1 contract at high stop
set target pprofit 20
set stop ploss 10
endif
All these new instructions have now been added in our online documentation for ProOrder/ProBacktest. Direct links for each of them are available in the above post.
Set Stop Breakeven example:
Put my long order at breakeven (stoploss at entry price) if price is above the entry price (in profit) since 10 bars:
inprofit = lowest[10](low)>tradeprice
if inprofit and longonmarket then
set stop breakeven
endif
Set Stop Price example:
Stoploss at 5-bars lowest low at order launch:
if buycondition and not longonmarket then
buy 1 contract at market
set stop price lowest[5](low)
endif
Trailing stop profit example made with Set Stop Price:
Trailing Profit Target
I have a question about that. Would this feature replace all the trailing stopcodes that exist?
No, they do not replace them, these new instructions make things easier!
For instance, no need to take care of continuously put a pending stop order at breakeven with a soft code version (countless codes about that in the forums!), just use the new SET STOP BREAKEVEN, and the server will take care of the rest when dealing with the broker.
Same goes with SET TARGET or SET STOP at PRICE.