Support Board
Date/Time: Tue, 26 Nov 2024 06:28:26 +0000
[Programming Help] - Trying to cancel order at a specific time.
View Count: 174
[2023-12-28 02:19:25] |
User373245 - Posts: 42 |
Not able to flatten or cancel my orders if they have not hit the target stop and limit I want to flatten or cancel the orders at a specified time? Maybe I am formatting time incorrectly and my comparison is off. Ive tried cancel working orders and flatten and put the cancel inside the buy and sell loop as well and could not get it to work ?? Anyone have any luck with this ?? #include "sierrachart.h" SCDLLName("Code - Automated Trading AUDJPY") SCSFExport scsf_AutomatedTradingAUDJPY(SCStudyInterfaceRef sc) { SCString msg; SCInputRef Input_Enabled = sc.Input[0]; SCInputRef Input_AllowTradingOnlyDuringTimeRange = sc.Input[1]; SCInputRef Input_StartTimeForAllowedTimeRange = sc.Input[2]; SCInputRef Input_EndTimeForAllowedTimeRange = sc.Input[3]; SCInputRef Input_AllowOnlyOneTradePerBar = sc.Input[4]; SCInputRef Input_SupportReversals = sc.Input[5]; SCInputRef Input_LongSignalSelection = sc.Input[6]; SCInputRef Input_ShortSignalSelection = sc.Input[7]; SCSubgraphRef Subgraph_BuyEntry = sc.Subgraph[8]; SCSubgraphRef Subgraph_SellEntry = sc.Subgraph[9]; SCInputRef Input_CustomTime = sc.Input[10]; SCInputRef Input_OrderQuantity = sc.Input[11]; if(sc.SetDefaults){ sc.GraphName = "Automated Trading"; sc.GraphRegion = 0; sc.AutoLoop = 1; sc.GraphRegion = 0; sc.CalculationPrecedence = LOW_PREC_LEVEL; Input_AllowTradingOnlyDuringTimeRange.Name = "Allow Trading Only During Time Range"; Input_AllowTradingOnlyDuringTimeRange.SetYesNo(1); Input_StartTimeForAllowedTimeRange.Name = "Start Time For Allowed Time Range"; Input_StartTimeForAllowedTimeRange.SetTime(HMS_TIME(21, 00, 00)); Input_EndTimeForAllowedTimeRange.Name = "End Time For Allowed Time Range"; Input_EndTimeForAllowedTimeRange.SetTime(HMS_TIME(15, 00, 00)); Input_AllowOnlyOneTradePerBar.Name = "Allow Only One Trade per Bar"; Input_AllowOnlyOneTradePerBar.SetYesNo(1); Input_SupportReversals.Name = "Support Reversals"; Input_SupportReversals.SetYesNo(1); Input_LongSignalSelection.Name = "Selct Long Signal"; Input_LongSignalSelection.SetChartStudySubgraphValues(1,4, 0); Input_ShortSignalSelection.Name = "Select Short Signal"; Input_ShortSignalSelection.SetChartStudySubgraphValues(1,9, 0); Subgraph_BuyEntry.Name = "Buy Title"; Subgraph_BuyEntry.DrawStyle = DRAWSTYLE_POINT_ON_HIGH; Subgraph_BuyEntry.LineWidth = 3; Subgraph_SellEntry.Name = "Sell Title"; Subgraph_SellEntry.DrawStyle = DRAWSTYLE_POINT_ON_LOW; Subgraph_SellEntry.LineWidth = 3; Input_CustomTime.Name = "Liquidate Time"; Input_CustomTime.SetTime(HMS_TIME(17,00,00)); Input_OrderQuantity.Name = "Set lot size"; Input_OrderQuantity.SetInt(1); return; } //current time // liquidatoin time int Hour = 16; int Minute = 0; int Second = 0; int MilliSecond = 0; SCDateTime liquidationTime = SCDateTime(Hour, Minute, Second, MilliSecond); //Alert signal array SCFloatArray LongArray; sc.GetStudyArrayUsingID(Input_LongSignalSelection.GetStudyID(), Input_LongSignalSelection.GetSubgraphIndex(), LongArray); if (LongArray.GetArraySize() == 1) return; SCFloatArray ShortArray; sc.GetStudyArrayUsingID(Input_ShortSignalSelection.GetStudyID(), Input_ShortSignalSelection.GetSubgraphIndex(), ShortArray); if (ShortArray.GetArraySize() == -1) return; if(LongArray[sc.Index] == 1) { int OrderQuantity = 1; Subgraph_BuyEntry[sc.Index] = sc.Low[sc.Index]; s_SCNewOrder NewOrder; NewOrder.OrderQuantity = Input_OrderQuantity.GetInt(); NewOrder.OCOGroup1Quantity = Input_OrderQuantity.GetInt(); NewOrder.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.Target1Offset = 40 * sc.TickSize; NewOrder.Stop1Offset = 35 * sc.TickSize; sc.MaximumPositionAllowed = OrderQuantity; sc.BuyEntry(NewOrder); } if(ShortArray[sc.Index] == 1) { int OrderQuantity = 1; Subgraph_SellEntry[sc.Index] = sc.High[sc.Index]; s_SCNewOrder NewOrder; NewOrder.OrderQuantity = Input_OrderQuantity.GetInt(); NewOrder.OCOGroup1Quantity = Input_OrderQuantity.GetInt(); NewOrder.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.Target1Offset = 40 * sc.TickSize; NewOrder.Stop1Offset = 35 * sc.TickSize; sc.MaximumPositionAllowed = OrderQuantity; sc.SellEntry(NewOrder); } // cancel working orders if (sc.CurrentSystemDateTime >= liquidationTime) { sc.CancelAllOrders(); sc.FlattenPosition(); } } |
To post a message in this thread, you need to log in with your Sierra Chart account: