Class StrategyBase

java.lang.Object
com.strategyquant.tradinglib.debug.Debugger
com.strategyquant.tradinglib.ChartData
com.strategyquant.tradinglib.StrategyBase
All Implemented Interfaces:
Serializable

public abstract class StrategyBase extends ChartData
The Class StrategyBase.
See Also:
Serialized Form
  • Field Details

    • DefaultLog

      public static final org.slf4j.Logger DefaultLog
      The Constant DefaultLog.
    • UpdatedChart

      public int UpdatedChart
      The Updated chart.
    • MultipleChartsUpdated

      public boolean MultipleChartsUpdated
      The Multiple charts updated.
    • UpdateEventType

      public int UpdateEventType
      The Update event type.
    • Trader

      public Trader Trader
      The Trader.
    • accountBalance

      public double accountBalance
    • accountEquity

      public double accountEquity
    • Stockpicker

      public com.strategyquant.tradinglib.engine.stockpicker.Stockpicker Stockpicker
      The Stockpicker.
  • Constructor Details

    • StrategyBase

      public StrategyBase()
      Instantiates a new strategy base.
  • Method Details

    • setTradeControllers

      public void setTradeControllers(String mainExecutionName, Trader[] tradeControllers)
      Sets the trade controllers.
      Parameters:
      mainExecutionName - the main execution name
      tradeControllers - the trade controllers
    • updateTradeControllers

      public void updateTradeControllers()
      Update trade controllers.
    • callOnInit

      public abstract void callOnInit(com.strategyquant.tradinglib.engine.TradingSetup tradingSetup) throws Exception
      Call on init.
      Parameters:
      tradingSetup - the trading setup
      Throws:
      Exception - the exception
    • callOnInit

      public void callOnInit() throws Exception
      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

      public abstract void Initialize() throws Exception
      Initialize.
      Throws:
      Exception - the exception
    • OnBarUpdate

      public abstract void OnBarUpdate() throws Exception
      On bar update.
      Throws:
      Exception - the exception
    • Deinitialize

      public void Deinitialize() throws Exception
      Deinitialize.
      Throws:
      Exception - the exception
    • OnEvent

      public void OnEvent(com.strategyquant.tradinglib.event.ITradingEvent event) throws Exception
      On event.
      Parameters:
      event - the event
      Throws:
      Exception - the exception
    • clone

      Clone.
      Returns:
      the strategy base
      Throws:
      CloneNotSupportedException - the clone not supported exception
    • hasTrader

      public boolean hasTrader(String connectionName)
      Checks for trader.
      Parameters:
      connectionName - the connection name
      Returns:
      true, if successful
    • Trader

      public Trader Trader(String connectionName)
      Trader.
      Parameters:
      connectionName - the connection name
      Returns:
      the trader
    • getStrategyName

      public String getStrategyName()
      returns name of this strategy. By default it returns name of the class.
      Returns:
      the strategy name
    • setStrategyName

      public void setStrategyName(String strategyName)
      Sets the strategy name.
      Parameters:
      strategyName - the new strategy name
    • setSetupName

      public void setSetupName(String setupName)
      Sets the setup name.
      Parameters:
      setupName - the new setup name
    • getSetupName

      public String getSetupName()
      Gets the setup name.
      Returns:
      the setup name
    • addTrader

      public void addTrader(String name, Trader trader)
      Adds the trader.
      Parameters:
      name - the name
      trader - the trader
    • setSettings

      public void setSettings(SettingsMap settings)
      Sets the settings.
      Parameters:
      settings - the new settings
    • getSettings

      public SettingsMap getSettings()
      Gets the settings.
      Returns:
      the settings
    • newInstance

      New instance.
      Returns:
      the strategy base
      Throws:
      NoSuchMethodException - the no such method exception
      SecurityException - the security exception
    • variables

      public Variables 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

      public double convertPipsToRealPrice(String symbol, double value) throws TradingException
      Convert pips to real price.
      Parameters:
      symbol - the symbol
      value - the value
      Returns:
      the double
      Throws:
      TradingException - the trading exception
    • convertRealPriceToPips

      public double convertRealPriceToPips(String symbol, double value) throws TradingException
      Convert real price to pips.
      Parameters:
      symbol - the symbol
      value - 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

      public void setTradingOptions(ArrayList<TradingOption> tradingOptions)
      Sets the trading options.
      Parameters:
      tradingOptions - the new trading options
    • callOptionsOnTick

      public void callOptionsOnTick(TickEvent tickEvent) throws Exception
      Call options on tick.
      Parameters:
      tickEvent - the tick event
      Throws:
      Exception - the exception
    • wasUsed

      public boolean wasUsed()
      Was used.
      Returns:
      true, if successful
    • checkBadStrategy

      public void checkBadStrategy() throws BadStrategyException, TradingException
      Check bad strategy.
      Throws:
      BadStrategyException - the bad strategy exception
      TradingException - the trading exception
    • init

      public static void init() throws Exception
      Inits the.
      Throws:
      Exception - the exception
    • reload

      public static void reload() throws Exception
      Throws:
      Exception
    • transformToVariables

      public void transformToVariables(boolean symmetric) throws Exception
      Transform to variables.
      Parameters:
      symmetric - the symmetric
      Throws:
      Exception - the exception
    • transformToVariables

      public void transformToVariables(boolean symmetric, ValuesMap parameterTypes) throws Exception
      Transform to variables.
      Parameters:
      symmetric - the symmetric
      parameterTypes - the parameter types
      Throws:
      Exception - the exception
    • transformToNumbers

      public void transformToNumbers() throws Exception
      Transform to numbers.
      Throws:
      Exception - the exception
    • createXmlStrategy

      public static StrategyBase createXmlStrategy(org.jdom2.Element elStrategy) throws Exception
      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 Exception
      Creates the xml strategy.
      Parameters:
      elStrategy - the el strategy
      strategyName - 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 Exception
      Creates the strategy variation.
      Parameters:
      strategy - the strategy
      optimizationSettings - the optimization settings
      indexes - 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() throws Exception
      Creates the indicators obj.
      Returns:
      the indicators obj
      Throws:
      Exception - the exception
    • getStrategyProblems

      public int getStrategyProblems()
      Gets the strategy problems.
      Returns:
      the strategy problems
    • updateJobProgress

      public void updateJobProgress() throws TradingException
      Update job progress.
      Throws:
      TradingException - the trading exception
    • getGlobalMMMethod

      public MoneyManagementMethod getGlobalMMMethod()
      Gets the global MM method.
      Returns:
      the global MM method
    • setGlobalMMMethod

      public void setGlobalMMMethod(MoneyManagementMethod moneyManagementMethod)
      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

      public static StrategyBase getStrategy(SettingsMap settings) throws TradingException
      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
    • callExitEOD

      public void callExitEOD(TickEvent tickEvent) throws Exception
      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

      public org.jdom2.Element customBlocksMapGet(String key)
      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

      public void setATM(ATM atm) throws Exception
      Throws:
      Exception
    • getATM

      public ATM 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

      public void evaluateEntryExit(byte triggeredAt) throws Exception
      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()