#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
// The order action type.
private C_ActionType _actionType;
// The order TIF.
private C_TIF _TIF;
// The order quantity.
private double _quantity;
// 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="C_ActionType" default="BUY">The order action type</param>
/// <param name="TIF" type="C_TIF" default="DAY">The order TIF</param>
/// <param name="quantity" type="Double" default="0">The order quantity</param>
/// <param name="comment" type="String">The order comment</param>
public void OnInitialize(
C_ActionType actionType,
C_TIF TIF,
double quantity,
string comment)
{
_actionType = actionType;
_TIF = TIF;
_quantity = quantity;
_comment = comment;
}
#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)
{
// Set the underlying symbol for the script.
SymbolSwitch(symbolIndex);
// Submit a market order.
BrokerMarket(_actionType, _quantity, _TIF, _comment);
}
#endregion
}
}