Sierra Chart - Automated Trading From an Advanced Custom Study

Automated Trading From an Advanced Custom Study

The information on this page applies the latest Sierra Chart version.

On This Page

This page has been updated and applies to version 632 and higher.


General Information about Trading From an Advanced Custom Study

This page provides documentation for automated trading functions for the Sierra Chart Advanced Custom Study Interface and Language (ACSIL). If you are not familiar with ACSIL, please see the Advanced Custom Study Interface and Language page.

Sierra Chart provides a fully managed environment for automated trading to make it very easy to perform automated trading and not get involved in all the low-level details of keeping track of positions and working orders. Sierra Chart provides a very solid, stable and robust environment for automated trading. Support for server-side brackets to exit a position entered through automated trading, is supported. Unmanaged automated trading is supported.

The trading functions in the Advanced Custom Study Interface work the same as the BuyEntry, SellEntry, BuyExit, SellExit worksheet columns in the Worksheet System For Trading study. Orders are submitted through the sc.BuyEntry, sc.BuyExit, sc.SellEntry and sc.SellExit trading functions that process Buy Entries, Buy Exits, Sell Entries, and Sell Exits. These functions examine the Session Position and Working Orders for the symbol of the chart that your trading study is applied to, and the related Auto Trade Management variables and will only send an order (whether simulated or live) if the right conditions are met. For more information about these functions, please see the Submitting And Modifying An Order Through the Advanced Custom Study Interface section.

Automated trading order processing occurs when the sc.BuyEntry, sc.BuyExit, sc.SellEntry and sc.SellExit trading functions are called, but do not occur on historical bars or while historical data is being downloaded. On historical bars and during a historical data download, these Entry and Exit Order Action functions are ignored and will return SCT_SKIPPED_FULL_RECALC or SCT_SKIPPED_DOWNLOADING_HISTORICAL_DATA. Only real time updating or data added to the chart during a replay can cause order processing. This is designed for safety. For example, if you are running a replay, since replays start at the very last visible bar where you begin the replay, all historical bars prior to that will cause these functions to return SCT_SKIPPED_FULL_RECALC since a recalculation occurs on a chart reload and replays perform a chart reload.

[Top]

Processed Order Quantities

When submitting orders from an Advanced Custom Study, the internal extra arrays 4, 5, 6, and 7 of sc.Subgraph[23] should not be used because the automated trading system in Sierra Chart will use these 4 arrays internally to indicate the total trade order quantities for each bar. Use of these arrays by you is optional. You can use these arrays and check for a nonzero quantity to determine if you should put a Buy/Sell indicator at the corresponding index on the chart, such as an arrow by using an arrow subgraph Draw Style. These arrays are also used by the sc.AllowOnlyOneTradePerBar variable.

The value of an array element at [index] as described above specifies the number of shares/contracts that were processed during that bar. Note that the quantity indicated within the array element may not necessarily be the quantity specified for the order. For example, if you have a long Session position of +3 and perform a Sell Entry of quantity 1 with sc.SupportReversals set to 1 (TRUE), the order system will automatically detect that you want a reversal and will sell 4 contracts so that the position will end up being -1 (short position of quantity 1). In this case, sc.Subgraph[23].Arrays[6][] will indicate 4 instead of 1 at the index where the Sell Entry function was called. Additionally, if another order is processed at the same index, the quantity will not replace the quantity already contained within the array element but add to it.

These arrays are only filled in during real time updating or while replaying a chart. On a chart recalculate or reload, the arrays will be cleared and reset back to 0.

[Top]

Advanced Custom Study Interface Variable Members Relevant to Trading

For a complete list of the variable members of the Advanced Custom Study Interface that are related to trading, please see the Variables section on the Auto Trade Management page. Variables which are specific for ACSIL trading and not Worksheet trading systems, are listed below. For the other members of the Advanced Custom Study Interface, see the Definitions of Advanced Custom Study Interface Members page.

