Support Board
Date/Time: Sat, 05 Jul 2025 13:33:35 +0000
Post From: trading system based on 2 signals
[2021-03-10 08:13:41] |
Flipper_2 - Posts: 57 |
Actually thinking about this you probably wouldn't have the signal as an int as they are floats arrays in subgraphs so a full example where say a buy signal is greater than 0 and a sell signal is less than 0 the complete code using that suggested scsf_TradingSystemStudySubgraphCrossover code as a framework SCSFExport scsf_TradingSystemStudySubgraph(SCStudyInterfaceRef sc) { SCInputRef Input_Line1Ref = sc.Input[0]; SCInputRef Input_Line2Ref = sc.Input[1]; SCInputRef Input_Enabled = sc.Input[2]; SCInputRef Input_SendTradeOrdersToTradeService = sc.Input[3]; SCInputRef Input_MaximumPositionAllowed = sc.Input[4]; SCInputRef Input_ActionOnCrossoverWhenInPosition = sc.Input[5]; SCInputRef Input_EvaluateOnBarCloseOnly = sc.Input[6]; SCSubgraphRef Subgraph_BuyEntry = sc.Subgraph[0]; SCSubgraphRef Subgraph_SellEntry = sc.Subgraph[1]; if (sc.SetDefaults) { // Set the configuration and defaults sc.GraphName = "Trading System - Study Subgraph"; sc.AutoLoop = 1; // true sc.GraphRegion = 0; sc.CalculationPrecedence = LOW_PREC_LEVEL; Input_Line1Ref.Name = "Line1"; Input_Line1Ref.SetStudySubgraphValues(1, 0); Input_Line2Ref.Name = "Line2"; Input_Line2Ref.SetStudySubgraphValues(1, 0); Input_Enabled.Name = "Enabled"; Input_Enabled.SetYesNo(false); Input_SendTradeOrdersToTradeService.Name = "Send Trade Orders to Trade Service"; Input_SendTradeOrdersToTradeService.SetYesNo(false); Input_MaximumPositionAllowed.Name = "Maximum Position Allowed"; Input_MaximumPositionAllowed.SetInt(1); Input_ActionOnCrossoverWhenInPosition.Name = "Action on Crossover When in Position"; Input_ActionOnCrossoverWhenInPosition.SetCustomInputStrings("No Action;Exit on Crossover;Reverse on Crossover"); Input_ActionOnCrossoverWhenInPosition.SetCustomInputIndex(0); Input_EvaluateOnBarCloseOnly.Name = "Evaluate on Bar Close Only"; Input_EvaluateOnBarCloseOnly.SetYesNo(true); Subgraph_BuyEntry.Name = "Buy"; Subgraph_BuyEntry.DrawStyle = DRAWSTYLE_POINT_ON_HIGH; Subgraph_BuyEntry.LineWidth = 4; Subgraph_SellEntry.Name = "Sell"; Subgraph_SellEntry.DrawStyle = DRAWSTYLE_POINT_ON_LOW; Subgraph_SellEntry.LineWidth = 4; sc.AllowMultipleEntriesInSameDirection = false; sc.SupportReversals = false; sc.AllowOppositeEntryWithOpposingPositionOrOrders = false; sc.SupportAttachedOrdersForTrading = false; sc.UseGUIAttachedOrderSetting = 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 should be set to true when a trading study uses trading functions. sc.MaintainTradeStatisticsAndTradesData = true; return; } sc.MaximumPositionAllowed = Input_MaximumPositionAllowed.GetInt(); sc.SendOrdersToTradeService = Input_SendTradeOrdersToTradeService.GetYesNo(); if (!Input_Enabled.GetYesNo()) return; // only process at the close of the bar. If it has not closed do not do anything if (Input_EvaluateOnBarCloseOnly.GetYesNo() && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_NOT_CLOSED) { return; } // using the Input_Line1Ref and Input_Line2Ref input variables, retrieve the subgraph arrays SCFloatArray StudyLine1; sc.GetStudyArrayUsingID(Input_Line1Ref.GetStudyID(), Input_Line1Ref.GetSubgraphIndex(), StudyLine1); SCFloatArray StudyLine2; sc.GetStudyArrayUsingID(Input_Line2Ref.GetStudyID(), Input_Line2Ref.GetSubgraphIndex(), StudyLine2); sc.SupportReversals = false; if (StudyLine1[sc.Index] > 0 && StudyLine2[sc.Index] > 0) { // mark the crossover on the chart Subgraph_BuyEntry[sc.Index] = 1; if (!sc.IsFullRecalculation && !sc.DownloadingHistoricalData) { s_SCNewOrder NewOrder; NewOrder.OrderQuantity = 0; NewOrder.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED; int Result = (int)sc.BuyEntry(NewOrder);//Buy order if (Result < 0) sc.AddMessageToLog(sc.GetTradingErrorTextMessage(Result), false); } } if (StudyLine1[sc.Index] < 0 && StudyLine2[sc.Index] < 0) { // mark the crossover on the chart Subgraph_SellEntry[sc.Index] = 1; if (!sc.IsFullRecalculation && !sc.DownloadingHistoricalData) { s_SCNewOrder NewOrder; NewOrder.OrderQuantity = 0; NewOrder.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED; int Result = (int)sc.SellEntry(NewOrder);//Sell order if (Result < 0) sc.AddMessageToLog(sc.GetTradingErrorTextMessage(Result), false); } } } Date Time Of Last Edit: 2021-03-10 08:14:19
|