Support Board
Date/Time: Wed, 27 Nov 2024 11:52:06 +0000
Post From: ACSIL question
[2014-08-21 20:49:08] |
User120827 - Posts: 77 |
Does anything stand out as wrong in this code ? With the error I got compiling, it seems I forgot something when adding the extra code you gave me. It seems I did not define something. Does the "send order to trade service " item I added to settings menu look correct? thanks // The top of every source code file must include this line
#include "sierrachart.h" /***************************************************************************** For reference, please refer to the Advanced Custom Study Interface and Language documentation on the Sierra Chart website. *****************************************************************************/ // This line is required. Change the text within the quote // marks to what you want to name your group of custom studies. SCDLLName("Go Live") SCSFExport scsf_SC_TradingCrossOverExample(SCStudyGraphRef sc) { SCInputRef Line1Ref = sc.Input[0]; SCInputRef Line2Ref = sc.Input[1]; SCInputRef Enabled = sc.Input[2]; SCSubgraphRef BuyEntry = sc.Subgraph[0]; SCSubgraphRef SellEntry = sc.Subgraph[1]; SCInputRef SendOrdersToService = sc.Input[10]; if (sc.SetDefaults) { // Set the configuration and defaults sc.GraphName = "Trading CrossOver Example"; Enabled.Name = "Enabled"; Enabled.SetYesNo(0); sc.StudyDescription = "An example ."; sc.AutoLoop = 1; // true sc.GraphRegion = 0; sc.FreeDLL = 1; sc.CalculationPrecedence = LOW_PREC_LEVEL; sc.Input[3].Name = "Start Hour"; sc.Input[3].SetInt(10); sc.Input[3].SetIntLimits(0,23); sc.Input[4].Name = "Start Minute"; sc.Input[4].SetInt(0); sc.Input[4].SetIntLimits(0,59); sc.Input[5].Name = "End Hour"; sc.Input[5].SetInt(16); sc.Input[5].SetIntLimits(0,23); sc.Input[6].Name = "End Minute"; sc.Input[6].SetInt(0); sc.Input[6].SetIntLimits(0,59); Line1Ref.Name = "Line1"; Line1Ref.SetStudySubgraphValues(1, 0); Line2Ref.Name = "Line2"; Line2Ref.SetStudySubgraphValues(1, 0); BuyEntry.Name = "Buy"; BuyEntry.DrawStyle = DRAWSTYLE_POINTHIGH; BuyEntry.LineWidth = 3; SellEntry.Name = "Sell"; SellEntry.DrawStyle = DRAWSTYLE_POINTLOW; SellEntry.LineWidth = 3; sc.Input[7].Name = "Flatten and Cancel?"; sc.Input[7].SetCustomInputStrings("Yes;No"); sc.Input[7].SetCustomInputIndex(0); sc.AllowMultipleEntriesInSameDirection = false; sc.MaximumPositionAllowed = 5; sc.SupportReversals = true; // This is false by default. Orders will not go to the external connected trading service. sc.SendOrdersToTradeService = false; sc.AllowOppositeEntryWithOpposingPositionOrOrders = false; // This can be false in this function because we specify Attached Orders directly with the order which causes this to be considered true when submitting an order. sc.SupportAttachedOrdersForTrading = true; sc.CancelAllOrdersOnEntriesAndReversals= true; sc.AllowEntryWithWorkingOrders = false; sc.CancelAllWorkingOrdersOnExit = true; // Only 1 trade for each Order Action type is allowed per bar. sc.AllowOnlyOneTradePerBar = true; //This needs to be set to true when a trading study uses trading functions. sc.MaintainTradeStatisticsAndTradesData = true; SendOrdersToService.Name = "Send Orders to Trade Service"; SendOrdersToService.SetYesNo(false); return; } if (!Enabled.GetYesNo()) return; // only process at the close of the bar; if it has not closed don't do anything if (sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_NOT_CLOSED) { return; } int StartTime, EndTime, InputDate; SCDateTime StartDateTime, EndDateTime, InputDateTime1, InputDateTime2; InputDate = sc.BaseDateTimeIn[sc.Index].GetDate(); InputDateTime1 = sc.BaseDateTimeIn[sc.Index]; InputDateTime2 = sc.BaseDateTimeIn[sc.Index-1]; StartTime = HMS_TIME(sc.Input[3].GetInt(), sc.Input[4].GetInt(), 0); StartDateTime = COMBINE_DATE_TIME(InputDate, StartTime); EndTime = HMS_TIME(sc.Input[5].GetInt(), sc.Input[6].GetInt(), 0); EndDateTime = COMBINE_DATE_TIME(InputDate, EndTime); { } // using the line1Ref and line2Ref input variables, retrieve the subgraph arrays into line1, line2 arrays respectively SCFloatArray line1; sc.GetStudyArrayUsingID(Line1Ref.GetStudyID(), Line1Ref.GetSubgraphIndex(), line1); SCFloatArray line2; sc.GetStudyArrayUsingID(Line2Ref.GetStudyID(), Line2Ref.GetSubgraphIndex(), line2); sc.SendOrdersToTradeService = SendOrdersToService.GetYesNo(); // code if (InputDateTime1 > StartDateTime && InputDateTime1 < EndDateTime) if (sc.CrossOver(line1, line2) == CROSS_FROM_BOTTOM) { // mark the crossover on the chart BuyEntry[sc.Index] = 1; // Create a market order and enter long. s_SCNewOrder order; order.OrderQuantity = 1; order.OrderType = SCT_ORDERTYPE_MARKET; sc.BuyEntry(order); } if (InputDateTime1 > StartDateTime && InputDateTime1 < EndDateTime) if (sc.CrossOver(line1, line2) == CROSS_FROM_TOP) { // mark the crossover on the chart SellEntry[sc.Index] = 1; // create a market order and enter short s_SCNewOrder order; order.OrderQuantity = 1; order.OrderType = SCT_ORDERTYPE_MARKET; sc.SellEntry(order); } if (InputDateTime2 < EndDateTime && InputDateTime1 >= EndDateTime) && sc.Input[7].GetIndex() == 0) sc.FlattenAndCancelAllOrders(); } Date Time Of Last Edit: 2014-08-21 21:04:19
|