sc.AllowOnlyOneTradePerBar

The default value for this variable is 1 (TRUE). When this variable is set to 1 (TRUE) (by default), only one trade for each Order Action type is allowed for a single chart bar. When you have exceeded one trade per bar for a particular Order Action, the Order Action functions will return SCT_SKIPPED_ONLY_ONE_TRADE_PER_BAR. This variable relies upon the data in arrays sc.Subgraph[23].Arrays[4–7] which indicate the actual traded quantities for each bar. These arrays are cleared on a chart reload (Chart >> Reload and Recalculate). Therefore, more than one trade on the last bar could occur if you do a reload.

Once a Buy Entry is called, additional Buy Entries will be ignored until there is a new bar. Buy Exits, Sell Entries, Sell Exits all work the same way, but separate from each other. For example, you may have one Buy Entry and one Sell Entry at the same bar, just not two Buy Entires or two Sell Entries. This variable does put some restrictions on what a trading study can do. For most cases, having 1 trade per bar should be sufficient. We recommend that you leave this variable as 1 (TRUE) unless you are confident you're not going to run into unexpected logic in your code which could cause numerous or endless trades to occur on a bar. If you want more control over your trading, then set this to 0 (FALSE). If you set this to 0 (FALSE), please thoroughly test your trading study through backtesting and in Sierra Chart Trade Simulation Mode.

This variable activates internal logic to prevent unexpected trades from occurring. An example of a programming error that could occur is if a study continuously makes trade Entries and trade Exits on the same bar. This can be due to honest mistakes and would require a more advanced programmer to really evaluate every condition that could happen.

sc.GlobalTradeSimulationIsOn

This variable is set to 1 (TRUE) when Sierra Chart Trade Simulation Mode is enabled on the Trade menu, and set to 0 (FALSE) when Trade Simulation Mode on the Trade menu is disabled. Note that this variable is not connected to sc.SendOrderSignalToOrderSystem. It only indicates whether or not Trade >> Trade Simulation Mode On on the menu is checked. You can determine if an order will be sent to the connected Trade Service by checking if sc.SendOrderSignalToOrderSystem is set to 1 (TRUE), and sc.GlobalTradeSimulationIsOn is set to 0 (FALSE).

[Top]

Submitting and Modifying An Order Through the Advanced Custom Study Interface

Entry and Exit Order Submission Functions

Order submission is done through the Buy Entry, Buy Exit, Sell Entry and Sell Exit Order Action functions.

These functions take a s_SCNewOrder structure parameter.

These Entry and Exit functions that are documented here, can only be used with ACSIL studies that use Automatic Looping. This is when sc.AutoLoop = 1 is set in the code block for setting the study's configuration and defaults at the top of your study function. There are versions of these functions for manual looping, but they are undocumented. The only difference is the ones for manual looping have an Index parameter.

Buy Entry

int sc.BuyEntry(s_SCNewOrder& NewOrder); Note: For use with Auto-Looping only.

Description: This function requires a s_SCNewOrder structure parameter. For a complete description of the behavior of this Order Action type, refer to the Auto Trade Management page.

Returns: A positive return value represent a successful Buy Order. The positive return value is the quantity of the order that was processed on success. If the return value is negative, no order was processed. The negative number is either SCTRADING_ORDER_ERROR on failure. In this case, the reason for the error is logged in the Trade Service Log. Or it can be a skipped order code that is one of the SkippedOrderCode constants.

Buy Exit

int sc.BuyExit(s_SCNewOrder& NewOrder); Note: For use with Auto-Looping only.

Description: This function requires a s_SCNewOrder structure parameter. For a complete description of the behavior of this Order Action type, refer to the Auto Trade Management page.

Returns: Positive return values represent a successful Sell Order, the positive return value is the quantity of the order that was processed on success. If the return value is negative, no order was processed. The negative number is either SCTRADING_ORDER_ERROR on failure that was logged in the Trade Service Log, or a skipped order code that is one of the SkippedOrderCode constants.

