How to detect if there is a spike on Boom 1000

 
Hello i need help am trying to detect a spike on boom 1000 , i have noted that  a spike is also there same as a bullish candle on the boom 1000  i have tried to detect this and count each occurance , the code runs without errors but i cant cant seem to detect anything  can anyone help me.
string bull="";
string isspike="";
  
int OnInit(){
//---
   
//---
   return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
//---
   
  }
void OnTick()
  {
  int bullcount=0;
  int spike_count=0;
  Comment("SPIKE DETECTOR: ",isspike," COUNT>> ",spike_count,
          "\nBULL_DETECTOR: ",bull," COUNT>> ",bullcount);
          
double openPrice = iOpen(Symbol(), 0, 0);
   double closePrice = iClose(Symbol(), 0, 0);
   
   if (closePrice > openPrice) {
      
      bull="IS BULL";
      bullcount++;
   } else {
      bull="NOT BULL";
   }
   //
   double threshold=1.02;
   if (closePrice > openPrice * threshold) {
      isspike="IS SPIKE";
      spike_count++
   } else {
      isspike="NOT SPIKE";
   }   
  }
Files:
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
ZhuwaoAbel: Hello i need help am trying to detect a spike on boom 1000 , i have noted that  a spike is also there same as a bullish candle on the boom 1000  i have tried to detect this and count each occurance , the code runs without errors but i cant cant seem to detect anything  can anyone help me.
  • A "Boom" spike is simply an up tick (with a price higher than the previous tick).
  • A "Crash" drop is simply a down tick (with a price lower than the previous tick).

In both cases, they are not related to the M1 bars. During the lifetime of a single 1 minute bar, there can often be multiple spikes on the "Boom", or drops in the "Crash".

So, instead of looking at the bar data, look at the tick data.

 
Fernando Carreiro #:
  • A "Boom" spike is simply an up tick (with a price higher than the previous tick).
  • A "Crash" drop is simply a down tick (with a price lower than the previous tick).

In both cases, they are not related to the M1 bars. During the lifetime of a single 1 minute bar, there can often be multiple spikes on the "Boom", or drops in the "Crash".

So, instead of looking at the bar data, look at the tick data.

Fernando Carreiro #:
  • A "Boom" spike is simply an up tick (with a price higher than the previous tick).
  • A "Crash" drop is simply a down tick (with a price lower than the previous tick).

In both cases, they are not related to the M1 bars. During the lifetime of a single 1 minute bar, there can often be multiple spikes on the "Boom", or drops in the "Crash".

So, instead of looking at the bar data, look at the tick data.

Okay , so how do i access tick data?

 
ZhuwaoAbel #: Okay , so how do i access tick data?

For example, by using ...

CopyTicks

Gets ticks in the MqlTick format into ticks_array

Documentation on MQL5: Timeseries and Indicators Access / CopyTicks
Documentation on MQL5: Timeseries and Indicators Access / CopyTicks
  • www.mql5.com
CopyTicks - Timeseries and Indicators Access - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
// Define your spike threshold
double spikeThreshold = 0.0001;

// Variables to store the number of spikes and ticks
int spikeCount = 0;
int tickCount = 0;
i have used the used the tick data to check for a spike but the code doesnt detect any spike i have attached image to show result
// Variable to store the last tick price
double lastTickPrice = 0.0;

int OnInit(){
//---
   
//---
   return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
//---
   ExpertRemove();
  }
void OnTick()
  {

// OnTick function
    MqlTick currentTick;
    if(SymbolInfoTick(Symbol(), currentTick))
    {
        // Increase the tick count
        tickCount++;

        // Check if this is not the first tick
        if(tickCount > 1)
        {
            // Calculate the price difference
            double priceDifference = MathAbs(currentTick.last - lastTickPrice);

            // Check if there is a price spike
            if(priceDifference > spikeThreshold)
            {
                // Increase the spike count
                spikeCount++;

                // Print information about the spike
                Alert("Spike detected! Number of spikes: ", spikeCount, ", Number of ticks: ", tickCount);
            }
        }

        // Update the last tick price
        lastTickPrice = currentTick.last;
    }

    Comment("Spike detected! Number of spikes: ", spikeCount, ", Number of ticks: ", tickCount);
         
      }

on the image i have drawn a  redline from whence the code started counting i have added two difference images to show my results
  
Files: