Support Board
Date/Time: Tue, 22 Apr 2025 22:53:58 +0000
[Programming Help] - [PROGRAMMING HELP] EMA Crossover Trading bot
View Count: 270
[2024-12-15 00:13:02] |
User137622 - Posts: 8 |
Dear all, I'm currently trying to build my first trading bots in Sierra Chart. The strategy is the following: IF EMA7 crosses above EMA14 AND the first candle is green, then buy NQ. If EMA14 crosses above EMA7 and first candle after the crossover is red, then sell NQ. I also added SL with -400 USD TP with +800 USD This strategy is not final, I just wanted to test how ASCIL works. I can build the DLL and receive the following message: Server: https://build.sierrachart.com The remote build is complete. The build succeeded. The compiler response is empty. When I try to add my custom study via Analysis >> Studies >> Add custom Study I receive errors in the log: 2024-12-15 01:10:57.077 | Found DLL: UserContributedStudies_64.dll 2024-12-15 01:10:57.085 | No custom study function names found in C:\SierraChart\Data\EMA7-14-crossover-test_64.dll 2024-12-15 01:10:57.085 | InternalVersionNumberToFileNameMap is empty for EMA7-14-crossover-test 2024-12-15 01:10:57.085 | Closest match search for: C:\SierraChart\Data\EMA7-14-crossover-test.dll returned empty result. * Can you please help me? Thanks! This is my code: #include "sierrachart.h" SCDLLName("EMA Crossover Bot") void scsf_EMA_Crossover_Bot(SCStudyInterfaceRef sc) { // Initialisierung if (sc.SetDefaults) { sc.GraphName = "EMA Crossover Bot"; sc.StudyDescription = "EMA7/14 crossover + candle confirmation."; sc.AutoLoop = 1; sc.FreeDLL = 1; sc.GraphRegion = 0; sc.Input[0].Name = "Stop Loss (USD)"; sc.Input[0].SetFloat(-400.0); sc.Input[1].Name = "Take Profit (USD)"; sc.Input[1].SetFloat(800.0); sc.Input[2].Name = "Trade Start Time (HHMM)"; sc.Input[2].SetInt(600); sc.Input[3].Name = "Trade End Time (HHMM)"; sc.Input[3].SetInt(2100); sc.Input[4].Name = "EMA 7 Length"; sc.Input[4].SetInt(7); sc.Input[5].Name = "EMA 14 Length"; sc.Input[5].SetInt(14); return; } // Inputs laden float stopLoss = sc.Input[0].GetFloat(); float takeProfit = sc.Input[1].GetFloat(); int tradeStartTime = sc.Input[2].GetInt(); int tradeEndTime = sc.Input[3].GetInt(); int ema7Length = sc.Input[4].GetInt(); int ema14Length = sc.Input[5].GetInt(); // Zeitfilter überprüfen int currentTime = sc.BaseDateTimeIn[sc.Index].GetTimeInSeconds() / 60; if (currentTime < tradeStartTime || currentTime > tradeEndTime) { return; } // EMA-Calculations SCFloatArray EMA7; SCFloatArray EMA14; sc.ExponentialMovAvg(sc.Close, EMA7, ema7Length); sc.ExponentialMovAvg(sc.Close, EMA14, ema14Length); // Crossover-Logic bool isLongSignal = (EMA7[sc.Index - 1] <= EMA14[sc.Index - 1]) && (EMA7[sc.Index] > EMA14[sc.Index]); bool isShortSignal = (EMA7[sc.Index - 1] >= EMA14[sc.Index - 1]) && (EMA7[sc.Index] < EMA14[sc.Index]); // Candle confirmation bool isLongConfirmed = isLongSignal && (sc.Close[sc.Index] > sc.Open[sc.Index]); bool isShortConfirmed = isShortSignal && (sc.Close[sc.Index] < sc.Open[sc.Index]); // Close position if new crossover occurs if (isLongSignal || isShortSignal) { sc.FlattenPosition(); } // Position eröffnen if (isLongConfirmed) { s_SCNewOrder order; order.OrderType = SCT_ORDERTYPE_MARKET; order.Target1Offset = takeProfit; order.Stop1Offset = stopLoss; order.AttachedOrderStop1Type = SCT_ORDERTYPE_STOP; order.AttachedOrderTarget1Type = SCT_ORDERTYPE_LIMIT; sc.BuyEntry(order); } if (isShortConfirmed) { s_SCNewOrder order; order.OrderType = SCT_ORDERTYPE_MARKET; order.Target1Offset = takeProfit; order.Stop1Offset = stopLoss; order.AttachedOrderStop1Type = SCT_ORDERTYPE_STOP; order.AttachedOrderTarget1Type = SCT_ORDERTYPE_LIMIT; sc.SellEntry(order); } } |
[2024-12-17 16:53:55] |
ForgivingComputers.com - Posts: 1042 |
replace void with SCSFExport SCSFExport scsf_EMA_Crossover_Bot(SCStudyInterfaceRef sc) {
|
[2024-12-18 21:13:59] |
User137622 - Posts: 8 |
Thanks a lot :)
|
To post a message in this thread, you need to log in with your Sierra Chart account: