Skip to content

Algorithm SDK

closeAllPositions

Closes every position this algorithm has open, at the market. The same as OPEN_POSITIONS.closeAll().

Trading on margin can lose you more than you put in. Past results, including backtests, do not predict future results. Cloud9Trader provides tools and education, not financial advice.

declare function closeAllPositions(): void;

Nothing. Each close goes to your broker; the positions leave OPEN_POSITIONS as they close.

function onTick() {
const fridayEvening = TIME.getUTCDay() === 5 && TIME.getUTCHours() >= 20;
if (fridayEvening && OPEN_POSITIONS_COUNT > 0) {
closeAllPositions();
}
}
  • Position: close one position with position.close().