Rule Scripting - Commands
Available commands and their parameters are shown. Commands appears as the 5th element of a logic line. Note, there are special commands of AND and OR that control how logic lines are joined together. Commands should be specified with any parameters in brackets and multiple parameters should be separated by a semi-colon.
- AI_CMD: Request AI check using supplied prompt
- promptRef: Reference of prompt to use
- flags: If contains M then AI check is for managing open trade in direction being evaluated
- ALERT: Raise alert via the configured methods
- text: Text to appear in the alert. Use \n for a new line.
- ALERT_LOCAL: Raise MetaTrader pop-up alert only, regardless of configured alert methods
- text: Text to appear in the alert. Use \n for a new line.
- BROKER_PEND: Set broker pending order using current lots for trade
- price: Price of pending order
- sl: Stop loss price, if supplied
- tp: Take profit price, if supplied
- expiration: Expiry time in seconds since EPOC, if supplied
- CHART_SET: Change chart symbol and/or timeframe
- symbol: Symbol to change chart to. If blank then symbol not changed.
- timeframe: Timeframe to change chart to, e.g. H1. If blank then timeframe not changed.
- CLEAR_BREAKEVEN: Turn off break even for trade
- CLEAR_TRADE_JUST_OPENED_ANY: Clears the flag returned by t.justOpenedAny for direction being evaluated
- CLEAR_TRAIL: Turn off trailing of stop loss for trade
- CLOSE_MULTI: Close multiple trades on the account
- symbol: Symbol of trades to close. If not supplied or set to <ALL> then will close trades on the account.
- flags: If set to HLF then will close largest trade first, else will use FIFO principles. If set to TRADE then will only close trade with magic number of trade index currently being evaluated. If MTO then will limit close to managed trades only, i.e. with magic numbers that the EA manages. If DIR then will only close trades in direction being evaluated. Note, will also do MTO if EA input Gen_accountManagedTradesOnly is set to true.
- magicNum: If supplied then will only close trades with this magic number
- magicNumEnd: If supplied then will close range of magic numbers from magicNum up to this value
- END_EVAL: End evaluation of the rule. This can be useful if there are some initial checks, which if fail means no need to carry on evaluating the rest of the rule.
- commentText: Optional fail comment that can be used for logging and display to explain why rule evaluation ended
- FILE_ADD: Add line of text to file opened with FILE_OPEN
- text: Text to add
- FILE_CLOSE: Close file opened with FILE_OPEN
- FILE_OPEN: Open text file for writing, ready for FILE_ADD
- fileName: Name of file, which will be in MetaTrader's Files folder
- FILTER_ENTRY: Turn filter on to prevent automated entry
- label: Label for filter which should be different to other filters. Used for status text.
- FILTER_EXIT: Turn filter on to prevent automated exit
- label: Label for filter which should be different to other filters. Used for status text.
- FORCE_CLOSE: Currently same as TRADE_CLOSE, but intended where have exit on/off control on panel and want to force close through if this control is set to on
- prctToClose: Percentage of original trade to close. If blank then percentage set on panel is used.
- GUI_SET: General purpose set of GUI control to supplied value
- refID: Reference ID of GUI control, excluding any xxxx. qualifier
- value: Value to set GUI control to, e.g. text or for tick box 1 or 0
- GUI_SET_BUTTON: Set button text of GUI control to supplied value
- refID: Reference ID of GUI control, excluding button.
- text: Text to set button to, if blank then text will not be adjusted
- color: Color to set set button text to, if blank then color will not be adjusted
- GUI_SET_LABEL: Set rule GUI label for display on panel
- refID: Reference ID of GUI control, excluding label.
- text: Text to set label to
- color: Color of label, if blank then color will not be adjusted
- fontSize: Font size for label, if blank then will not be adjusted
- GUI_SET_LISTBOX: Set rule GUI list box control to supplied text
- refID: Reference ID of GUI control, excluding listBox.
- text: Text that GUI control is to be set to
- GUI_SET_TEXTBOX: Set rule GUI text box control to supplied text
- refID: Reference ID of GUI control, excluding textBox.
- text: Text that GUI control is to be set to. Will be blanked if not supplied.
- GUI_SET_TICKBOX: Set rule GUI tick box control to supplied value
- refID: Reference ID of GUI control, excluding tickBox.
- value: Put 1 to for tick or 0 for unticked
- HIDDEN_TP_RECALC: Recalculate hidden take profit prices
- riskPips: Risk in pips to base calculation on. If not supplied then current risk is used.
- openPrice: Open price to base calculation on. If not supplied then current open price is used.
- LOG_ADD: Add information to trade log in tag=value format
- tag: Tag to appear in log
- value: Value to appear with tag
- LOOP_END: If rule has been specified in loop mode (where t.loopIdx increases as rule is executed again) then allows the loop to end
- LOOP_TRADE_END: If in multi-trade mode then will exit trade index loop through the allocated magic numbers
- MESSAGE_CONFIRM: Show confirmation message box and end rule evaluation if user presses Cancel
Only shown if rule has been manually requested, e.g. by clicking GUI button, and EA input Rules_ignoreMessageConfirm is false. - text: Message to show. If not supplied then a default confirmation message is shown.
- flags: If Cancel pressed then L will continue rule loop and T will continue trade index loop
- OBJ_CREATE: Allows rule scripting to create objects that appear on the chart, e.g lines, text, etc.
- name: Object name, must be unique. A rwfx specifier will be added to the start of name, so the object will be auto deleted if EA removed from the chart.
- type: Type of object. One of VLINE, HLINE, TREND, TEXT, LABEL, FIBO, RECTANGE, RECTANGE_LABEL, TRIANGLE, ARROW, ARROW_UP, ARROW_DOWN, BITMAP, ARROW_THUMB_UP, ARROW_THUMB_DOWN, ARROW_BUY, ARROW_SELL, ARROW_LEFT_PRICE, ARROW_RIGHT_PRICE
- xOffset: X offset to position object
- yOffset: Y offset to position object
- corner: Corner of chart to position object. One of LU, LL, RL, RU or if block around panel can be A or B.
- text: Text to set object description to
- color: Color to set object to. If blank then color not adjusted.
- fontSize: Font size. If blank then not adjusted.
- fontName: Font name. If blank then not adjusted.
- OBJ_SET: Sets object property to supplied value
- name: Object name
- propertyID: Property numerical ID. See Value column of: https://docs.mql4.com/constants/objectconstants/enum_object_property
- value: Value to set object property to
- OBJ_SET_COLOR: Set color and optionally style of object
- name: Object name
- color: Color to set object to
- style: Style, e.g of line, to set object to. If blank then won't be adjusted. Set to numerical value for style. See Value column of: https://docs.mql4.com/constants/indicatorconstants/drawstyles
- OBJ_SET_FIB: Set Fibonacci object
- name: Object name
- levels: Number of levels to set object to, if supplied
- time1: Time1 to set object to. Either seconds since EPOC, or if negative value then number of bars/candles back. If blank then will use 5 bars/candles back.
- time2: Time2 to set object to as seconds since EPOC. If not supplied or blank then will use current time.
- price1: Price 1 to set object to. Only set if supplied.
- price2: Price 2 to set object to. Only set if supplied. Will set price 1 to same value if price 1 was not supplied.
- level0Text: Text to set level 0 to, if supplied
- level0Color: Color to set level 0 to, if supplied
- level0Width: Width to set level 0 to, if supplied
- OBJ_SET_FONT: Set object font name and/or size
- name: Object name
- fontSize: Size of font. If blank then won't be adjusted.
- fontName: Name of font. If blank then won't be adjusted.
- OBJ_SET_POSITION: Set X/Y position of object
- name: Object name
- xOffset: X offset to position object
- yOffset: Y offset to position object
- corner: Corner of chart to position object. One of LU, LL, RL, RU or if block around panel can be A or B. If not supplied then X/Y distance set directly without reference to corner.
- OBJ_SET_PT: Set price and time of object
- name: Object name
- price: Price to set object to. If blank and time supplied then price will not be adjusted.
- time: Time to set object to, in seconds from EPOC
- price2: If supplied, will set Price 2 of object to this
- time2: If supplied will set Time 2 of object to this
- OBJ_SET_PTO: Set price and time of object with pixel offset
- name: Object name
- price: Price to set object to, if supplied
- time: Time to set object to, in seconds since EPOC, if supplied
- pixelOffset: Number of pixels to offset from supplied price, added if buy
- OBJ_SET_TEXT: Set text of object and optionally color
- name: Object name
- text: Text to set object to, if specified
- color: Color to set object to, if specified
- OBJ_SWAP_COLOR: Allows object color to be changed if matches supplied value
- name: Object name
- fromColor: Color object must currently have
- toColor: Color to set object to if current has fromColor
- PEND_CANCEL: Cancel pending order
- scope: Can be ALL for all trade indexes and directions, REST like ALL but not selected trade index, OTHER for other direction, BOTH for both directions.
- PEND_DISABLE: Disable pending order but still show
If pending order is disabled then if hit it will be cancelled but no other action will be taken. Only works with hidden pending orders. - PEND_ENABLE: Will re-enable previous disabled pending order, so that will be actioned when price is reached
- PLAY_SOUND: Play sound file
- fileName: Sound file name, e.g. alert.wav. If not supplied then any playing sound is stopped.
- PRINT: Outputs supplied text to Experts log that appears in the Experts tab
- text: Text to outputted
- RESET_ALERT: Resets alert/trade status so is ready for next trade. Will set t.alertPrice to -1 to signify this. Used to ensure system only trades on a fresh/new signal.
- flags: If set to ALL then will reset all trade indexes (magic numbers), when in multi-trade mode
- RESET_ALERT_OPP: As RESET_ALERT command but resets opposite direction
- flags: If set to ALL then will reset all trade indexes (magic numbers) of opposite direction, when in multi-trade mode
- SCALE_IN: Scale-in trade. Will open an addition ticket in order to increase your position in a current trade.
- prct: Percentage of original trade to be scaled-in by in total, e.g. 20 will open an additional 20% of the original lot size. To scale in further, would need to increase this percentage further. If supply value with + then will add the scale-in % already performed.
- lots: Lots to scale-in by, used instead of prct, which should be left blank
- SCREENSHOT: Take screenshot of chart
- fileName: File name for screenshot. If not supplied then default file name is used.
- SEND_EVENT: Send event to other runwiseFX EAs, which can be received with t.eventStr and t.eventLong
- eventStr: String value to send with event
- eventLong: Long (integer) value to send with event
- SEND_EVENT_DIR: As SEND_EVENT but event is for direction being evaluated
- eventStr: String value to send with event
- eventLong: Long (integer) value to send with event
- SEND_EVENT_DIR_OPP: As SEND_EVENT but event is for opposite direction to the one being evaluated
- eventStr: String value to send with event
- eventLong: Long (integer) value to send with event
- SEND_MAIL: Send email via MetaTrader email settings
- subject: Subject of email
- body: Body of email
- SEND_MAIL_VIA_GUI: Send email via runwiseFX GUI application
- subject: Subject of email
- body: Body of email
- extra: Optional additional email detail
- SEND_NOTIF: Send push notification to MetaTrader mobile app
- text: Text of notification
- SET_AUTO_MODE: Set auto entry mode for direction being evaluated
- mode: Auto entry mode, one of MAN, EVL, ALT, TOE, TOA or TC
- scope: BOTH for both directions, ALL for all trade indexes and directions, or BROADCAST as ALL but also sends to other runwiseFX EAs
- SET_BREAKEVEN: Set trade for break even, i.e. will exit when profit falls back to break even
If trade is not yet in profit then break even will only apply once profit has risen above break even, unless STRICT is supplied, in which case trade will exit immediately if below break even. - flags: Set to STRICT to apply break even even if trade not currently in profit
- SET_CONFIG: Set configuration value
- cfgIdx: Numeric index of configuration value to set
- value: Value to set configuration value to
- SET_HIDDEN_SL: Set hidden (virtual/stealth/soft) stop loss
Note, this is the stop loss that is used for the risk calculation. If mode is not supplied, or not MAN or OFF, then the price is used as the calculated stop loss, e.g. for stop loss mode RULE, with the configured stop loss offset applied. - price: Price to set stop loss to
- mode: Stop loss mode to set, e.g. RULE. If MAN or OFF then price is set directly as a manual stop loss.
- SET_HIDDEN_SL_MODE: Set hidden stop loss mode and recalculate stop loss price
- mode: Stop loss mode to set, e.g. AUTO
- flags: If set to UOO then stop loss is recalculated using original open price rather than current price
- SET_HIDDEN_TP: Set hidden (soft) take profit price for supplied level
- level: Level to set. By default this is value between 1-4 for each of the take profit boxes.
- price: Price to set take profit to. If blank then level will be set automatically.
- flags: If set to FORCE:ONLY then this will be the only take profit level, set to exit 100% of the trade
- SET_HIDDEN_TP_MASTER: Turn take profit master setting on or off for direction being evaluated
- value: Set to 1 for on or 0 for off
- SET_HIDDEN_TP_PRCT: Set percentage of trade to exit when hidden take profit level is reached
- level: Level to set. By default this is value between 1-4 for each of the take profit boxes.
- exitPrct: Percentage of original trade to exit. If blank then exit is disabled for level.
- SET_HIDDEN_TP_RRR: Set hidden take profit level using risk reward ratio or pips
- level: Level to set. By default this is value between 1-4 for each of the take profit boxes.
- rrr: Risk reward ratio, or prefix with p for pips, e.g. p20, or rr for risk reward ratio, e.g. rr1.5. If blank then auto set is turned off for level.
- flags: If set to FORCE:ONLY then this will be the only take profit level, set to exit 100% of the trade
- SET_HIDDEN_TP_SLM: Set stop loss mode to apply when hidden take profit level is reached
- level: Level to set. By default this is value between 1-4 for each of the take profit boxes.
- slMode: Stop loss mode to apply when level is reached
- SET_LOCAL: Sets local variable that just has scope of current rule evaluation
- index: Index from 0-39 to say which variable is to be set
- value: Value to set local variable to. Can be alphanumeric.
- inc: If supplied, then giva an increment to add to the supplied value. Will assume value and inc are integer numbers.
- SET_LOTS: Set lots for direction being evaluated, as shown on panel
- lots: Lots to set, which will be normalised to the account's lot step
- SET_PEND: Set hidden pending order for direction being evaluated
Order type, e.g. stop or limit, is worked out from where price is relative to the current price. If a trade is already open then pending order will be a scale-in. - price: Price to set pending order to. If blank then price not adjusted.
- action: Action or blank if not to be adjusted. If set can be AT = alert on price reached, TT = trade when price reached, AC = alert when price closed beyond, TC = trade when price closed beyond.
- SET_PEND_OPP: As SET_PEND but for opposite direction, e.g. for setting bracketed pending orders
- price: Price to set pending order to. If blank then price not adjusted.
- action: Action to take when pending price is reached
- SET_PEND_PRICE: Adjust price of existing pending order
Price will only be adjusted if it stays on the same side of the current price, unless pending price has just been initialised. - price: Price to set pending order to
- SET_RISK: Set risk for direction being evaluated, as shown on panel
- risk: Risk to set
- SET_TRAIL: Turn on trailing of stop loss for trade
- SET_VAR: Set MetaTrader global variable or EA internal variable
- name: Variable name. Will add rwfx marker and symbol, unless ! supplied before name. If starts with # followed by 0-39 then will use internal EA variable, where numeric gives index. Note, internal EA variable values are stored per direction, unless input Main_variableIdxPerDirection is set to true, or flags is set to BOTH.
- value: Value to set varible to. For MetaTrader global variables this needs to be numeric.
- symbol: If global variable then provides symbol, if specified. If * provided then will set for all symbols. If set to .. then will use chart symbol concatenated with the chart period, e.g. EURUSDM30.
- flags: If set to TEMP then will set global variable to temp kind, which is forogotten when MetaTrader closes. If set to BOTH then for internal variable will set value for both directions.
- SIGNAL_SET: Sets signal price and time and will reset opposite direction if 'Auto reset on opposite signal' is ticked in CONFIG | General Settings
- price: Signal price. If blank then current bid price is used.
- SYNC_TICK: Wait until tick from another program, e.g. indicator, matches this EA's tick, for up to approx. 1.5 seconds
- objName: Name of chart object whose text holds the other program's time|volume|timestamp
- TEST_OPEN: Open test trade directly with broker, with 25 pip stop loss and 35 pip take profit, for testing purposes
- lots: Lots for test trade
- magicNum: Magic number for test trade
- symbol: Symbol for test trade
- sleepMs: Milliseconds to wait before setting stop loss and take profit, if supplied
- TRADE_CLOSE: Close or partially close trade. If auto exit mode is set the ALT then will just alert exit.
- prctToClose: Percentage of original trade to close, e.g. TRADE_CLOSE(50) will close half the trade (subject to minimum lot size account settings). If blank then percentage set on panel is used.
- TRADE_COMMENT: Allows trade comment shown in MetaTrader to be set to something different than the configured value
- text: Text to set trade comment to
- TRADE_OPEN: Open trade depending on auto entry mode set
For example, if set to TC then will open trade or if mode is ALT then will just alert. Note, will only happen if reset has occurred, i.e. RESET_ALERT command has previous been called. - lotsOverride: If greater than 0 then will use this as the lot size for the trade. Note, this will override and risk/margin checks. The min/max lot and lot step for the account will still be applied.
- alertText: If supplied then will override the default alert text with the given text
- flags: Can be set to NAR to not do automatic reset of opposite direction. Can be set to AGRSV (agressive) mode where will not do spread checks or pips moved since original signal (say on open retry). If flags set to AGRSV2 then will also ignore any filters and trading hours checks. If contains HEDGE then trade will be opened as a hedge.
- VOID_ALERT: Voids alert/trade status so that reset is required before trade can happen. Sets t.alertPrice to 0.
- flags: If set to ALL then will void all trade indexes (magic numbers), when in multi-trade mode
- VOID_ALERT_OPP: As VOID_ALERT commend but voids opposite direction
- flags: If set to ALL then will void all trade indexes (magic numbers) for opposite direction, when in multi-trade mode
