#include "sierrachart.h" SCDLLName("SizeRandomizer") SCSFExport scsf_SizeRandomizer(SCStudyInterfaceRef sc) { // Section 1 - Set the configuration variables and defaults if (sc.SetDefaults) { sc.GraphName = "Size Randomizer"; sc.AutoLoop = 0; // We don't need automatic looping in this study // Define the input for the total lots sc.Input[0].Name = "Total Lots"; sc.Input[0].SetInt(12); // Buttons for Buy and Sell cycles sc.AddButton(1, "Buy Cycle 1: 2+2+4+2"); sc.AddButton(2, "Sell Cycle 1: 2+2+4+2"); return; } // Section 2 - Check for button clicks and handle trading if (sc.IsFullRecalculation) { // Reset trade counts on full recalculation sc.SetCustomStudyArrays(0, 0); sc.SetCustomStudyArrays(1, 0); } // Check for user clicks on the Buy or Sell buttons if (sc.ButtonClick) { // Handle Buy cycle if (sc.ButtonID == 1) { int tradeSize = 0; const int buyCycle[] = {2, 2, 4, 2}; for (int i = 0; i < 4; ++i) { tradeSize += buyCycle[i]; if (tradeSize > sc.Input[0].GetInt()) { sc.AddMessageToLog("Buy Cycle 1: Trade size limit reached. Cannot place a buy order.", 1); return; } sc.BuyEntry(sc.GetChartTradingOrderSymbol, buyCycle[i]); sc.AddMessageToLog("Buying " + sc.GetChartTradingOrderSymbol + " (" + sc.FormatGraphValue(buyCycle[i]) + " contracts)"); } } // Handle Sell cycle else if (sc.ButtonID == 2) { int tradeSize = 0; const int sellCycle[] = {2, 2, 4, 2}; for (int i = 0; i < 4; ++i) { tradeSize += sellCycle[i]; if (tradeSize > sc.Input[0].GetInt()) { sc.AddMessageToLog("Sell Cycle 1: Trade size limit reached. Cannot place a sell order.", 1); return; } sc.SellEntry(sc.GetChartTradingOrderSymbol, sellCycle[i]); sc.AddMessageToLog("Selling " + sc.GetChartTradingOrderSymbol + " (" + sc.FormatGraphValue(sellCycle[i]) + " contracts)"); } } } }