Sell Entry

int sc.SellEntry(s_SCNewOrder& NewOrder); Note: For use with Auto-Looping only.

Description: This function requires a s_SCNewOrder structure parameter. For a complete description of the behavior of this Order Action type, refer to the Auto Trade Management page.

Returns: A positive return value represent a successful Sell Order. The positive return value is the quantity of the order that was processed on success. If the return value is negative, no order was processed. The negative number is either SCTRADING_ORDER_ERROR on failure. In this case, the reason for the error is logged in the Trade Service Log. Or a skipped order code that is one of the SkippedOrderCode constants.

Sell Exit

int sc.SellExit(s_SCNewOrder& NewOrder); Note: For use with Auto-Looping only.

Description: This function requires a s_SCNewOrder structure parameter. For a complete description of the behavior of this Order Action type, refer to the Auto Trade Management page.

Returns: Positive return values represent a successful Buy Order, the positive return value is the quantity of the order that was processed on success. If the return value is negative, no order was processed. The negative number is either SCTRADING_ORDER_ERROR on failure that was logged in the Trade Service Log, or a skipped order code that is one of the SkippedOrderCode constants.

Modifying an Order

int sc.ModifyOrder(s_SCNewOrder& OrderModification);

Description: Order modifications are done with the sc.ModifyOrder() function. Only the price or prices of an order and the order quantity can be modified. You need to pass in a s_SCNewOrder structure to this function. This is the same structure used for the Order Action functions for order entry. When this function is called, an order modification request will be sent to the Sierra Chart trade simulation system or the connected trading service depending upon whether you are in Trade Simulation Mode and whether the order was originally a simulated order.

The entire s_SCNewOrder does not need to be filled in, except for the InternalOrderID member. That must be set to the InternalOrderID of the order that you want to modify. The InternalOrderID can be obtained when you submitted the order. The InternalOrderID can also be obtained with the sc.GetOrderByIndex() function. Only the members that you want to modify, need to be set. For example, if you only want to change the quantity of an order, simply pass in a s_SCNewOrder structure with the OrderQuantity member set to the new quantity and the InternalOrderID set.

Only the following members of the s_SCNewOrder can be set when modifying an order: OrderQuantity, LimitPrice, StopPrice, InternalOrderID. All other members are not relevant because only price and quantity can be modified.

In the case of Target and Stop orders specified with a parent order (Target1Offset, Stop1Offset), when these orders have been submitted, they exist as individual orders that can be individually modified. If you wish to modify the prices of these Attached Orders, then you will need to set the LimitPrice and/or StopPrice members, not the Offset members of the s_SCNewOrder structure. After order submission, these prices are actual prices and never offsets. The order prices for all orders can be clearly seen in the Trade >> Trade Orders Window.

Returns: 1 on a successful order modification. This does not mean the order modification is successful. Only that it succeeded in sending it the Sierra Chart order system. If there is no order found to modify, the function returns SCTRADING_ORDER_ERROR.

For a code example to modify an Attached Order, refer to the scsf_TradingExampleWithAttachedOrdersDirectlyDefined function in the /ACS_Source/tradingsystem.cpp file.

Example

s_SCNewOrder ModifyOrder;
ModifyOrder.InternalOrderID = Target1OrderID;
ModifyOrder.LimitPrice = NewLimit;

sc.ModifyOrder(ModifyOrder);

s_SCNewOrder Structure Members

The Order Action and the order modification functions require a s_SCNewOrder structure. The following is a description of each member of the s_SCNewOrder structure.

[int] OrderQuantity

Specifies order quantity for the order. By default this is 0, in which case it will be automatically set to 1 upon order submission of a Buy/Sell Entry order. In the case of a Buy Exit or Sell Exit, if this is set to 0, then the position will be flattened. If it is set to a nonzero number in the case of an Exit, and the quantity is less than the quantity required to flatten the current position, then that will be the order quantity. If it exceeds the quantity necessary to flatten the position, then the current position will just be flattened and this quantity will be ignored. The current position quantity is always determined by the Session Position Data maintained by Sierra Chart.

