runwiseFX

groundbreaking functionality for MetaTrader & TradingView

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.


  • ALERT: Raise alert via the configured methods
    • text: Text to appear in the alert

  • 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. Note, will also do MTO if EA input Gen_accountManagedTradesOnly is set to true.

  • COMMENT: Can be used to set fail comment to explain why rule is not passing, i.e. why not open/closing a trade
    • text: Text of fail comment

  • DEL_OBJECT: Remove object from chart
    • name: Name of object (_rwfx_u_ will be added to this when delete by the runwiseFX EA)

  • 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

  • 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

  • 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
    • 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. Will be blanked if not supplied.

  • 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

  • LOG_ADD: Add information to trade log in tag=value format

  • 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

  • MISC: Miscellaneous command
    • command: Miscellaneous command to perform

  • OBJ_CREATE: Create chart object
    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
    • name: Object name

  • OBJ_SET_COLOR: Set color and optionally style of object
    • 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
    • time1: Time1 to set object to. Either seconds since EPOC, or if negative value then number of 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: Enable pending order
    Will re-enable previous disabled pending order, so that will be actioned when price is reached

  • 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.

  • SET_BREAK_EVEN: Will set trade for break even, i.e. will exit when profit falls to break even. Note, if trade is already below break even then trade will exit.

  • SET_BROKER_SL: Set broker (hard) stop loss. Note, it is the hidden (soft) stop loss that will be used for any risk calculation.
    • setWithPrice: Price to set stop loss to
    • setWithPips: Pips to set stop loss to. If both price and pips are supplied then price will be used. Pips can been supplied as a percentage of the daily range by adding '%' after the number, e.g. 50% would set the pips to 50% of the current daily range of the symbol.
    • offsetPips: Additional pips to add to stop loss. Positive values will make to stop loss further away from the price.
    • offsetPrctMode: If % supplied in offset then if prctMode = "DR" will be % of daily range, else if = "R" then will be % of risk. If empty the DR mode will be assumed.
    • autoOnly: If set then will only update stop loss if set to auto via the radio buttons in the Symbol tab

  • SET_BROKER_TP: Set broker (hard) take profit
    • setWithPrice: Price to set take profit to
    • setWithPips: Pips to set take profit to. If both price and pips are supplied then price will be used.
    • offsetPips: Additional pips to add to take profit. Positive values will make to take profit further away from the price.

  • SET_HIDDEN_SL: Set hidden(virtual/stealth/soft) stop loss. Note, this is the stop loss that is used for the risk calculation. Once trade open then SL can't be set further away with this command.
    • setWithPrice: Price to set stop loss to
    • setWithPips: Pips to set stop loss to. If both price and pips are supplied then price will be used. Pips can been supplied as a percentage of the daily range by adding '%' after the number, e.g. 50% would set the pips to 50% of the current daily range of the symbol.
    • offsetPips: Additional pips to add to stop loss. Positive values will make to stop loss further away from the price. Pips can been supplied as a percentage of the daily range by adding '%' after the number, e.g. 20% would set the offset to 20% of the current daily range of the symbol.
    • minPips: Minimum pips to use for stop loss, even if price/pips is less. Note, minimum only applied if trade not open. If blank then no minimum will be applied. Pips can been supplied as a percentage of the daily range by adding '%' after the number, e.g. 50% would set the pips to 50% of the current daily range of the symbol.
    • maxPips: Maximum pips to use for stop loss, even if price/pips is more. If blank then no maximum will be applied. Pips can been supplied as a percentage of the daily range by adding '%' after the number, e.g. 50% would set the pips to 50% of the current daily range of the symbol.
    • autoOnly: If set then will only update stop loss if set to auto via the radio buttons in the Symbol tab

  • SET_HIDDEN_TP: Set hidden (soft) take profit
    • level: Level to set. By default this is value between 1-4 for each of the take profit boxes.
    • enabled: Enabled. Set to 1 to enable the take profit level. Set to 0 to disable. Leave blank to not change this field.
    • exitPrct: Percentage of original trade to exit when take profit level is reached
    • setWithRRR: Set with risk reward ratio. Leave blank to not change this field.
    • setWithPips: Pips to set take profit level to. If both price and pips are supplied then price will be used. Pips can been supplied as a percentage of the daily range by adding '%' after the number, e.g. 50% would set the pips to 50% of the current daily range of the symbol. Leave blank to not change this field.
    • setWithPrice: Price to set take profit to. Leave blank to not change this field.
    • raiseSL: If set to 1 then will enable auto raise of stop loss when target is reached. Set to 0 to turn off. Leave blank to not change this field.

  • SET_INDICATOR: Set indicator value. Allows indicator values to be set by runwiseFX rather than being read from MetaTrader. Example usage would be to the set the value of a hybrid indicator that combines values from various indicators captured from MetaTrader and/or calculated locally.
    • indicatorToSet: Indicator to set. You can add new indicators by using the 'Indicators/Objects to Capture from MetaTrader' menu in the Configure main menu.
    • valueToSetTo: Value to set indicator to

  • 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_LOCAL_VARIABLE: Set variable that just has local scope, i.e. can only be accessed whilst the rule is being evaluated and will be forgot afterwards. Example usage is for temporary storage whilst working out a value. Note, changes made to local variables are not logged.
    • localToSet: Local variable whose value is to be set. You can create new local variables using the Local Variable menu option in the Configure menu.
    • valueToSetTo: Value to set variable to. Can also be ++ to increment as integer by 1. Or -- to decrement as integer by 1.

  • SET_OBJECT: Set object on chart
    • name: Name of object (_rwfx_u_ will be added to this when object is created by the runwiseFX EA)
    • type: Type of object
    • value: Value to set object to, e.g. price
    • color: Color to set object to (if appropriate)
    • label: Label to associate with object (if supported by object type)
    • lineType: Line type, e.g. dotted line (if supported by object type)

  • SET_OPEN_WARN: Set warning icon, shown next to trade open button
    • icon: Icon to show. Default is none (-1).

  • SET_RANK_VAL: Set value used to rank symbol. Should be positive for buy and negative for sell. The bigger the number, the higher the rank.
    • valueToSetTo: Should be positive for buy and negative for sell. The bigger the number, the higher the rank. Set to 0 for undecided.

  • SET_RULE: Set rule attribute or main rule setting. This command allows rules to change attributes of its own attributes or the attributes of other rules. The command can also be used to 'switch' on or off other rules, by changing the rules main setting.
    • ruleAttrToSet: Rule and rule attribute to be set
    • valueToSetTo: Value to set rule to. Can also be ++ to increment as integer by 1. Or -- to decrement as integer by 1.

  • 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.

  • SET_VARIABLE: Set symbol variable associated with strategy/symbol/direction to a particular value. The variable can be accessed by any rule. Example usage would be to store the peak value of an indicator value.
    • varToSet: Variable whose value is to be set. You can create new variable with the Symbol Variable menu option in the Configure menu.
    • valueToSetTo: Value to set variable to. Can also be ++ to increment as integer by 1. Or -- to decrement as integer by 1.

  • SIGNAL_SET: Sets signal price and time and will reset opposite direction if 'Auto reset on opposite signal' is ticked in CONFIG | General Settings.

  • SL_REVERSE: Stop loss reverse. Will open a trade of type stop loss reverse. Stop loss reverse trade will only open if the previous trade for symbol/strategy was not itself a stop loss reverse.
    • hiddenSLPrice: Hidden stop loss price. Set to bid price of where stop loss is required. Leave blank to use current setting shown in Symbol tab.
    • hiddenSLPips: Hidden stop loss pips to set when trade is opened. Leave blank to use current setting shown in Symbol tab. Note, if both price and pips supplied then price will be used.
    • riskAdjustPrct: Percentage to adjust risk by. 10 would add an extra 10% to the risk percent/amount shown in the Symbol tab. E.g., if risking 2.5% of account then if this parameter is 10 then that will be increased to 2.75%. Use negative numbers to decrease the risk.
    • 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.

  • 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. If blank or 100 then entire trade will be closed, else the supplied percentage. E.g., TRADE_CLOSE(50) will close half the trade (subject to minimum lot size account settings).

  • 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, e.g. 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.

  • 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