- Data types and values
- Introduction to MQL5 and development environment
- Questions about the MQL5 Cloud Network
You will get little help if you don’t post the code because that makes it a guessing game.
Oh right, here is the code
//+------------------------------------------------------------------+ //| SNR V3.mq4| //| Copyright 2024, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property strict #property indicator_chart_window input double SetPrice = 1236.69; input double Percentage = 0.75; input int NumberOfLines = 168; input color LineColor = clrYellow; input ENUM_LINE_STYLE LineStyle = STYLE_DOT; input int LineWidth = 1; // Array to hold the horizontal line handles int lineHandles[]; // Array to hold the count of candle touches for each line int lineTouchCounts[]; int currentTimeFrame = 0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { ArrayResize(lineHandles, NumberOfLines * 2); // Twice the number of lines to account for above and below ArrayResize(lineTouchCounts, NumberOfLines * 2); currentTimeFrame = Period(); DrawLines(); EventSetTimer(60); // Set timer to update touch counts every 60 seconds return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { EventKillTimer(); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { if (currentTimeFrame != Period()) { currentTimeFrame = Period(); DrawLines(); } UpdateTouchCounts(high, low, rates_total); return(rates_total); } //+------------------------------------------------------------------+ //| Function to draw the support and resistance lines | //+------------------------------------------------------------------+ void DrawLines() { DeleteLines(); // Determine default values based on the symbol double defaultPrice; double defaultPercentage; if (Symbol() == "XAUUSD") { defaultPrice = 1236.69; defaultPercentage = 0.75; } else if (Symbol() == "GBPJPY") { defaultPrice = 184.005; defaultPercentage = 0.52; } else if (Symbol() == "EURJPY") { defaultPrice = 132.075; defaultPercentage = 0.48; } else if (Symbol() == "USDJPY") { defaultPrice = 113.765; defaultPercentage = 0.43; } else if (Symbol() == "GBPUSD") { defaultPrice = 1.57730; defaultPercentage = 0.43; } else if (Symbol() == "EURUSD") { defaultPrice = 1.27870; defaultPercentage = 0.42; } else if (Symbol() == "CHFJPY") { defaultPrice = 122.755; defaultPercentage = 0.45; } else if (Symbol() == "EURNZD") { defaultPrice = 1.98450; defaultPercentage = 0.48; } else if (Symbol() == "AUDJPY") { defaultPrice = 81.520; defaultPercentage = 0.52; } else if (Symbol() == "NZDJPY") { defaultPrice = 71.055; defaultPercentage = 0.59; } else if (Symbol() == "CADJPY") { defaultPrice = 96.990; defaultPercentage = 0.56; } else if (Symbol() == "AUDUSD") { defaultPrice = 0.82950; defaultPercentage = 0.53; } else if (Symbol() == "USDCHF") { defaultPrice = 1.06515; defaultPercentage = 0.43; } else if (Symbol() == "USDCAD") { defaultPrice = 1.24170; defaultPercentage = 0.40; } else if (Symbol() == "NZDUSD") { defaultPrice = 0.68710; defaultPercentage = 0.57; } else if (Symbol() == "NASDAQ") { defaultPrice = 8955.65; defaultPercentage = 0.89; } else { defaultPrice = SetPrice; defaultPercentage = Percentage; } double price = defaultPrice; double percentage = defaultPercentage / 100.0; double upperPrice = price; double lowerPrice = price; for (int i = 0; i < NumberOfLines; i++) { upperPrice = upperPrice * (1.0 + percentage); lowerPrice = lowerPrice * (1.0 - percentage); string upperLineName = "SRLineUpper_" + IntegerToString(i); string lowerLineName = "SRLineLower_" + IntegerToString(i); lineHandles[i] = ObjectCreate(0, upperLineName, OBJ_HLINE, 0, 0, upperPrice); ObjectSetInteger(0, upperLineName, OBJPROP_COLOR, LineColor); ObjectSetInteger(0, upperLineName, OBJPROP_STYLE, LineStyle); ObjectSetInteger(0, upperLineName, OBJPROP_WIDTH, LineWidth); lineHandles[i + NumberOfLines] = ObjectCreate(0, lowerLineName, OBJ_HLINE, 0, 0, lowerPrice); ObjectSetInteger(0, lowerLineName, OBJPROP_COLOR, LineColor); ObjectSetInteger(0, lowerLineName, OBJPROP_STYLE, LineStyle); ObjectSetInteger(0, lowerLineName, OBJPROP_WIDTH, LineWidth); } } //+------------------------------------------------------------------+ //| Function to delete all lines | //+------------------------------------------------------------------+ void DeleteLines() { for (int i = 0; i < ArraySize(lineHandles); i++) { if (lineHandles[i] != 0) { ObjectDelete(0, "SRLineUpper_" + IntegerToString(i)); ObjectDelete(0, "SRLineLower_" + IntegerToString(i - NumberOfLines)); lineHandles[i] = 0; } } } //+------------------------------------------------------------------+ //| Function to update the touch counts for each line | //+------------------------------------------------------------------+ void UpdateTouchCounts(const double &high[], const double &low[], const int rates_total) { ArrayFill(lineTouchCounts, 0, ArraySize(lineTouchCounts), 0); for (int i = 0; i < NumberOfLines; i++) { double upperPrice = ObjectGetDouble(0, "SRLineUpper_" + IntegerToString(i), OBJPROP_PRICE1); double lowerPrice = ObjectGetDouble(0, "SRLineLower_" + IntegerToString(i), OBJPROP_PRICE1); for (int j = 0; j < rates_total; j++) { if (high[j] >= upperPrice && low[j] <= upperPrice) { lineTouchCounts[i]++; } if (high[j] >= lowerPrice && low[j] <= lowerPrice) { lineTouchCounts[i + NumberOfLines]++; } } string upperLineName = "SRLineUpper_" + IntegerToString(i); string lowerLineName = "SRLineLower_" + IntegerToString(i); ObjectSetString(0, upperLineName, OBJPROP_TEXT, "Touched " + IntegerToString(lineTouchCounts[i]) + " times"); ObjectSetString(0, lowerLineName, OBJPROP_TEXT, "Touched " + IntegerToString(lineTouchCounts[i + NumberOfLines]) + " times"); } } //+------------------------------------------------------------------+

- www.metaquotes.net
You will get little help if you don’t post the code because that makes it a guessing game.
i think its need to calculate all the candle sir, thats why i put so much history, what do you think? i already post the code, is that any flaw?
i think its need to calculate all the candle sir, thats why i put so much history, what do you think? i already post the code, is that any flaw?
You are calculating every candle of chart every single tick. So you have quite a lot of code to change
simply put, to much data can cause freze in application?
can you tell me how much at least i should use? 20 years history, should be fine right?
simply put, to much data can cause freze in application?
can you tell me how much at least i should use? 20 years history, should be fine right?
its not about that, you are recalculating EVERYTHING every tick.... you should calculate everything once, then only calculate the delta since last calculation. and for what you are doing probably only need to calculate at start of a new bar as well. Do this and your processing would come down 99%
you should calculate everything once, then only calculate the delta since last calculation. and for what you are doing probably only need to calculate at start of a new bar as well. Do this and your processing would come down 99%
so thats the key, thank mr paul, ill try...

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use