Discussion of article "How to detect trends and chart patterns using MQL5" - page 2

 

Please post in English only on this forum.

You can use automatic translation tool if needed.

Thanks.
 
J M #:

A big thank you for this article, because it is really a non beginning already for me. Especially since I can't stop all day long to browse the articles posted here on this magnificent site in search of those who could precisely use this possibility to make automatic detection of this kind of figures, which, according to the own man little experience in this business, are of significant importance in technical analysis.

Only, compared to your code, with regard to the detection of configurations in M (double top) and those in W ( double bottom ), is there no possibility of proposing a code which is able to rather draw 4 different and definitive lines (drawing more or less clearly on the graph an M)? Rather than lines that redraw as prices change, which is not a good thing at all when it comes to spotting patterns.  

As for the double top, for example:

1.   A first line, which will draw the first bullish leg. And the line remains final without moving any further with the next course changes...

2. A second, which will trace the first bearish correction, will at the same time indicate a potential formation of a first top of a potential M pattern.

3. A third, which traces the bullish recovery (a second bullish impulse), and alerts the trader to the imminence of a return…

4. And, finally, a behind line that will be drawn once the figure is really formed...

Well, I think you have understood my concern.

Is it a code capable of doing these different tracings is it not possible? THANKS

Thanks for your comment.

I know that detecting patterns may be difficult based on the pattern form as there are many accepted variances and you may find that you need to develop your code as per objectives and what you mentioned.

What I think is that anything you can describe in a logical way, you can code it.

Thanks

 
Mohamed Abdelmaaboud #:

Thanks for your comment.

I know that detecting patterns may be difficult based on the pattern form as there are many accepted variances and you may find that you need to develop your code as per objectives and what you mentioned.

What I think is that anything you can describe in a logical way, you can code it.

Thanks

Ok.  Thanks

Translated to English by moderator.