[SCOrderTypeEnum] OrderType

Specifies the order type of a new order that you would like to submit. For more information about valid Order Types, please see the SCOrderTypeEnum constants section. Order Modifications ignore this member. So it's not possible to modify the order type after the original order has been submitted.

[double] LimitPrice

Specifies the Limit price of the order. This member is only used when the OrderType is set to SCT_LIMIT, SCT_MIT or SCT_STOPLIMIT. In the case of SCT_LIMIT or SCT_MIT, if the LimitPrice is set to 0, then it will be set to the current Bid price if the order is a sell order or it will be set to the current Ask price if the order is a buy order. This price is always rounded to the nearest tick upon final order submission. So it does not have to be precise.

[double] StopPrice

Specifies the Stop Price of the order. This member is only used when the OrderType is set to SCT_STOP or SCT_STOPLIMIT. This price is always rounded to the nearest tick upon final order submission. So it does not have to be precise.

[int] InternalOrderID

This member you do not set. When you call one of the Order Action functions (sc.BuyEntry,...), then this will be set to the Sierra Chart internal InternalOrderID of the order that has been accepted. If it is not set and remains at 0, then this means the order signal was ignored. This is explained in more detail with the documentation for each of the Order Action functions. This InternalOrderID is used to cancel the order or modify the order.

When you submit an submit order and get the InternalOrderID for a subsequent order modification or cancellation, most likely you will not need it at that time and you need to remember it. Therefore, assign it to a Persistent Variable for use on subsequent calls into your function.

[SCString] TextTag

This is an optional text string that can be set to any text that you want, to help identify an order. It is displayed at the end of the Last Order Action Source field in the Trade >> Trade Orders Window and the Trade >> Trade Activity Log. It is automatically prefixed with the Chart Name and your Study Name. So you will have clear identification as to the source of an order.

[double] Target1Offset

[double] Target2Offset

[double] Target3Offset

[double] Target4Offset

This specifies the offset for a Target Attached Order (1, 2, 3, or 4) to submit along with the parent order. This only applies to the BuyEntry and SellEntry Order Actions. When this is set to a nonzero value, then the Attached Order will be specified. Otherwise, it will not. Use an actual price value. For example, to specify an actual offset of 2 points from the parent order, use 2. For the Attached Order to actually be attached, it is necessary to set sc.SupportAttachedOrdersForTrading to TRUE (1). When this variable is set, you will notice that the associated Trade Window for the chart that the trading system is applied to, will list this Target 1, 2, 3, or 4 order. The Target order is a Limit order type.

[int] Target1InternalOrderID

[int] Target2InternalOrderID

[int] Target3InternalOrderID

[int] Target4InternalOrderID

These members are set to the Internal Order IDs of the Target 1, 2, 3 or 4 orders respectively, after you call one of the Order Action functions and the order has been accepted by the Auto-Trade Management System.

[double] Stop1Offset

[double] Stop2Offset

[double] Stop3Offset

[double] Stop4Offset

This specifies the offset for a Stop Attached Order (1, 2, 3 or 4) to submit along with the parent order. This only applies to the BuyEntry and SellEntry Order Actions. When this is set to a nonzero value, then the Attached Order will be specified. Otherwise, it will not. Use an actual price value. For example, to specify an actual offset of 2 points from the parent order, use 2. For the Attached Order to actually be attached, it is necessary to set sc.SupportAttachedOrdersForTrading to TRUE (1). When this variable is set, you will notice that the associated Trade Window for the chart that the trading system is applied to, will list this Stop 1, 2, 3 or 4 order. The Stop order is a Stop order type.

[int] Stop1InternalOrderID

[int] Stop2InternalOrderID

