Support Board
Date/Time: Sat, 08 Feb 2025 02:56:48 +0000
Post From: What Parameter is Missing
[2020-06-22 19:14:00] |
User769783 - Posts: 188 |
Ahh, works now. Thanks. Could you look at this code and explain why it is not selling. It buys only. Am I using SC_OPEN and SC_CLOSE correctly? Thanks ... // 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]; SCSubgraphRef Subgraph_BidSize = sc.Subgraph[6]; SCSubgraphRef Subgraph_BidValue = sc.Subgraph[7]; SCSubgraphRef Subgraph_AskSize = sc.Subgraph[8]; SCSubgraphRef Subgraph_AskValue = sc.Subgraph[9]; SCSubgraphRef Subgraph_BidStackPullValue = sc.Subgraph[10]; SCSubgraphRef Subgraph_AskStackPullValue = sc.Subgraph[11]; 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; Subgraph_BidSize.Name = "Bid Size"; Subgraph_BidSize.DrawStyle = DRAWSTYLE_DASH; Subgraph_BidSize.PrimaryColor = RGB(0,255,0); Subgraph_BidSize.DrawZeros = false; Subgraph_BidValue.Name = "Bid Value"; Subgraph_BidValue.DrawStyle = DRAWSTYLE_DASH; Subgraph_BidValue.PrimaryColor = RGB(255,0,255); Subgraph_BidValue.DrawZeros = false; Subgraph_AskSize.Name = "Ask Size"; Subgraph_AskSize.DrawStyle = DRAWSTYLE_DASH; Subgraph_AskSize.PrimaryColor = RGB(255,255,0); Subgraph_AskSize.DrawZeros = false; Subgraph_AskValue.Name = "Ask Value"; Subgraph_AskValue.DrawStyle = DRAWSTYLE_DASH; Subgraph_AskValue.PrimaryColor = RGB(255,127,0); Subgraph_AskValue.DrawZeros = false; Subgraph_AskStackPullValue.Name = "Ask Stack/Pull Value"; Subgraph_AskStackPullValue.DrawStyle = DRAWSTYLE_IGNORE; Subgraph_AskStackPullValue.PrimaryColor = RGB(128, 128, 128); Subgraph_AskStackPullValue.DrawZeros = false; Subgraph_BidStackPullValue.Name = "Bid Stack/Pull Value"; Subgraph_BidStackPullValue.DrawStyle = DRAWSTYLE_IGNORE; Subgraph_BidStackPullValue.PrimaryColor = RGB(128, 128, 128); Subgraph_BidStackPullValue.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; } } } |