Hotkeys: Variables and Conditions
Advanced: Expressions
The expressions that can be used in defining the variables and, later, properties in the Action section, are fairly standard ones. Some operators are duplicated for the users' convenience (for example, both = and == mean the same thing).
The expressions can utilize System Variables/Parameters and Functions that HAMMER makes available.
The variables in expressions can be numeric or strings. Strings can be delimited with single quotes and can be concatenated with a +. Usually, when an expression cannot be evaluated as numeric, it is assumed to be a string. Thus, when assigning simple strings, the quotes can be omitted.
Operators
arithmetic: + - / * %
compare: == (same as =) > >= < <= != (same as <>)
logical: && (same as and), ! (same as not), || (same as or) true false
conditional: ?
Advanced: System Variables and Functions
System Variables:
Account | current selected account in the trading window |
Broker | current selected account's broker |
Cash | current selected account's cash buying power |
BP | current selected account's buying power |
DefaultQty | current quantity in the Trading tab of ribbon menu or on trading ticket |
Price | current price for symbol |
Bid | current bid |
Ask | current ask |
Mid | (Bid+Ask)/2 |
PrevClose | previous day's close |
TodayOpen | current session's open |
TodayHigh | current session's high |
TodayLow | current session's low |
Pos | currently held # of shares (or 0 if no position) |
PosAbs | absolute value of currently held # of shares (or 0) |
CurrencyPos | for crypto - the right side of the pair. For example USDT in #BTC.USDT |
PosPaid | for currently held position, average paid price |
PriceAtMouse | only for Charts, DOM - whatever the price at mouse is |
CapPrice | only for Charts, DOM - if hovering over a trading cap, its price |
CapAction | only for Charts, DOM - if hovering over a trading cap, its action - buy/sell |
CapOrderType | only for Charts, DOM - if hovering over a trading cap, its OrderType |
TicketLimitPrice | only for Trade Ticket and LII window - the limit price entered in the ticket |
TicketStopPrice | only for Trade Ticket and LII window - the stop price entered in the ticket |
BarOpen | only for Charts - the open price for the last candle |
BarHigh | only for Charts - the high price for the last candle |
BarLow | only for Charts - the high price for the last candle |
BarOpen1,BarHigh1,BarLow1,BarClose1, etc. | only for Charts - these are the BarOpen etc. values for 1 (or 2, 3..) candles back |
Now | current time, UTC |
DayStart | start of current (last) trading day, UTC |
DayEnd | end of current (last) trading day, UTC |
SessionStart | start of current (last) official trading session, UTC |
SessionEnd | end of current (last) official trading session, UTC |
PreMarket | true if currently before the official trading session |
AfterMarket | true if currently after the official trading session |
RegSession | true if currently in official trading session |
MinIntoSession | # of minutes into official trading session. 0 if RegSession is false |
RiskRewardQty | If you have a RiskReward annotation drawn on the chart, this will represent its values |
RiskRewardTarget | If you have more than one RiskReward annotation on the chart, this will represent the values of the one |
RiskRewardStop | over which the mouse is currently hovering |
Functions:
abs |
absolute value |
min |
minimum of 2 values |
max |
maximum of 2 values |
round, floor, ceil |
rounding, rounding up, rounding down. Example: round(1.6) = 2 |
round_dig, |
rounding-up/down, but at decimal digits |
floor_dig, |
Example: round_dig(2.127,2) = 2.13 |
ceil_dig |
|
round_inc, |
rounding-up/down, but at increments |
floor_inc, |
Example: round_dig(2.31, 0.25) = 2.25 |
ceil_inc |
|
offset
|
for use in the price offset parameters in the order For example offset(2) is equivalent to '+2' |
Peg |
pegs the price to Bid, Ask, Price, Mid with an optional offset Example: peg(Bid, -0.2) |
Advanced: Inline Conditionals
Expressions support the C# style conditional ? operator. The syntax is condition ? a : b. If condition is true, it will evaluate to a, otherwise to b.
This means that if you write Pos>=0? ’Buy’ : ’Sell’ - the result will be ‘Buy’ if Pos is above 0, otherwise ‘Sell’.
Such conditions can be nested as well. So you could do Pos>0 ? 'Sell' : Pos<0? 'Buy' : 'None’.
In addition, for readability, the syntax can be changed to use the if… then… else... format. If you do, BOTH then and else have to be in the expression for each if. They can be nested as well.
Thus the equivalent of the above example would be: if Pos>0 then 'Sell' else if Pos<0 then 'Buy' else 'None’.