[int] Stop3InternalOrderID

[int] Stop4InternalOrderID

This is set to the Internal Order ID of the Stop 1, 2, 3 or 4 order after you call one of the Order Action functions and the order has been accepted by the Auto-Trade Management System.

[unsigned int] OCOGroup1Quantity

[unsigned int] OCOGroup2Quantity

[unsigned int] OCOGroup3Quantity

[unsigned int] OCOGroup4Quantity

Set this to the Order Quantity you want for the Target and Stop Attached Orders 1, 2, 3 or 4 respectively. Keep in mind that the total of all the Attached Order OCO groups must equal the quantity of the parent. If they do not, the order will be rejected. This is an optional variable to set and will be automatically set if left at the default of 0.

[Top]

Getting Order Information

sc.GetOrderByOrderID

int sc.GetOrderByOrderID(int InternalOrderID, s_SCTradeOrder& OrderDetails);

Description: The GetOrderByOrderID function returns the order details of the order specified by the InternalOrderID. This is the same order details you see in the Trade >> Trade Orders Window. The order details are copied to the s_SCTradeOrder structure that you pass in.

Returns: 1 on success or SCTRADING_ORDER_ERROR on an error.

sc.GetOrderByIndex

int sc.GetOrderByIndex(int OrderIndex, s_SCTradeOrder& OrderDetails);

Description: The GetOrderByIndex function returns the order details of an order based on an index value. This is a zero based index. Beginning from 0, you can increment the index by 1 and keep calling GetOrderByIndex until the function returns SCTRADING_ORDER_ERROR indicating there are no more orders. You will only be able to get orders that have the same symbol as the chart the trading study is applied to. The order details returned are the same as what you see in the Trade >> Trade Orders Window. The order details are copied to the s_SCTradeOrder structure that you pass in.

Returns: 1 on success or SCTRADING_ORDER_ERROR on an error.

When using sc.GetOrderByIndex, if you are in global Trade Simulation Mode or sc.SendOrderSignalToOrderSystem is set to 0, then you will only be able to get simulated orders. If you are not in global Trade Simulation Mode and the sc.SendOrderSignalToOrderSystem is set to 1 (true), then you will only be able to get non-simulated orders.

s_SCTradeOrder Structure Members

[int] InternalOrderID

The InternalOrderID of the order as shown in the Trade >> Trade Orders Window.

[SCString] Symbol

The Symbol of the order as shown in the Trade >> Trade Orders Window.

[SCString] OrderType

The Order Type of the order as shown in the Trade >> Trade Orders Window.

[int] OrderQuantity

The Order Quantity of the order as shown in the Trade >> Trade Orders Window.

[int] FilledQuantity

The FilledQuantity member is set to the number of shares/contracts that have already been filled. This is an important member that you may need to check if there is a partial fill. A working order that is only partially filled does not update the Session Position data. It's only when an order completely fills that the Session Position data is updated and will then reflect the position from the order.

[int] BuySell

Whether this order is Buy or Sell order as shown in the Trade >> Trade Orders Window. This is an integer enumeration and can be either BSE_BUY or BSE_SELL.

[double] Price1

The 1st Price of the order.

[double] Price2

The 2nd Price of the order.

[double] AvgFillPrice

The average fill price for the order.

AvgFillPrice Code Example:

// Enter a new order as a Buy Entry order.
s_SCNewOrder NewOrder;
NewOrder.OrderQuantity = 1;
NewOrder.OrderType = SCT_MARKET;
sc.BuyEntry(NewOrder);


// Once the order fills, after calling the above function, we can
// determine the actual fill price with the following code. Keep in
// mind that we may not obtain the fill price at this moment, but
// on a subsequent call into the study function.

