Support Board
Date/Time: Wed, 25 Dec 2024 13:17:02 +0000
Post From: Passing SCGraphData Object as argument
[2015-11-06 22:42:24] |
reticent67 - Posts: 4 |
Sorry for the confusion, I will attempt to clarify. Here is a simple example of what I’m trying to do using a double stochastics crossover. If I use the following code, everything works as expected… SCGraphData DS;
sc.GetStudyArraysFromChartUsingID(DS_in.GetChartNumber(), DS_in.GetStudyID(), DS); int RefIndex = sc.GetExactMatchForSCDateTime(DS_in.GetChartNumber(), sc.BaseDateTimeIn[sc.Index]); SCFloatArray DubStoch = DS[0]; SCFloatArray DS_Sig = DS[5]; SCFloatArray DS_OB = DS[6]; SCFloatArray DS_OS = DS[7]; //Create New order object … if (DubStoch[RefIndex] < DS_OS[RefIndex] && sc.CrossOver(DubStoch, DS_Sig) == CROSS_FROM_BOTTOM) sc.BuyEntry(BuyOrder); if (PositionData.PositionQuantity > 0 && DubStoch[RefIndex] > DS_OB[RefIndex] && sc.CrossOver(DubStoch, DS_Sig) == CROSS_FROM_TOP) sc.BuyExit(BuyOrder); However, if I create a function to generate the trading signals and pass the graph data object (whether by reference or by value), the subgraph values for DubStoch (the main subgraph) and DS_Sig (it’s signal line) always remain at zero and no trades are executed. But the overbought and oversold lines correctly receive their values - 90 and 10, respectively. SCGraphData DS;
sc.GetStudyArraysFromChartUsingID(DS_in.GetChartNumber(), DS_in.GetStudyID(), DS); int RefIndex = sc.GetExactMatchForSCDateTime(DS_in.GetChartNumber(), sc.BaseDateTimeIn[sc.Index]); //Create New order object … if (calcDoubleStoch(DS, sc, RefIndex) > 0)) sc.BuyEntry(BuyOrder); if (PositionData.PositionQuantity > 0 && calcDoubleStoch(DS, sc, RefIndex) < 0)) sc.BuyExit(BuyOrder); } //Declared outside of study function... int calcDoubleStoch(SCGraphData &DS, SCStudyInterfaceRef sc, int Index) { SCFloatArray DubStoch = DS[0]; SCFloatArray DS_Sig = DS[5]; SCFloatArray DS_OB = DS[6]; SCFloatArray DS_OS = DS[7]; if (DubStoch[Index] < DS_OS[Index] && sc.CrossOver(DubStoch, DS_Sig) == CROSS_FROM_BOTTOM) return 1; if (DubStoch[Index] > DS_OB[Index] && sc.CrossOver(DubStoch, DS_Sig) == CROSS_FROM_TOP) return -1; else return 0; } |