Is there samples available , how i can load strategies with the development API ???
best regards
Gidien
Moderator: admin
Program
is responsible for loading a list of indicators and strategies, getting an indicator’s profile, and filling parameters for a strategy. It creates an instance of the strategy (an object of StrategyInstance
class implemented as MyStrategyInstance
). Strategy instance always uses two tick sources (“bid” and “ask”), so you need to implement IndicatorTickSource
class (MyIndicatorTickSource
class in the example). Some strategies may use time frames other than “tick”. It means you will need to implement IndicatorBarSource
class (MyIndicatorBarSource
class in the example). Classes IndicatorTickSource
and IndicatorBarSource
are subclasses of IndicatorSource
. Host
class for host application. Class MyHost
implements Host
in the example. It is used to execute commands or to get data which are not covered by the standard interface of the indicators or the strategies.StrategyCallback
class (MyStrategyCallback
class in the example). Program
will notify strategy instance when asynchronous operations requested by strategy are completed.MyHost
class:MyHost
gets commands getTradingDayOffset
, getTradingWeekOffset
or getTradingProperty
, it calls Order2Go
class. For GetHistory
commands MyHost
is using HistoryMgr
class. For setTimer
and killTimer
commands MyHost
is using TimersMgr
class.MyIndicatorTickSource
or MyIndicatorBarSource
(MyIndicatorBarSource
uses helper class BarData
). History Manager keeps information about streams created for the strategy instance via Ticket
class.Order2Go
is used for getting trading property, trading day offset, trading week offset, and price history helper (the last is used for getting a candle for specific time). When MyHost
gets command findTable
, it returns TradingDataTable
. Class MyTradingTable
implements TradingDataTable
and contains information about trading tables (“Accounts”, “Offers”, “Orders”, “Trades”, “Closed Trades”, “Summary”, “Messages”). Class MyTradingTable
also uses MyTradingRowEnumerator
(subclass of TradingDataTableEnumerator
) and MyTradingRow
(subclass of TradingDataTableRow
).Indicore
.Order2Go
. You would also need Order2Go
for creating trading orders in case you strategy would be allowed to trade.gehtsoft.indicore.dll
and FXCore.dll
as references to your projectindicore2.dll
and lua5.1.dll
to the target directorystrategies\standard\include
structure in the target directory and copy files from strategies\standard\include
folder there (you will need files helper.lua
and helperAlert.lua
)Program
class which is a hub of the application.[application].exe [username] [password] [instrument (optional)] [time frame (optional)]
Indicore Manager
object Core
object of Order2Go
trade desk
objectgetHistory
requests (they may need history from time frame other than “tick”). Accomplishment of these requests takes time, so you would need to use asynchronous functions. OnPriceHistoryCompleted
and OnPriceHistoryFailed
OnRequestCompleted
and OnRequestFailed
trade desk
MA_ADVISOR
is used in the example)MA_ADVISOR
used in the example you would need to set parameter CANTRADE
to “Yes”, and parameter ACCOUNT
to account ID (which can be extracted by helper function GetAccountID
) in case the strategy is allowed to trade.Host
class in your codeHost
class (MyHost
), and set it as a Host
for your Indicore Manager
objectHost
has method findTable
returning TradingDataTable
.TradingDataTable
(see class MyTradingTable
). You can omit this step if the strategy is not allowed to trade.StrategyCallback
class in your code (see class MyStrategyCallBack
)IndicatorTickSource
class (see class MyIndicatorTickSource
).IndicatorBarSource
in case the strategy can use time frame other than “tick” (see class MyIndicatorBarSource
)HistoryMgr
class to prepare ticks for you. You need the tick history up to “now” (use 0 as date “from” and date “to”, and “t1” as time frame). History manager would do the work of merging “historic” ticks and “new” ticks.HistoryMgr
) keeps all streams for the strategy instance. “Bid” and “ask” tick streams are special, because they were created before the strategy instance was born. That’s that is why you have to attach them to strategy instance right after creating a strategy instance with those streams.ProcessPendingEvents
), and in case there are new prices, all price streams associated with the strategy instance would get new ticks (bars), and the strategy instance would be updated.OnPriceHistoryCompleted
happens, check the dictionary in history manager, find a stream for the price history request, fill it with the prices you got, add new ticks stored in the buffer for the stream (if any), mark stream as completed, and call notifyFinished
for the strategy instance (function FxCore_OnPriceHistoryCompleted
).OnPriceHistoryFailed
happens (function FxCore_OnPriceHistoryFailed
).OnRequestCompleted
or OnRequestFailed
happen (functions FXCore_OnRequestCompleted
and FXCore_OnRequestFailed
). Check Order2Go
dictionary, find information about the order for specific request, get a cookie for the strategy, and call notifyFinished
for the strategy instance. Information about order requests older than one minute can be removed from the dictionary.MyHost
implements Host
class. It is called by strategy for executing commands, finding trading tables, logging, getting trading day offset, trading week offset, and trading properties.Host
returns TradingDataTable
in findTable
method.MyTradingTable
implements TradingDataTable
and reflects real trading tables (“Accounts”, “Offers”, “Orders”, “Trades”, “Closed Trades”, “Summary”, “Messages”):TradingDataTable
returns TradingDataTableRow
in function findRow
. That’s why you need to implement TradingDataTableRow
(class MyTradingRow
in the example).MyTradingTable
returns TradingDataTableEnumerator
in a function getEnumerator
. It means you need to implement TradingDataTableEnumerator
(class MyTradingRowEnumerator
in the example).MyHost
uses class Order2Go
to get trading day offset, trading week offset, and trading properties. Order2Go
is also used for price history helper (the last is used for getting a candle for specific time).Order2Go
also keeps information about the trading orders requested by the strategy. In the example below the information is kept in a dictionary where strategy instance is a key, and the list with information about corresponding orders is a value. A helper class OrderInfo
is used to keep information about an order (request ID, strategy’s cookie, and time of request).Order2Go
.GetTradingProperty
gets trading properties like baseUnitSize
or canCreateEntry
.It uses helper functions GetInstrument
and GetAccount
. These helper functions extract instrument and account from the list of arguments for trading property. Function GetTradingProperty
also uses CheckPermissions
function for permission properties. CheckPermissions
converts an integer returned by permission checker for specific instrument into the boolean value. Function GetPrimaryKey
gets a primary key for the table like OrderID
for Orders
table.MyHost
class calls history manager class (HistoryMgr
) in order for getHistory
requests of the strategy.HistoryMgr
class.HistoryMgr
is used to prepare price streams: “bid” and “ask” sources for the strategy, as well as streams for strategy’s getHistory
requests. History manager keeps strategy instance with a list of price streams for this instance. PrepareTicks
to create “bid” and “ask” sources for strategy. First it gets historic prices. It this case application uses synchronous call because prices have to be filled in order to create strategy instance. There could be new ticks coming from the moment of the GetPriceHistory
call to the moment of getting the result with 300 ticks. Function GetPendingEvents
of the trading desk is used to get new ticks. Function MergeTicksHistWithTicksBuffer
is used to merge historic and new ticks. Ticks should not overlap, so there is a helper function IsSamePatternStarted
(it is used to check for the exact match between history ticks and tick buffer to avoid overlapping when merging).GetPriceHistoryAsync
for getPriceHistory
request from strategy. One of the arguments is a cookie
from the strategy to be used in notifyFinished
. GetPriceHistoryAsync
function creates an empty stream, and sends an asynchronous call to get historic prices. Application does not wait for prices to be filled. Instead it gets request ID for the history request (it would be used in event OnPriceHistoryCompleted
). The empty stream is attached to the instance of a strategy together with supporting information (price history request ID, cookie
for notifyFinished
). The stream would be kept with a flag PriceHistoryCompleted
as “false” until prices would be filled.ProcessPendingEvents
checks pending events, and in case there were new prices (“new offer” events), new ticks are added for all completed streams (ticks are kept in a buffer for uncompleted streams).ProcessTick
adds new tick for all corresponding tickets (the tick should be stored in the tick buffer in case stream is not filled yet).AddTick2Stream
adds a tick to tick stream or bar stream.Attach2Instance
attaches price stream to strategy instance to keep them together in a dictionary. Class Ticket
is used to keep all this information.Ticket
holds price stream itself (could be “tick” or “bar), flag showing whether price stream was filled, request id for asynchronous GetPriceHistoryAsync
method (string to be used in OnPriceHistoryCompleted
), asynchronous operation cookie
(an integer to be sent to AsyncOperationFinished
function of the strategy when data is loaded), flag indicating whether price stream keeps prices up to "now", and “tick buffer” to keep ticks from the moment of calling GetPriceHistory
until price history would be completed.setTimer
and killTimer
commands. MyHost
class calls timers manager class (TimersMgr
) for setTimer
and killTimer
commands of the strategy. TimersMgr
uses helper class TimerInfo
. Function AddTimer
starts the timer and keeps information about the timer in the list timersInfo
. When “timer elapsed” event happens (function timer_Elapsed
) the timer is found in the list timersInfo
, and strategy instance is notified with cookie belonging to this timer as an argument for AsyncOperationFinished
. Function KillTimer
stops the timer. The timer is found in the list timersInfo
by using timer ID.MyStrategyCallBack
implements StrategyCallBack
class.MyStrategyCallBack
class for “Buy” and “Sell” signals (sending alerts) and for executing trading orders if trading is allowed. executeOrder
and alert
functions are the heart of the application. Function executeOrder
needs to get arguments for creating an order. executeOrder
uses helper functions GetStringParamFromValueMap
and GetNumberParamFromValueMap
to extract string or number parameter from ValueMap
argument. executeOrder
also uses helper function GetValueFromTable
if the argument for creating an order can be extracted from the trading table. Function GetValueFromTable
gets value for the specific column of the trading table where the row is determined by the primary key value.GetTimeInForce
converts a string for time in force (“GTC” for “good till cancelled”, “IOC” for “immediate or cancel”, “FOK” for “fill or kill”) into an integer expected by Order2Go functions creating an order.GetValuesForRangeOrder
is used for the “range” orders (“OM” or “CM”). If minimum and maximum rates are used, this function will calculate “medium” value and range in points (minimum and maximum values are not used by “classic” Order2Go functions for creating an order).GetStopLimitType
gets an integer to be used as a type of “Stop” and “Limit” for creating an order. OpenTrade3Async
, CloseTrade2Async
, CreateEntryOrder3Async
, and ChangeEntryOrderStopLimit3Async
) for creating an order. Each of these functions returns request ID. Function AttachToInstance
of Order2Go
class would keep request ID and the cookie in a dictionary together with the time of request. When an event OnRequestCompleted
or OnRequestFailed
happens, the strategy instance would be notified. In order to avoid keeping too many orders you can remove orders with request time older than one minute from the dictionary.Users browsing this forum: No registered users and 1 guest