Support Board
Date/Time: Tue, 26 Nov 2024 04:49:54 +0000
Post From: Liquidation ACSIL
[2024-01-09 21:44:07] |
User373245 - Posts: 42 |
/ Set Liquidation Time int Hour = 19; int Minute = 0; int Second = 0; SCDateTime liquidationTime = SetTime(HMS_TIME(Hour, Minute, Second); I cant get this to compile. this will compile int hour = 18; int minute = 00; int second = 0; SCDateTime liquidatoinTime; liquidatoinTime.SetTimeHMS(hour, minute, second); but neither liquidate the trade...it does however not close it out immediately as it opens??? I have played around with a couple different options and none of them flatten the trade...This does compile. Possible the if statement needs to be inside the new order loop or I need to get the order number also...which I also tired from the SC instructions page but the order came up as zero in the log and that did not work either! ??? #include "sierrachart.h" SCDLLName("Phil Code - Automated Trading AUDJPY") #include<iostream> using namespace std; 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 = "AUDJPY AUTO"; 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 SCDateTime CurrentDateTime; CurrentDateTime = sc.CurrentSystemDateTime; SCDateTime CurrentTime; CurrentTime = CurrentDateTime.GetTime(); //liquidationTime int Hour = 18; int Minute = 00; int Second = 0; SCDateTime liquidationTime; liquidationTime.SetTime(HMS_TIME(18,00,00)); int &RememberedOrderID = sc.GetPersistentInt(1); bool CancelOrder = false; int& TradeFlattened = sc.GetPersistentInt(0); //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.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.Target1Offset = 4.5 * sc.TickSize; NewOrder.Stop1Offset = 3.5 * sc.TickSize; sc.MaximumPositionAllowed = OrderQuantity; RememberedOrderID = NewOrder.InternalOrderID; 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.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.Target1Offset = 4.5 * sc.TickSize; NewOrder.Stop1Offset = 3.5 * sc.TickSize; sc.MaximumPositionAllowed = OrderQuantity; RememberedOrderID = NewOrder.InternalOrderID; sc.SellEntry(NewOrder); } // cancel working orders if(TradeFlattened == 0 && CurrentTime >= liquidationTime && CurrentTime < liquidationTime + SCDateTime::SECONDS(1)) { sc.FlattenAndCancelAllOrders(); TradeFlattened = 1; } } |