// Get the available order details for the submitted order by using
// the InternalOrderID that was assigned after calling the Order
// Action function sc.BuyEntry. InternalOrderID will only
// be set if the Order Action function returns a value > 0.
if (NewOrder.InternalOrderID != 0)
{
  s_SCTradeOrder ListedOrderDetails;
  int Result = sc.GetOrderByOrderID(NewOrder.InternalOrderID,
    ListedOrderDetails);

  if (Result != SCTRADING_ORDER_ERROR)
  {
    double FillPrice = ListedOrderDetails.AvgFillPrice;
  }
}

[int] OrderStatusCode

The following are the various constants that the OrderStatusCode can be set to. They simply indicate what the status of the order is. They are self descriptive. For more details, refer to these constants in the /ACS_Source/scconstants.h file in the folder where Sierra Chart is installed to.

[int] ParentInternalOrderID

If the order is an Attached Order, then this member is set to the internal order ID of the Parent. Otherwise it will be 0. If it is 0, then you know it's not an Attached Order. If you are trying to find Attached Orders to be able to modify them after the Parent order is submitted, then what you need to do is use the sc.GetOrderByIndex() function and iterate through all of the orders. You want to look for the orders that have the OrderStatusCode set to SCT_OSC_WORKING and have a non-zero ParentInternalOrderID. These will be the active Attached Orders. Once you find them you will then have access to the InternalOrderID of the Attached Order. This internal order ID can be used with the sc.ModifyOrder() function to modify the price or quantity of the order.

[int] LinkID

This member will be set to the Link ID of the order you see in the Trade >> Trade Orders Window. If orders are linked together they will have a Link ID. Orders will be linked together if they are split into smaller order quantities when Attached Orders are used and the Attached Orders are set to the OCA Group All Groups.



[Top]

Canceling Orders

sc.CancelOrder

int sc.CancelOrder(int InternalOrderID);

Description: Cancels the order with the InternalOrderID that is passed in. The InternalOrderID is obtained when you called one of the order submission functions and an order was accepted. The InternalOrderID can also be determined with the sc.GetOrderByIndex() function.

With this function, when sc.SendOrderSignalToOrderSystem is set to FALSE, it only applies to simulated orders and there will be no commands sent to the connected trade service.

Returns: 1 on success, SCTRADING_ORDER_ERROR on failure.

sc.CancelAllOrders

int sc.CancelAllOrders();

Description: Cancels all working orders of the symbol that the trading study is applied to.

With this function, when sc.SendOrderSignalToOrderSystem is set to FALSE, it only applies to simulated orders and there will be no commands sent to the connected trade service.

Returns: 1 on success, SCTRADING_ORDER_ERROR on failure.

sc.FlattenAndCancelAllOrders

int sc.FlattenAndCancelAllOrders();

Description: Flattens your position based upon the Session Position of the symbol of the chart that the trading study is applied to and cancels all working orders for the same symbol.

With this function, when sc.SendOrderSignalToOrderSystem is set to FALSE, it only applies to simulated orders and there will be no commands sent to the connected trade service.

Returns: 1 on success, SCTRADING_ORDER_ERROR on failure.

[Top]

Getting Position Data

sc.GetServicePosition and sc.GetSessionPosition

int sc.GetServicePosition(s_SCPositionData& PositionData);

int sc.GetSessionPosition(s_SCPositionData& PositionData);

Description: These functions return the position data into the structure PositionData. This structure is of type s_SCPositionData.

There are 2 different functions to get position data. GetServicePosition is for getting the Service Position data which corresponds to the position data on the Service Positions tab of the Trade >> Positions Window. GetSessionPosition is for getting the Session Position data which corresponds to the position data on the Session Positions tab of the Trade >> Positions Window. When an ACSIL trading system is using Trade Simulation mode, then the Session position data is for trades made in simulation mode only. For more information about the Service and Session Position data, see Positions Window.

Returns: Always returns 1.

Example

//Get Session Position data for the symbol that this trading study is applied to.
s_SCPositionData PositionData;
int Result = sc.GetSessionPosition(PositionData);
double LastTradeProfitOrLoss = PositionData.LastTradeProfitLoss;

