Variables and Conditions Section

 

Hotkey Editor - Vars

 

This section can be omitted unless you need to make the action of the hotkey different depending on some parameters of the specific window on which the hotkey is executed and the logic of that is complex enough that it warrants making a separate section.

 

The + Variable button adds a variable to the section. If at the time you press the button the highlight is on THEN or ELSE, it will add a variable to that section, otherwise it will just add a general variable.

 

The above example defines two variables - Action and Amount - and sets them to Sell  and Pos/2 (which means half the current position) if the current position is positive - that is, if you are long the stock. Or it sets it to Buy and abs(Pos/4) (which means quarter of the current position) if your current position is short.

 

Hotkey Editor - Vars2

 

Since the expressions in hotkeys can use the conditional ?: operators, the conditional structure at the top could be shortened to the above, but at the expense of readability. (This is basically a standard C# ? conditional operator).

 

Note that the strings are enclosed in single quotes - '.

 

You can have as many variables or conditions as you like. Any variables thus defined can be used later in the Action sections.

 

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 Medved Trader 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:    ? (see further below)

 

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

OvernightBP

current selected account's overnight buying power

DaytradeBP

current selected account's daytrade 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). Negative if short. For crypto, the left side of the pair - for example BTC in #BTC.USD

PosAbs

absolute value of currently held # of shares (or 0).

LastFillPrice

price for the last fill (if there was one) otherwise 0

LastFillQty

quantity for the last fill (if there was one) otherwise 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 low 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
RiskRewardEntry
RiskRewardTarget
RiskRewardStop
 

If you have a RiskReward annotation drawn on the chart, this will represent its values.
 
If you have more than one RiskReward annotation on the chart, this will represent the values of the one 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,

floor_dig,

ceil_dig

rounding-up/down, but at decimal digits

Example: round_dig(2.127,2) = 2.13



round_inc,

floor_inc,

ceil_inc

rounding-up/down, but at increments

Example: round_dig(2.31, 0.25) = 2.25



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)

 

bead

 

gets the value of the pre-set bead - the parameter is the bead number. Like: bead(1)  or bead(5)

intervar

gets the intervar specified as a string (in single quotes only!).
Example: intervar('passvalue')

chartvar

similar to intervar but this variable is specific to chart (and thus can only be used in a hotkey that is executed on the same chart where it was set) and not global for symbol. Example: chartvar('somevalue')

symbolprice,

symbolbid,

symbolask

these functions take the symbol as a parameter (in single quotes only!) and return the corresponding values. In order for the values to be populated, the symbol has to be currently subscribed to in some portfolio or chart. Example: symbolprice('AAPL')

symbolrecent

takes two parameters: symbol (in single quotes only) and # of seconds. Returns true if the information for the symbol is current within that # of seconds, and false otherwise.  For example, symbolrecent('AAPL', 10) will return true if AAPL's price has been updated within the last 10 seconds.



 

 

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