Support Board
Date/Time: Sat, 08 Feb 2025 03:16:10 +0000
Post From: What Parameter is Missing
[2020-06-22 19:16:54] |
User769783 - Posts: 188 |
I trimmed it down to make it easier to read.. ..... ..... // The top of every source code file must include this line #include "sierrachart.h" // This line is required. Change the text within the quote // marks to what you want to name your group of custom studies. SCDLLName("Depth Bars DLL") /*==========================================================================*/ SCSFExport scsf_TradingExampleWithAttachedOrders(SCStudyInterfaceRef sc) { /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Define Subgraphs */ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ SCSubgraphRef Subgraph_BuyEntry = sc.Subgraph[0]; SCSubgraphRef Subgraph_SellEntry = sc.Subgraph[1]; SCInputRef Input_Enabled = sc.Input[0]; /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Define Defaults */ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ if (sc.SetDefaults) { // Set the study configuration and defaults. sc.GraphName = "Trading Example: Moving Average Crossover with Attached Orders"; sc.UsesMarketDepthData = 1; Subgraph_BuyEntry.Name = "Buy Entry"; Subgraph_BuyEntry.DrawStyle = DRAWSTYLE_ARROW_UP; Subgraph_BuyEntry.PrimaryColor = RGB(0, 255, 0); Subgraph_BuyEntry.LineWidth = 2; Subgraph_BuyEntry.DrawZeros = false; Subgraph_SellEntry.Name = "Sell Entry"; Subgraph_SellEntry.DrawStyle = DRAWSTYLE_ARROW_DOWN; Subgraph_SellEntry.PrimaryColor = RGB(255, 0, 0); Subgraph_SellEntry.LineWidth = 2; Subgraph_SellEntry.DrawZeros = false; Input_Enabled.Name = "Enabled"; Input_Enabled.SetYesNo(0); /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Trade Parameters */ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ sc.AllowMultipleEntriesInSameDirection = false; sc.MaximumPositionAllowed = 100000; sc.SupportReversals = true; // This is false by default. Orders will go to the simulation system always. 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 = false; sc.CancelAllOrdersOnEntriesAndReversals= true; sc.AllowEntryWithWorkingOrders = true; sc.CancelAllWorkingOrdersOnExit = true; // Only 1 trade for each Order Action type is allowed per bar. sc.AllowOnlyOneTradePerBar = false; //This needs to be set to true when a trading study uses trading functions. sc.MaintainTradeStatisticsAndTradesData = true; sc.AutoLoop = 1; sc.GraphRegion = 0; return; } if (!Input_Enabled.GetYesNo()) return; /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Begin Data Processing */ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Use persistent variables.....attached order IDs.......can be modified or canceled */ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ // . int& Target1OrderID = sc.GetPersistentInt(1); int& Stop1OrderID = sc.GetPersistentInt(2); /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Make Sure No Open Trades */ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ s_SCPositionData PositionData; sc.GetTradePosition(PositionData); if(PositionData.PositionQuantity != 0) return; /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Create an s_SCNewOrder object */ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ s_SCNewOrder NewOrder; NewOrder.OrderQuantity = 1; NewOrder.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED; /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Target- StopLoss - Trailing */ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ NewOrder.Target1Offset = 8*sc.TickSize; NewOrder.Stop1Offset = 8*sc.TickSize; NewOrder.OCOGroup1Quantity = 1; // If this is left at the default of 0, then it will be automatically set. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Buy Order Function */ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ if (SC_CLOSE > SC_OPEN)//What is SC_CLOSE and SC_OPEN? { int Result = (int)sc.BuyEntry(NewOrder); if (Result > 0) //If there has been a successful order entry, then draw an arrow at the low of the bar. { Subgraph_BuyEntry[sc.Index] = sc.Low[sc.Index]; // Remember the order IDs for subsequent modification and cancellation Target1OrderID = NewOrder.Target1InternalOrderID; Stop1OrderID = NewOrder.Stop1InternalOrderID; } } /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ /* Sell Order Function */ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ else if (SC_CLOSE < SC_OPEN) { int Result = (int)sc.SellEntry(NewOrder); if (Result > 0) //If there has been a successful order entry, then draw an arrow at the high of the bar. { Subgraph_SellEntry[sc.Index] = sc.High[sc.Index]; // Remember the order IDs for subsequent modification and cancellation Target1OrderID = NewOrder.Target1InternalOrderID; Stop1OrderID = NewOrder.Stop1InternalOrderID; } } } |