Trade Smarter with Automation

Managing opportunities

Learn how to use opportunities to manage stock, option and spread positions.

Opening

When your routine finds an opportunity, it instructs the bot to open it by calling $bot.open and passing an object with option:value pairs that inform the bot specifically what to open, e.g.

$bot.open({
    type: 'equity',
    symbol: 'JPM',
    price: 55.23
});

There are many options available when opening a new opportunity, but the most important option is the type option because the type option determines what other options are supported. At the end of this document there is a list of the types of opportunities Alta5 supports and with links to further documention of the options, properties and functions available for that type of opportunity.


Monitoring

When the market opens each weekday, after the wake event is done, a bot starts triggering the monitor event multiple times per second if it has any open opportunities. Your monitor script can check for profit taking, stop loss or any other condition that should trigger the bot to close an opportunity.

$bot.opps

All open opportunities for your bot are in the $bot.opps collection. For convenience, the first open opportunity is available via the $bot.opp property.

// first opp
var opp = $bot.opp;

// or by array index
var opp = $bot.opps[0];

// first shortput opp
var opp = $bot.opps.first('shortput');

Closing an opportunity

When you determine that you want to close an opportunity, call the opportunity's close function. The close function accepts a memo message to display in the app or an options object with the following options:

  • String

    Memo text displayed in the application.

  • Mixed

    A fixed limit price, array of prices or price settings object. If you don't provide a price, Smart Pricing will automatically try limit orders between the bid/ask spread.

  • Number/String

    The amount of time to keep the order open. More info...

For example:

// pass memo directly
$bot.opp.close('Profit taking at 75%');

// pass options with timeout in 300 seconds (5 minutes)
$bot.opp.close({memo: 'Profit taking at 75%', timeout: 300});

Example monitor script

Below is the monitor script from the Tasty Condor bot:

var opp = $bot.opp;

// Prevent day trade
if(opp.daysOpen < 1){
    return;
}

// Don't buy back for more $ than max loss at expiration
if(-opp.maintenance > opp.marketValue){
    return;
}

// Take profit at 50% of premium won
if(opp.premiumGain >= .5){
    opp.close('50% premium won');
    return;
}

// Take loss at 2x premium
if(opp.pnl <= -(opp.premium * 2)){
    opp.close('2x premium stop loss');
    return;
}

// Close 15 min before expiration if in-the-money
if(opp.itm && opp.isLastTradingDay && $a5.isClosing(15)){
    opp.close('Close before expiration');
}

Types of opportunities

Below is a list of the types of opportunities Alta5 currently supports. Each guide below provides documentation for the $bot.open options to open an opportunity and the properties/functions available for monitoring opportunities.

Equity

Manages long or short equity positions.

Call option

Manages long or short call option positions.

Put option

Manages long or short put option positions.

Bear call spread

Manages bear call spread positions.

Bull put spread

Manages bull put option positions.

Iron condorNew

Manages iron condor spreads.