Anybody ?
Of course, a perfect V would be formed with an odd number of bars so that there is an equal number of higher closes to the right and left of the low close.
//+------------------------------------------------------------------+ //| V_Pattern.mq5 | //| Keith Watford | //+------------------------------------------------------------------+ #property copyright "Keith Watford" #property link "" #property version "1.00" //--- input parameters input int NumberOfBarsForVpattern=11; //Number Of Bars For V Pattern input int CheckStartBar=1; //Check Start Bar (Just for testing, normally will be 1) //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- CheckForVpattern(CheckStartBar); //In OnInit just for testing while the market is closed and no incoming ticks //Normally in OnTick() after a check for a new bar. //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- } //+------------------------------------------------------------------+ bool CheckForVpattern(int startBar=1) { double closeArray[]; ArraySetAsSeries(closeArray,true); int copied=CopyClose(_Symbol,PERIOD_CURRENT,startBar,NumberOfBarsForVpattern,closeArray); if(copied!=NumberOfBarsForVpattern) { Print("Error copying close values. Error code ",GetLastError()); return(false); } int centerBar=(NumberOfBarsForVpattern-1)/2; //For the V pattern to be valid, the lowest close MUST be the center bar. int min=ArrayMinimum(closeArray); if(min!=centerBar) return(false); //Check for higher closes to the right for(int x=centerBar-2; x>=0; x--) { if(closeArray[x]<=closeArray[x+1]) //close is not higher than previous return(false); } //Check for higher closes to the left for(int x=centerBar+2; x<copied; x++) { if(closeArray[x]<=closeArray[x-1]) //close is not higher than later bar return(false); } Print("Is V Pattern"); return true; } //+------------------------------------------------------------------+
Keith Watford:
Of course, a perfect V would be formed with an odd number of bars so that there is an equal number of higher closes to the right and left of the low close.
Thanks, i was able to understand the code and implement it into my EA

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
This would form a " V " shape and hopefully it made sense, in my strategy the number of candles could be 10 or even 50, I use array minimum to find the lowest candle close. I'd tried to loop it but the loop will check only if any one of the condition is true and execute the block of code inside the loop, I want the loop to check whether all the conditions are true and if yes only then execute the block of code.