Is there a way that i can find numbers that are the nearest to each other in a array

Is there a way that i can find numbers that are the nearest to each other in a array

Manage alerts

Loading saved threads...

Javier Macias · External communityPost link
External question — Stack Overflow Stack Exchange Author: Javier Macias Original post: https://stackoverflow.com/questions/69909228 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. My logic in my code right now is this Step1. Scan for 100 candlesstick or more from the past Step2. Collect and store the date of all 100 to find out the high of each candlestick Step3. Go through all the candlestick high data and find the one that are near each other (Still dont know how i would do that) Step4. Plot HLine Now the first problem im having is how would i code it where i would be able to find which candlestick numbers are close to each other in order to plot the HLine. extern int candleCount = 100; int totalHigh; int FinishingTotalHigh; int totalLow; int FinishingTotalLow; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { totalHigh = 0; totalLow = 0; // Initializing the variables. double Highest = High[0]; double Lowest = Low[0]; Alert(""); Alert(""); Alert(""); Alert(""); Alert(""); // Scan the 100 candles and update the values of the highest and lowest. for (int i = 0; i <= candleCount; i++) { //Alert(i+"Index Data: "+High[i]); totalHigh = High[i] + totalHigh; totalLow = Low[i] + totalLow; if (High[i] > Highest) Highest = High[i]; if (Low[i] < Lowest) Lowest = Low[i]; } FinishingTotalHigh = totalHigh/candleCount; FinishingTotalLow = totalLow/candleCount; // Print the result. Alert("Highest price found is "+Highest); Alert("Lowest price found is "+Lowest); Alert("TotalHigh: "+FinishingTotalHigh); Alert("TotalLow: "+FinishingTotalLow); } //+------------------------------------------------------------------+
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Javier Macias Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/69909228 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. My logic in my code right now is this Step1. Scan for 100 candlesstick or more from the past Step2. Collect and store the date of all 100 to find out the high of each candlestick Step3. Go through all the candlestick high data and find the one that are near each other (Still dont know how i would do that) Step4. Plot HLine Now the first problem im having is how would i code it where i would be able to find which candlestick numbers are close to each other in order to plot the HLine. extern int candleCount = 100; int totalHigh; int FinishingTotalHigh; int totalLow; int FinishingTotalLow; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { totalHigh = 0; totalLow = 0; // Initializing the variables. double Highest = High[0]; double Lowest = Low[0]; Alert(""); Alert(""); Alert(""); Alert(""); Alert(""); // Scan the 100 candles and update the values of the highest and lowest. for (int i = 0; i <= candleCount; i++) { //Alert(i+"Index Data: "+High[i]); totalHigh = High[i] + totalHigh; totalLow = Low[i] + totalLow; if (High[i] > Highest) Highest = High[i]; if (Low[i] < Lowest) Lowest = Low[i]; } FinishingTotalHigh = totalHigh/candleCount; FinishingTotalLow = totalLow/candleCount; // Print the result. Alert("Highest price found is "+Highest); Alert("Lowest price found is "+Lowest); Alert("TotalHigh: "+FinishingTotalHigh); Alert("TotalLow: "+FinishingTotalLow); } //+------------------------------------------------------------------+

Cancel quote

Checking account access…