Support Board
Date/Time: Thu, 28 Nov 2024 06:40:40 +0000
[Programming Help] - Automated Trading Code not working
View Count: 313
[2023-06-02 12:24:30] |
USERunknow007 - Posts: 1 |
Hi Dear, I have run below code and got an error.I am trying to build automated bot using some indicators. It showing that below function not avaliable. Please guide me to resolve this issue #include "sierrachart.h" SCDLLName("Simple Automated System 1") SCSFExport scsf_SimpleAutomatedSystem(SCStudyInterfaceRef sc) { if (sc.SetDefaults) { sc.GraphName = "Simple Automated System"; sc.StudyDescription = "Example of a simple automated trading system"; sc.GraphRegion = 0; sc.AutoLoop = 1; sc.MaintainAdditionalChartDataArrays = 1; sc.Subgraph[0].Name = "movingAverage"; sc.Subgraph[0].DrawStyle = DRAWSTYLE_LINE; sc.Subgraph[0].PrimaryColor = RGB(0,255,0); sc.Subgraph[1].Name = "buySignal"; sc.Subgraph[1].DrawStyle = DRAWSTYLE_ARROW_UP; sc.Subgraph[1].PrimaryColor = RGB(255,0,0); sc.Subgraph[2].Name = "sellSignal"; sc.Subgraph[2].DrawStyle = DRAWSTYLE_ARROW_DOWN; sc.Subgraph[2].PrimaryColor = RGB(0,255,255); sc.Input[0].Name = "Period"; sc.Input[0].SetInt(20); return; } SCFloatArrayRef close = sc.Close; SCFloatArrayRef movingAverage = sc.Subgraph[0].Data; SCFloatArrayRef buySignal = sc.Subgraph[1].Data; SCFloatArrayRef sellSignal = sc.Subgraph[2].Data; int period = sc.Input[0].GetInt(); // Moving average period sc.SimpleMovAvg(close, movingAverage, period); // Generate buy and sell signals based on the moving average crossover buySignal[sc.Index] = close[sc.Index] > movingAverage[sc.Index] && close[sc.Index - 1] <= movingAverage[sc.Index - 1]; sellSignal[sc.Index] = close[sc.Index] < movingAverage[sc.Index] && close[sc.Index - 1] >= movingAverage[sc.Index - 1]; //Create a reference to a persistent integer variable for the order ID so it can be modified or canceled. int& InternalOrderID = sc.GetPersistentInt(1); // Create an s_SCNewOrder object. s_SCNewOrder NewOrder; NewOrder.OrderQuantity = 1; // NewOrder.OrderType = SCT_MARKET; // Buy when the last price crosses the moving average from below. if (sc.CrossOver(Last, SimpMovAvgSubgraph) == CROSS_FROM_BOTTOM && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED) { int Result = sc.BuyEntry(NewOrder); if (Result > 0) //If there has been a successful order entry, then draw an arrow at the low of the bar. { BuyEntrySubgraph[sc.Index] = sc.Low[sc.Index]; // Remember the order ID for subsequent modification and cancellation InternalOrderID = NewOrder.InternalOrderID; } } // // Place trades based on the generated signals // if (buySignal[sc.Index]) // { // sc.BuyMarket(sc.TradeSize, "Buy"); // } // else if (sellSignal[sc.Index]) // { // sc.SellMarket(sc.TradeSize, "Sell"); // } } -- Starting remote build of Custom Studies Source files: SimpleTrading1.cpp. 64-bit -- 12:17:28 Allow time for the server to compile the files and build the DLL. The remote build did not succeed. Result: SimpleTrading1.cpp: In function 'void scsf_SimpleAutomatedSystem(SCStudyInterfaceRef)': SimpleTrading1.cpp:205:22: error: 'Last' was not declared in this scope 205 | if (sc.CrossOver(Last, SimpMovAvgSubgraph) == CROSS_FROM_BOTTOM && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED) | ^~~~ SimpleTrading1.cpp:205:28: error: 'SimpMovAvgSubgraph' was not declared in this scope 205 | if (sc.CrossOver(Last, SimpMovAvgSubgraph) == CROSS_FROM_BOTTOM && sc.GetBarHasClosedStatus() == BHCS_BAR_HAS_CLOSED) | ^~~~~~~~~~~~~~~~~~ SimpleTrading1.cpp:210:13: error: 'BuyEntrySubgraph' was not declared in this scope 210 | BuyEntrySubgraph[sc.Index] = sc.Low[sc.Index]; | ^~~~~~~~~~~~~~~~ -- End of Build -- 12:17:33 |
To post a message in this thread, you need to log in with your Sierra Chart account: