#region Namespaces using System; using System.IO; using System.Linq; #endregion namespace ScriptCode { /// <summary> /// Alert scripts are used for executing custom actions as part of the actions executed by an alert. /// </summary> public partial class MyAlert : AlertScriptBase // NEVER CHANGE THE CLASS NAME { #region Variables // Use for the order action type. private IQ_ActionType _actionType; // Use for the order TIF. private IQ_TIF _TIF; // Use for the order quantity. private double _quantity; // Use for the order tick offset from the last bar close. private double _tickOffset; // Use for the order stop price. private double _stopPrice; // Use for the order limit price. private double _limitPrice; // Use for the order comment. private string _comment; #endregion #region OnInitialize /// <summary> /// This function is used for accepting the script parameters and for initializing the script prior to all other function calls. /// </summary> /// -------------------------------------------------------------------------------------------------- /// PLEASE USE THE SCRIPT WIZARD (CTRL+W) TO ADD, EDIT AND REMOVE THE SCRIPT PARAMETERS /// -------------------------------------------------------------------------------------------------- /// YOU MUST SET A PARAM TAG FOR EACH PARAMETER ACCEPTED BY THIS FUNCTION. /// ALL PARAM TAGS SHOULD BE SET IN THE 'OnInitialize' REGION, RIGHT ABOVE THE 'OnInitialize' FUNCTION. /// THE ORDER OF THE TAGS MUST MATCH THE ORDER OF THE ACTUAL PARAMETERS. /// REQUIRED ATTRIBUTES: /// (1) name: The exact parameter name. /// (2) type: The type of data to collect from the user: /// Set to "Integer" when the data type is 'int' /// Set to "IntegerArray" when the data type is 'int[]' /// Set to "DateTime" when the data type is 'long' /// Set to "DateTimeArray" when the data type is 'long[]' /// Set to "Boolean" when the data type is 'bool' /// Set to "BooleanArray" when the data type is 'bool[]' /// Set to "Double" when the data type is 'double' /// Set to "DoubleArray" when the data type is 'double[]' /// Set to "String" when the data type is 'string' /// Set to "StringArray" when the data type is 'string[]' /// OPTIONAL ATTRIBUTES: /// (3) default: The default parameter value is only valid when the type is Integer, Boolean, Double, String or an API Type. /// (4) min: The minimum parameter value is only valid when the type is Integer or Double. /// (5) max: The maximum parameter value is only valid when the type is Integer or Double. /// EXAMPLE: <param name="" type="" default="" min="" max="">Enter the parameter description here.</param> /// -------------------------------------------------------------------------------------------------- /// <param name="actionType" type="IQ_ActionType" default="Buy">The order action type</param> /// <param name="TIF" type="IQ_TIF" default="DAY">The order TIF</param> /// <param name="quantity" type="Double" default="0">The order quantity</param> /// <param name="tickOffset" type="Double" default="1">The tick offset</param> /// <param name="comment" type="String">The order comment</param> /// <param name="stopPrice" type="Double" default="0">The order stop price</param> /// <param name="limitPrice" type="Double" default="0">The order limit price</param> public void OnInitialize( IQ_ActionType actionType, IQ_TIF TIF, double quantity, double tickOffset, string comment, double stopPrice, double limitPrice) { // Set the script parameter to a variable. _actionType = actionType; // Set the script parameter to a variable. _TIF = TIF; // Set the script parameter to a variable. _quantity = quantity; // Set the script parameter to a variable. _tickOffset = tickOffset; // Set the script parameter to a variable. _comment = comment; // Set the script parameter to a variable. _stopPrice = stopPrice; // Set the script parameter to a variable. _limitPrice = limitPrice; } #endregion #region OnAction /// <summary> /// This function is called when the alert processes its actions on one of the data grid rows. /// </summary> /// <param name="symbolIndex" type="Integer">The symbol index of the symbol being displayed in the data grid row (or -1 if none is available)</param> /// <param name="index" type="Integer">The item index of the item being displayed in the data grid row, such as the order index, trade index and position index (or -1 if none is available)</param> public override void OnAction( int symbolIndex, int index) { // Submit a stop limit order. BrokerStopLimit(_actionType, symbolIndex, _quantity, _TIF, _stopPrice, _limitPrice, _comment); } #endregion } }

The Algorithmic Trading Software for Hedge Funds and Quants