Interface AntherTradingStrategy<P extends BasicAntherTradingStrategyParameters>
- Type Parameters:
P- child ofBasicAntherTradingStrategyParameters
- All Known Implementing Classes:
BloomTradingStrategy
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface
public interface AntherTradingStrategy<P extends BasicAntherTradingStrategyParameters>
Defines a trading strategy, an algorithmic method of placing and exiting financial market
positions.
- Version:
- 2.0.3
- Author:
- Stephen Prizio
-
Method Summary
Modifier and TypeMethodDescriptiondefault doublecalculateLimit(double price, double increment, boolean shouldAdd) Calculates the limit used as either a take profit or stop loss.default voidcheckPositions(Map<String, AntherPosition> openPositions, Map<String, AntherPosition> closedPositions, MarketPrice marketPrice) Checks whether the givenMarketPricecloses an openAntherPosition.default voidcloseDay(MarketPrice currentPrice, Map<String, AntherPosition> openPositions, Map<String, AntherPosition> closedPositions) Closes the day, meaning close all positions on the exit signal.default voidclosePosition(AntherPosition position, LocalDateTime positionClosed, double closePrice) Updates the givenAntherPositionwith a close time and price.executeStrategy(P parameters) Executes aAntherTradingStrategywith the given parameters.default AntherPositionopenPosition(PositionType positionType, double lotSize, LocalDateTime positionOpened, double openPrice, double stopLoss, double takeProfit) Creates a newAntherPositionthat is considered active.
-
Method Details
-
executeStrategy
Executes aAntherTradingStrategywith the given parameters.- Parameters:
parameters-P- Returns:
AntherTradingStrategyResult
-
openPosition
default AntherPosition openPosition(PositionType positionType, double lotSize, LocalDateTime positionOpened, double openPrice, double stopLoss, double takeProfit) Creates a newAntherPositionthat is considered active. In this case active means that anAntherPositiondoes not yet have a close price.- Parameters:
positionType-PositionTypelotSize- position sizepositionOpened- time of openopenPrice- price at openstopLoss- limit losstakeProfit- limit profit- Returns:
AntherPosition
-
closePosition
default void closePosition(AntherPosition position, LocalDateTime positionClosed, double closePrice) Updates the givenAntherPositionwith a close time and price.- Parameters:
position-AntherPositionpositionClosed- close timeclosePrice- close price
-
calculateLimit
default double calculateLimit(double price, double increment, boolean shouldAdd) Calculates the limit used as either a take profit or stop loss.- Parameters:
price- trade priceincrement- increment to add or subtractshouldAdd- if true, add- Returns:
- limit level
-
checkPositions
default void checkPositions(Map<String, AntherPosition> openPositions, Map<String, AntherPosition> closedPositions, MarketPrice marketPrice) Checks whether the givenMarketPricecloses an openAntherPosition.- Parameters:
openPositions- currently opened positionsclosedPositions- previously closed positionsmarketPrice-MarketPrice
-
closeDay
default void closeDay(MarketPrice currentPrice, Map<String, AntherPosition> openPositions, Map<String, AntherPosition> closedPositions) Closes the day, meaning close all positions on the exit signal.- Parameters:
currentPrice-MarketPricecurrent baropenPositions- open positionsclosedPositions- closed positions
-