s_SCPositionData Structure Members

[SCString] Symbol

The Symbol of the position as shown in the Positions Window. For simulated orders, the symbol will be prefixed with [SIM].

[int] PositionQuantity

The Position Quantity of the position as shown in the Positions Window.

[double] AveragePrice

The Average Fill Price of the position as shown in the Positions Window.

[double] OpenProfitLoss

The Open Profit/Loss of the current position for the symbol as shown in the Positions Window.

[double] CumulativeProfitLoss

The Cumulative Profit/Loss for the symbol as shown in the Positions Window. This member is only available when getting the Session Position data.

[double] DailyProfitLoss

The Daily Profit/Loss for the symbol as shown in the Positions Window. This member is only available when getting the Session Position data. The Daily Profit/Loss is reset when a new day begins, according to the Time Zone setting in Sierra Chart, and there is a trade which closes or reduces the position for the symbol.

[int] WinTrades

The number of winning trades for the symbol as shown in the Positions Window. This is only available when getting the Session Position data.

[int] LoseTrades

The number of losing trades for the symbol as shown in the Positions Window. This is only available when getting the Session position data.

[int] TotalTrades

The total number of trades for the symbol as shown in the Positions Window. This is only available when getting the Session position data.

[double] MaximumOpenPositionLoss

The maximum open position loss or Maximum Adverse Excursion (MAE) of the position as shown in the Positions Window. This is only available when getting the Session position data.

[double] MaximumOpenPositionProfit

The maximum open position profit or Maximum Favorable Excursion (MFE) of the position as shown in the Positions Window. This is only available when getting the Session position data.

[double] LastTradeProfitLoss

The Profit or Loss for the last trade. This member is updated when a trade is made that closes out a position or reduces the size of the position. This is only available when getting the Session position data.

[int] PositionQuantityWithAllWorkingOrders

This variable indicates the session position quantity combined with the quantities of all working orders. Working Sell orders decrease the position and Buy orders increase the position.

[int] PositionQuantityWithExitWorkingOrders

This variable indicates the session position quantity combined with the quantities of Working orders that will reduce the size of the position. Working Sell orders decrease the position and Buy orders increase the position.

[int] WorkingOrdersExist

This variable will be set to a nonzero value when there are working orders. Otherwise, it will be 0.

[Top]

Constants

This section lists various constant identifiers used by ACSIL trading functions and the meaning of them.

SCTRADING_ORDER_ERROR

On an error, the ACSIL trading functions will return the SCTRADING_ORDER_ERROR (-1) constant to indicate an error. A more detailed error message is listed in the Trade >> Trade Service Log.

SCOrderTypeEnum constants

The Order Type constants are currently:

SkippedOrderCode Constants

These constants indicate specific reasons an order may have been skipped when using one of the Order Action ACSIL trading functions (sc.BuyEntry(),...).

[Top]

Example Code

For an ACSIL trading system example, please review the file tradingsystem.cpp inside the ACS_Source folder in the Sierra Chart installation folder. This contains a simple ACSIL trading study which uses the ACSIL trading functions. This trading study uses the same logic as the Worksheet System for Trading example in the Creating a System for Automated Trading section.

The system supports the BuyEntry, BuyExit, SellEntry, SellExit functions.

We recommend that you understand everything in this example before you begin writing your own ACSIL Trading study.

How to Use the Trading Example

  1. Select Analysis >> Studies >> Add Custom Study>> Sierra Chart Custom Studies and Examples.
  2. In the list select Trading Example.
  3. Press Add.
  4. Press Settings on the Chart Studies window to display the Study Settings window.
  5. Set the Enabled input to Yes.
  6. Initially, the study will not display any Buy or Sell arrows on the chart because a trading system will only work with new data added to the chart during live updating or a Replay. Therefore you will need to wait for some live data to be received in the chart or you can perform back-testing through a replay.

[Top]