This is the English forum. Please only write in English.

 
I am delighted to have read your article, Mohamed.
I have taken the liberty (I hope you don't take offence) of unifying the codes to see the results grouped together: It's what I can think of to continue taking steps towards the creation of a possible EA.
Who is encouraged to implement orders to the different graphic states?

Best regards.

//+------------------------------------------------------------------+
//|                                        TrendDTDB.mq5             |
//+------------------------------------------------------------------+

input int checkBars= 20;
   int high1, high2, low1, low2;
   double highVal1, highVal2, lowVal1, lowVal2;

void OnInit()
{
   PonEtiquetas();
}


void OnTick()
{
   high1=getmove(MODE_HIGH,checkBars,0);
   high2=getmove(MODE_HIGH,checkBars,high1+1);
   highVal1=NormalizeDouble(iHigh(_Symbol,_Period,high1),5);
   highVal2=NormalizeDouble(iHigh(_Symbol,_Period,high2),5);
   
   low1=getmove(MODE_LOW,checkBars,0);
   low2=getmove(MODE_LOW,checkBars,low1+1);
   lowVal1=NormalizeDouble(iLow(_Symbol,_Period,low1),5);
   lowVal2=NormalizeDouble(iLow(_Symbol,_Period,low2),5);

// DOBLE TECHO
   if(highVal1<=highVal2&&lowVal1>lowVal2){ObjectSetString((int)_Symbol,"LS0",OBJPROP_TEXT,0,"Potencial DT-DOBLE TECHO"); DibujaArriba("DTP",clrGreen);}
   else if(highVal1<=highVal2&&lowVal1<lowVal2){ObjectSetString((int)_Symbol,"LS0",OBJPROP_TEXT,0,"DT-DOBLE TECHO");DibujaArriba("DT",clrGreen);}
        else{ObjectSetString((int)_Symbol,"LS0",OBJPROP_TEXT,0,"."); ObjectsDeleteAll(0,"DT",0,-1);}

//DOBLE SUELO
   if(lowVal1>=lowVal2&&highVal1<highVal2){ObjectSetString((int)_Symbol,"LS1",OBJPROP_TEXT,0,"Potencial DS-DOBLE SUELO"); DibujaAbajo("DSP",clrRed);}
   else if(lowVal1>=lowVal2&&highVal1>highVal2){ObjectSetString((int)_Symbol,"LS1",OBJPROP_TEXT,0,"DT-DOBLE TECHO");DibujaArriba("DS",clrGreen);}
        else{ObjectSetString((int)_Symbol,"LS1",OBJPROP_TEXT,0,"."); ObjectsDeleteAll(0,"DS",0,-1);}

// TREND FINDER
   if(lowVal1>lowVal2&&highVal1>highVal2){ObjectSetString((int)_Symbol,"LS2",OBJPROP_TEXT,0,"UP-Tendencia ALCISTA");DibujaArriba("T",clrGreen);}
   else if(highVal1<highVal2&&lowVal1<lowVal2){ObjectSetString((int)_Symbol,"LS2",OBJPROP_TEXT,0,"DOWN-Tendencia BAJISTA");DibujaAbajo("T",clrRed);}
        else{ObjectSetString((int)_Symbol,"LS2",OBJPROP_TEXT,0,"SW-Tendencia LATERAL");  ObjectsDeleteAll(0,"T",0,-1);}
      
}


int getmove(int move, int count, int startPos)
{
   if(move!=MODE_HIGH && move!=MODE_LOW)
      return (-1);
   int currentBar=startPos;
   int moveReturned=getNextMove(move,count*2+1,currentBar-count);
   while(moveReturned!=currentBar)
     {
      currentBar=getNextMove(move,count,currentBar+1);
      moveReturned=getNextMove(move,count*2+1,currentBar-count);
     }
   return(currentBar);
}
  
int getNextMove(int move, int count, int startPos)
{
   if(startPos<0)
     {
      count +=startPos;
      startPos =0;
     }
   return((move==MODE_HIGH)?
          iHighest(Symbol(),Period(),(ENUM_SERIESMODE)move,count,startPos):
          iLowest(Symbol(),Period(),(ENUM_SERIESMODE)move,count,startPos));
}
  
void DibujaArriba(string Nombre, int mColor)
{ 
   ObjectDelete(0,Nombre);
   ObjectCreate(0,Nombre,OBJ_TREND,0,iTime(Symbol(),Period(),high2),iHigh(Symbol(),Period(),high2),iTime(Symbol(),Period(),high1),iHigh(Symbol(),Period(),high1));
   ObjectSetInteger(0,Nombre,OBJPROP_COLOR,mColor);
   ObjectSetInteger(0,Nombre,OBJPROP_WIDTH,1);
   ObjectSetInteger(0,Nombre,OBJPROP_RAY_RIGHT,true);

}

void DibujaAbajo(string Nombre, int mColor)
{ 
   ObjectDelete(0,Nombre);
   ObjectCreate(0,Nombre,OBJ_TREND,0,iTime(Symbol(),Period(),low2),iLow(Symbol(),Period(),low2),iTime(Symbol(),Period(),low1),iLow(Symbol(),Period(),low1));
   ObjectSetInteger(0,Nombre,OBJPROP_COLOR,mColor);
   ObjectSetInteger(0,Nombre,OBJPROP_WIDTH,1);
   ObjectSetInteger(0,Nombre,OBJPROP_RAY_RIGHT,true);
}

void PonEtiquetas()
{ 
   ObjectCreate((int)_Symbol,"LS0", OBJ_LABEL, 0, 0, 0);
   ObjectSetString(0,"LS0",OBJPROP_FONT,"Arial");
   ObjectSetInteger(0,"LS0",OBJPROP_FONTSIZE,25); 
   ObjectSetInteger(0,"LS0",OBJPROP_COLOR,clrGreen);    
   ObjectSetInteger(0,"LS0", OBJPROP_CORNER, 4);   
   ObjectSetInteger(0,"LS0", OBJPROP_XDISTANCE, 800);
   ObjectSetInteger(0,"LS0", OBJPROP_YDISTANCE, 50);
   ObjectSetString((int)_Symbol,"LS0",OBJPROP_TEXT,0,"-");  
   
   ObjectCreate((int)_Symbol,"LS1", OBJ_LABEL, 0, 0, 0);
   ObjectSetString(0,"LS1",OBJPROP_FONT,"Arial");
   ObjectSetInteger(0,"LS1",OBJPROP_FONTSIZE,25); 
   ObjectSetInteger(0,"LS1",OBJPROP_COLOR,clrRed);    
   ObjectSetInteger(0,"LS1", OBJPROP_CORNER, 4);   
   ObjectSetInteger(0,"LS1", OBJPROP_XDISTANCE, 800);
   ObjectSetInteger(0,"LS1", OBJPROP_YDISTANCE, 90);
   ObjectSetString((int)_Symbol,"LS1",OBJPROP_TEXT,0,"-");  
   
   ObjectCreate((int)_Symbol,"LS2", OBJ_LABEL, 0, 0, 0);
   ObjectSetString(0,"LS2",OBJPROP_FONT,"Arial");
   ObjectSetInteger(0,"LS2",OBJPROP_FONTSIZE,25); 
   ObjectSetInteger(0,"LS2",OBJPROP_COLOR,clrWhiteSmoke);    
   ObjectSetInteger(0,"LS2", OBJPROP_CORNER, 4);   
   ObjectSetInteger(0,"LS2", OBJPROP_XDISTANCE, 800);
   ObjectSetInteger(0,"LS2", OBJPROP_YDISTANCE, 130);
   ObjectSetString((int)_Symbol,"LS2",OBJPROP_TEXT,0,"-");        
}
Reason: