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
FieldsModifier and TypeFieldDescriptiondoubledoublestatic org.slf4j.LoggerThe Constant DefaultLog.com.strategyquant.tradinglib.explore.ExploreThe explore.booleanbooleanThe Multiple charts updated.com.strategyquant.tradinglib.engine.stockpicker.StockpickerThe Stockpicker.The Trader.intThe Updated chart.intThe 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBlocksToXML(org.jdom2.Element elCustomBlocks)Adds the blocks to XML.voidAdds the trader.voidcallExitEOD(TickEvent tickEvent)Call exit EOD.voidCall on init.abstract voidcallOnInit(com.strategyquant.tradinglib.engine.TradingSetup tradingSetup)Call on init.voidcallOptionsOnTick(TickEvent tickEvent)Call options on tick.voidCheck bad strategy.clone()Clone.doubleconvertPipsToRealPrice(String symbol, double value)Convert pips to real price.doubleconvertRealPriceToPips(String symbol, double value)Convert real price to pips.static com.strategyquant.tradinglib.indicator.IndicatorsObjcreateIndicatorsObj(int engine)Creates the indicators obj.static com.strategyquant.tradinglib.optimization.StrategyParamDatacreateStrategyVariation(StrategyBase strategy, com.strategyquant.tradinglib.optimization.OptimizationSettings optimizationSettings, short[] indexes)Creates the strategy variation.static StrategyBasecreateXmlStrategy(org.jdom2.Element elStrategy)Creates the xml strategy.static StrategyBasecreateXmlStrategy(org.jdom2.Element elStrategy, String strategyName)Creates the xml strategy.voidcustomBlocksMapAdd(org.jdom2.Element elCBItem)Custom blocks map add.org.jdom2.ElementcustomBlocksMapGet(String key)Custom blocks map get.voidDeinitialize.voidthis method must be called only after the data were received by BacktestEngine.voidevaluateEntryExit(byte triggeredAt)Stockpicker, evaluates entry/exit signals.doubleGets the account balance.doubleGets the account equity.intbooleanGets the apply exits at the end of rule.getATM()abstract doublegetATRValue(ChartData chartData, int atrPeriod, int shift)intGets the engine.intgets 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.IndicatorsCacheGets the indicators cache.doubleGets the settings.Gets the setup name.com.strategyquant.tradinglib.options.parameters.StockpickerOptionsStockpicker, returns settings from Trading options tab.static StrategyBasegetStrategy(SettingsMap settings)Gets the strategy.returns name of this strategy.intGets the strategy problems.org.jdom2.ElementGets the strategy xml.booleanChecks for daily data block.booleanChecks for monthly data block.booleanChecks for on tick rule.booleanChecks for trader.booleanChecks for weekly data block.static voidinit()Inits the.abstract voidInitialize.booleanStockpicker, check if StockpickerbooleanChecks if is symmetry enabled.booleanGets the engine.New instance.abstract voidOn bar update.voidOnEvent(com.strategyquant.tradinglib.event.ITradingEvent event)On event.static voidreload()voidvoidsetGlobalMMMethod(MoneyManagementMethod moneyManagementMethod)Sets the global MM method.voidsetSettings(SettingsMap settings)Sets the settings.voidsetSetupName(String setupName)Sets the setup name.voidsetStrategyName(String strategyName)Sets the strategy name.voidsetStrategyProblem(int reason)Sets the strategy problems.voidsetTradeControllers(String mainExecutionName, Trader[] tradeControllers)Sets the trade controllers.voidsetTradingOptions(ArrayList<TradingOption> tradingOptions)Sets the trading options.Trader.voidTransform to numbers.voidtransformToVariables(boolean symmetric)Transform to variables.voidtransformToVariables(boolean symmetric, ValuesMap parameterTypes)Transform to variables.voidUpdate job progress.voidUpdate trade controllers.returns an array of variables in this strategy.booleanwasUsed()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, VolumeMethods 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
-