Support Board
Date/Time: Sat, 05 Jul 2025 13:50:23 +0000
Post From: trading system based on 2 signals
[2021-03-11 07:15:07] |
User61576 - Posts: 450 |
Here is the code, though the if condition is simple and it's based on the original scsf_TradingSystemStudySubgraphCrossover I understand I need to add to that signal on the chart a value, how should it be done? thanks! #include <string> #include "sierrachart.h" #include <math.h> #include <iostream> #include <fstream> using namespace std; SCDLLName("test") SCSFExport scsf_TradingSystemStudySubgraphCrossover(SCStudyInterfaceRef sc) { SCInputRef Input_Line1Ref = sc.Input[0]; SCInputRef Input_Line2Ref = sc.Input[1]; SCInputRef Input_Line3Ref = sc.Input[2]; SCInputRef Input_Enabled = sc.Input[3]; SCInputRef Input_SendTradeOrdersToTradeService = sc.Input[4]; SCInputRef Input_MaximumPositionAllowed = sc.Input[5]; SCInputRef Input_EvaluateOnBarCloseOnly = sc.Input[7]; SCInputRef Min_Ratchet = sc.Input[8]; SCInputRef Max_Ratchet = sc.Input[9]; SCInputRef ddOffsetInput = sc.Input[10]; SCSubgraphRef Subgraph_BuyEntry = sc.Subgraph[0]; SCSubgraphRef Subgraph_SellEntry = sc.Subgraph[1]; if (sc.SetDefaults) { // Set the configuration and defaults sc.GraphName = "test"; sc.StudyDescription = "A trading system that enters a new position \ based"; sc.AutoLoop = 1; // true sc.GraphRegion = 1; sc.CalculationPrecedence = LOW_PREC_LEVEL; Input_Line1Ref.Name = "Max"; Input_Line1Ref.SetStudySubgraphValues(1, 0); Input_Line2Ref.Name = "Min"; Input_Line2Ref.SetStudySubgraphValues(1, 0); Input_Line3Ref.Name = "Final"; Input_Line3Ref.SetStudySubgraphValues(1, 0); Input_Enabled.Name = "Enabled"; Input_Enabled.SetYesNo(true); Input_SendTradeOrdersToTradeService.Name = "Send Trade Orders to Trade Service"; Input_SendTradeOrdersToTradeService.SetYesNo(false); Input_MaximumPositionAllowed.Name = "Maximum Position Allowed"; Input_MaximumPositionAllowed.SetInt(0); Input_EvaluateOnBarCloseOnly.Name = "Evaluate on Bar Close Only"; Input_EvaluateOnBarCloseOnly.SetYesNo(true); Subgraph_BuyEntry.Name = "Buy"; Subgraph_BuyEntry.DrawStyle = DRAWSTYLE_CIRCLE_HOLLOW; Subgraph_BuyEntry.PrimaryColor = RGB(0, 255, 0); Subgraph_BuyEntry.LineWidth = 7; Subgraph_BuyEntry.DrawZeros = false; Subgraph_SellEntry.Name = "Sell"; Subgraph_SellEntry.DrawStyle = DRAWSTYLE_CIRCLE_HOLLOW; Subgraph_SellEntry.PrimaryColor = RGB(255, 0, 0); Subgraph_SellEntry.LineWidth = 7; Subgraph_SellEntry.DrawZeros = false; Min_Ratchet.Name = "Minimal Counter Pick"; Min_Ratchet.SetInt(-100); Min_Ratchet.SetIntLimits(-10000, -1); Max_Ratchet.Name = "Maximal Counter Pick"; Max_Ratchet.SetInt(100); Max_Ratchet.SetIntLimits(1, 1000); ddOffsetInput.Name = "Display Signal Offset"; ddOffsetInput.SetFloat(.02); ddOffsetInput.SetFloatLimits(.00001f, 1000); 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; sc.FreeDLL = 1; //need to change to 0 in production 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; //Max sc.GetStudyArrayUsingID(Input_Line1Ref.GetStudyID(), Input_Line1Ref.GetSubgraphIndex(), StudyLine1); SCFloatArray StudyLine2; //Min sc.GetStudyArrayUsingID(Input_Line2Ref.GetStudyID(), Input_Line2Ref.GetSubgraphIndex(), StudyLine2); SCFloatArray StudyLine3;//Close sc.GetStudyArrayUsingID(Input_Line3Ref.GetStudyID(), Input_Line3Ref.GetSubgraphIndex(), StudyLine3); //simplifing the caclculations float Max = StudyLine1[sc.Index]; float Min = StudyLine2[sc.Index]; float Close = StudyLine3[sc.Index]; s_SCPositionData PositionData; if (!sc.IsFullRecalculation) sc.GetTradePosition(PositionData); // code below is where we check for crossovers and take action accordingly sc.SupportReversals = false; //long entry condition if ( (StudyLine2[sc.Index] < (Min_Ratchet.GetInt())) ) { // mark the crossover on the chart Subgraph_BuyEntry[sc.Index] = sc.Low[sc.Index] - ddOffsetInput.GetFloat();//from DD if (!sc.IsFullRecalculation && !sc.DownloadingHistoricalData)// i am not d.l. historical data and i am not in full recalc { if (Input_SendTradeOrdersToTradeService.GetYesNo() == true) { s_SCNewOrder NewOrder; NewOrder.OrderQuantity = 1; NewOrder.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED; int Result = (int)sc.SellExit(NewOrder);//Buy order if (Result < 0) sc.AddMessageToLog(sc.GetTradingErrorTextMessage(Result), false); } } } //short entry condition if ( (StudyLine1[sc.Index] >= (Max_Ratchet.GetInt())) ) { // mark the crossover on the chart Subgraph_SellEntry[sc.Index] = sc.High[sc.Index] + ddOffsetInput.GetFloat();//from DD if (!sc.IsFullRecalculation && !sc.DownloadingHistoricalData)// i am not d.l. historical data and i am not in full recalc { if (Input_SendTradeOrdersToTradeService.GetYesNo() == true) { s_SCNewOrder NewOrder; NewOrder.OrderQuantity = 1; NewOrder.OrderType = SCT_ORDERTYPE_MARKET; NewOrder.TimeInForce = SCT_TIF_GOOD_TILL_CANCELED; int Result = (int)sc.SellExit(NewOrder);//Buy order if (Result < 0) sc.AddMessageToLog(sc.GetTradingErrorTextMessage(Result), false); } } } } |