Package com.strategyquant.tradinglib
Class StrategyBase
java.lang.Object
com.strategyquant.tradinglib.debug.Debugger
com.strategyquant.tradinglib.ChartData
com.strategyquant.tradinglib.StrategyBase
- All Implemented Interfaces:
Serializable
The Class StrategyBase.
- See Also:
- Serialized Form
-
Field Summary
Modifier and TypeFieldDescriptiondouble
double
static org.slf4j.Logger
The Constant DefaultLog.com.strategyquant.tradinglib.explore.Explore
The explore.boolean
boolean
The Multiple charts updated.com.strategyquant.tradinglib.engine.stockpicker.Stockpicker
The Stockpicker.The Trader.int
The Updated chart.int
The Update event type.Fields inherited from class com.strategyquant.tradinglib.ChartData
ChartTF_D1, ChartTF_M1, ChartTF_W1, Close, Connection, EventType, High, Instrument, Low, MarketData, Median, Open, Symbol, Time, Timeframe, Typical, Volume, Weighted
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addBlocksToXML(org.jdom2.Element elCustomBlocks)
Adds the blocks to XML.void
Adds the trader.void
callExitEOD(TickEvent tickEvent)
Call exit EOD.void
Call on init.abstract void
callOnInit(com.strategyquant.tradinglib.engine.TradingSetup tradingSetup)
Call on init.void
callOptionsOnTick(TickEvent tickEvent)
Call options on tick.void
Check bad strategy.clone()
Clone.double
convertPipsToRealPrice(String symbol, double value)
Convert pips to real price.double
convertRealPriceToPips(String symbol, double value)
Convert real price to pips.static com.strategyquant.tradinglib.indicator.IndicatorsObj
createIndicatorsObj(int engine)
Creates the indicators obj.static com.strategyquant.tradinglib.optimization.StrategyParamData
createStrategyVariation(StrategyBase strategy, com.strategyquant.tradinglib.optimization.OptimizationSettings optimizationSettings, short[] indexes)
Creates the strategy variation.static StrategyBase
createXmlStrategy(org.jdom2.Element elStrategy)
Creates the xml strategy.static StrategyBase
createXmlStrategy(org.jdom2.Element elStrategy, String strategyName)
Creates the xml strategy.void
customBlocksMapAdd(org.jdom2.Element elCBItem)
Custom blocks map add.org.jdom2.Element
customBlocksMapGet(String key)
Custom blocks map get.void
Deinitialize.void
this method must be called only after the data were received by BacktestEngine.void
evaluateEntryExit(byte triggeredAt)
Stockpicker, evaluates entry/exit signals.double
Gets the account balance.double
Gets the account equity.int
boolean
Gets the apply exits at the end of rule.getATM()
abstract double
getATRValue(ChartData chartData, int atrPeriod, int shift)
int
Gets the engine.int
gets the event type that will be handled by this Strategy.onBarUpdate() The onBarUpdate method will be called only for the specified event type.Gets the global MM method.com.strategyquant.tradinglib.indicator.IndicatorsCache
Gets the indicators cache.double
Gets the settings.Gets the setup name.com.strategyquant.tradinglib.options.parameters.StockpickerOptions
Stockpicker, returns settings from Trading options tab.static StrategyBase
getStrategy(SettingsMap settings)
Gets the strategy.returns name of this strategy.int
Gets the strategy problems.org.jdom2.Element
Gets the strategy xml.boolean
Checks for daily data block.boolean
Checks for monthly data block.boolean
Checks for on tick rule.boolean
Checks for trader.boolean
Checks for weekly data block.static void
init()
Inits the.abstract void
Initialize.boolean
Stockpicker, check if Stockpickerboolean
Checks if is symmetry enabled.boolean
Gets the engine.New instance.abstract void
On bar update.void
OnEvent(com.strategyquant.tradinglib.event.ITradingEvent event)
On event.static void
reload()
void
void
setGlobalMMMethod(MoneyManagementMethod moneyManagementMethod)
Sets the global MM method.void
setSettings(SettingsMap settings)
Sets the settings.void
setSetupName(String setupName)
Sets the setup name.void
setStrategyName(String strategyName)
Sets the strategy name.void
setStrategyProblem(int reason)
Sets the strategy problems.void
setTradeControllers(String mainExecutionName, Trader[] tradeControllers)
Sets the trade controllers.void
setTradingOptions(ArrayList<TradingOption> tradingOptions)
Sets the trading options.Trader.void
Transform to numbers.void
transformToVariables(boolean symmetric)
Transform to variables.void
transformToVariables(boolean symmetric, ValuesMap parameterTypes)
Transform to variables.void
Update job progress.void
Update trade controllers.returns an array of variables in this strategy.boolean
wasUsed()
Was used.Methods inherited from class com.strategyquant.tradinglib.ChartData
Ask, Bars, Bars, Bid, BigPointValue, chartHashCode, cloneForTF, cloneOnlyTF, Close, Close, CloseD, CloseD, CloseM, CloseM, CloseW, CloseW, destroy, findTickInData, findTickInDataComplete, getConnectionHash, getConnectionName, getCurrentBar, getIndyStartingBar, getInstrumentInfo, getMinDistance, getSerieIndex, getSeries, getSeries, getSymbol, getSymbolHash, High, High, HighD, HighD, HighM, HighM, HighW, HighW, isNewBarOnMainSymbolTF, isNextDay, isUpdated, Low, Low, LowD, LowD, LowM, LowM, LowW, LowW, Median, MinMove, Open, Open, OpenD, OpenD, Openint, OpenM, OpenM, OpenW, OpenW, PriceScale, processTick, processTickSimplified, resetPreparedDataShifts, setCurrentBar, setIndyStartingBar, setInstrumentInfo, setPerformanceParams, setSymbol, Time, Time, Time, TimeCurrent, TimeD, TimeM, TimeW, Typical, Volume, Volume
Methods inherited from class com.strategyquant.tradinglib.debug.Debugger
debug, fdebug
-
Field Details
-
DefaultLog
public static final org.slf4j.Logger DefaultLogThe Constant DefaultLog. -
UpdatedChart
public int UpdatedChartThe Updated chart. -
MultipleChartsUpdated
public boolean MultipleChartsUpdatedThe Multiple charts updated. -
UpdateEventType
public int UpdateEventTypeThe Update event type. -
Trader
The Trader. -
accountBalance
public double accountBalance -
accountEquity
public double accountEquity -
isAlgoWizard
public boolean isAlgoWizard -
Stockpicker
public com.strategyquant.tradinglib.engine.stockpicker.Stockpicker StockpickerThe Stockpicker. -
Explore
public com.strategyquant.tradinglib.explore.Explore ExploreThe explore.
-
-
Constructor Details
-
StrategyBase
public StrategyBase()Instantiates a new strategy base.
-
-
Method Details
-
setTradeControllers
Sets the trade controllers.- Parameters:
mainExecutionName
- the main execution nametradeControllers
- the trade controllers
-
updateTradeControllers
public void updateTradeControllers()Update trade controllers. -
callOnInit
public abstract void callOnInit(com.strategyquant.tradinglib.engine.TradingSetup tradingSetup) throws ExceptionCall on init.- Parameters:
tradingSetup
- the trading setup- Throws:
Exception
- the exception
-
callOnInit
Call on init.- Parameters:
tradingSetup
- the trading setup- Throws:
Exception
- the exception
-
getEventType
public int getEventType()gets the event type that will be handled by this Strategy.onBarUpdate() The onBarUpdate method will be called only for the specified event type.- Returns:
- the event type
-
Initialize
Initialize.- Throws:
Exception
- the exception
-
OnBarUpdate
On bar update.- Throws:
Exception
- the exception
-
Deinitialize
Deinitialize.- Throws:
Exception
- the exception
-
OnEvent
On event.- Parameters:
event
- the event- Throws:
Exception
- the exception
-
clone
Clone.- Returns:
- the strategy base
- Throws:
CloneNotSupportedException
- the clone not supported exception
-
hasTrader
Checks for trader.- Parameters:
connectionName
- the connection name- Returns:
- true, if successful
-
Trader
Trader.- Parameters:
connectionName
- the connection name- Returns:
- the trader
-
getStrategyName
returns name of this strategy. By default it returns name of the class.- Returns:
- the strategy name
-
setStrategyName
Sets the strategy name.- Parameters:
strategyName
- the new strategy name
-
setSetupName
Sets the setup name.- Parameters:
setupName
- the new setup name
-
getSetupName
Gets the setup name.- Returns:
- the setup name
-
addTrader
Adds the trader.- Parameters:
name
- the nametrader
- the trader
-
setSettings
Sets the settings.- Parameters:
settings
- the new settings
-
getSettings
Gets the settings.- Returns:
- the settings
-
newInstance
New instance.- Returns:
- the strategy base
- Throws:
NoSuchMethodException
- the no such method exceptionSecurityException
- the security exception
-
variables
returns an array of variables in this strategy.- Returns:
- the variables
-
destroyHistoryTrades
public void destroyHistoryTrades()this method must be called only after the data were received by BacktestEngine. -
getIndicatorsCache
public com.strategyquant.tradinglib.indicator.IndicatorsCache getIndicatorsCache()Gets the indicators cache.- Returns:
- the indicators cache
-
convertPipsToRealPrice
Convert pips to real price.- Parameters:
symbol
- the symbolvalue
- the value- Returns:
- the double
- Throws:
TradingException
- the trading exception
-
convertRealPriceToPips
Convert real price to pips.- Parameters:
symbol
- the symbolvalue
- the value- Returns:
- the double
- Throws:
TradingException
- the trading exception
-
getStrategyXml
public org.jdom2.Element getStrategyXml()Gets the strategy xml.- Returns:
- the strategy xml
-
setTradingOptions
Sets the trading options.- Parameters:
tradingOptions
- the new trading options
-
callOptionsOnTick
Call options on tick.- Parameters:
tickEvent
- the tick event- Throws:
Exception
- the exception
-
wasUsed
public boolean wasUsed()Was used.- Returns:
- true, if successful
-
checkBadStrategy
Check bad strategy.- Throws:
BadStrategyException
- the bad strategy exceptionTradingException
- the trading exception
-
init
Inits the.- Throws:
Exception
- the exception
-
reload
- Throws:
Exception
-
transformToVariables
Transform to variables.- Parameters:
symmetric
- the symmetric- Throws:
Exception
- the exception
-
transformToVariables
Transform to variables.- Parameters:
symmetric
- the symmetricparameterTypes
- the parameter types- Throws:
Exception
- the exception
-
transformToNumbers
Transform to numbers.- Throws:
Exception
- the exception
-
createXmlStrategy
Creates the xml strategy.- Parameters:
elStrategy
- the el strategy- Returns:
- the strategy base
- Throws:
Exception
- the exception
-
createXmlStrategy
public static StrategyBase createXmlStrategy(org.jdom2.Element elStrategy, String strategyName) throws ExceptionCreates the xml strategy.- Parameters:
elStrategy
- the el strategystrategyName
- the strategy name- Returns:
- the strategy base
- Throws:
Exception
- the exception
-
createStrategyVariation
public static com.strategyquant.tradinglib.optimization.StrategyParamData createStrategyVariation(StrategyBase strategy, com.strategyquant.tradinglib.optimization.OptimizationSettings optimizationSettings, short[] indexes) throws ExceptionCreates the strategy variation.- Parameters:
strategy
- the strategyoptimizationSettings
- the optimization settingsindexes
- the indexes- Returns:
- the strategy param data
- Throws:
Exception
- the exception
-
isSymmetryEnabled
public boolean isSymmetryEnabled()Checks if is symmetry enabled.- Returns:
- true, if is symmetry enabled
-
createIndicatorsObj
public static com.strategyquant.tradinglib.indicator.IndicatorsObj createIndicatorsObj(int engine) throws ExceptionCreates the indicators obj.- Parameters:
engine
- the engine- Returns:
- the indicators obj
- Throws:
Exception
- the exception
-
getStrategyProblems
public int getStrategyProblems()Gets the strategy problems.- Returns:
- the strategy problems
-
setStrategyProblem
public void setStrategyProblem(int reason)Sets the strategy problems. -
updateJobProgress
Update job progress.- Throws:
TradingException
- the trading exception
-
getGlobalMMMethod
Gets the global MM method.- Returns:
- the global MM method
-
setGlobalMMMethod
Sets the global MM method.- Parameters:
moneyManagementMethod
- the new global MM method
-
hasOnTickRule
public boolean hasOnTickRule()Checks for on tick rule.- Returns:
- true, if successful
-
hasDailyDataBlock
public boolean hasDailyDataBlock()Checks for daily data block.- Returns:
- true, if successful
-
hasWeeklyDataBlock
public boolean hasWeeklyDataBlock()Checks for weekly data block.- Returns:
- true, if successful
-
hasMonthlyDataBlock
public boolean hasMonthlyDataBlock()Checks for monthly data block.- Returns:
- true, if successful
-
getStrategy
Gets the strategy.- Parameters:
settings
- the settings- Returns:
- the strategy
- Throws:
TradingException
- the trading exception
-
getApplyExitsAtTheEndOfRule
public boolean getApplyExitsAtTheEndOfRule()Gets the apply exits at the end of rule.- Returns:
- the apply exits at the end of rule
-
getEngine
public int getEngine()Gets the engine.- Returns:
- the engine
-
isTradestationEngine
public boolean isTradestationEngine()Gets the engine.- Returns:
- the engine
-
callExitEOD
Call exit EOD.- Parameters:
tickEvent
- the tick event- Throws:
Exception
- the exception
-
customBlocksMapAdd
public void customBlocksMapAdd(org.jdom2.Element elCBItem)Custom blocks map add.- Parameters:
elCBItem
- the el CB item
-
customBlocksMapGet
Custom blocks map get.- Parameters:
key
- the key- Returns:
- the element
-
addBlocksToXML
public void addBlocksToXML(org.jdom2.Element elCustomBlocks)Adds the blocks to XML.- Parameters:
elCustomBlocks
- the el custom blocks
-
setATM
- Throws:
Exception
-
getATM
-
getATRValue
public abstract double getATRValue(ChartData chartData, int atrPeriod, int shift) throws TradingException- Throws:
TradingException
-
getInitialBalance
public double getInitialBalance() -
getAccountBalance
public double getAccountBalance()Gets the account balance.- Returns:
- the account balance
-
getAccountEquity
public double getAccountEquity()Gets the account equity.- Returns:
- the account equity
-
isStockpicker
public boolean isStockpicker()Stockpicker, check if Stockpicker- Returns:
- true if Stockpicker, otherwise false
-
evaluateEntryExit
Stockpicker, evaluates entry/exit signals.- Throws:
Exception
-
getStockpickerOptions
public com.strategyquant.tradinglib.options.parameters.StockpickerOptions getStockpickerOptions()Stockpicker, returns settings from Trading options tab. -
getAmbiguousTrades
public int getAmbiguousTrades() -
getTradingOptions
-