Discussion of article "How to deal with lines using MQL5"

 

New article How to deal with lines using MQL5 has been published:

In this article, you will find your way to deal with the most important lines like trendlines, support, and resistance by MQL5.

We can use the Trend line in trading by placing our orders based on the trend line type. If there is an upward trend line, we may expect the price moves down to test this trend line from above then rebounding to up and then we can place our buying order around this trend line. Vice versa, if there is a downward trend line, we may that the price moves up to test this trend line from below then rebounding to down and then we can place our shorting or selling order around this downward trend line.

The following is for the upward trend line:

 Up trendline

We can see that it is clear in the previous figure that we have an up movement and if we try to connect between the last three lows we can find that they are on the same line heading up.

Author: Mohamed Abdelmaaboud

 
but why   ObjectCreate(_Symbol,"supportLine",OBJ_HLINE,0,pArray[candleLow].time,pArray[candleLow].low, pArray[0].time,pArray[0].low);  ?
enough  ObjectCreate(_Symbol,"supportLine",OBJ_HLINE,0,pArray[candleLow].time,pArray[candleLow].low);
 
MetaQuotes:

The article"How to work with lines using MQL5 tools" has been published:

Author: Mohamed Abdelmaaboud

This is an interesting article for beginners, but for correct work of Expert Advisors a small modification of codes is required.

Regards, Vladimir.

//+------------------------------------------------------------------+
//|UpwardTrendline System.mq5 |
//+------------------------------------------------------------------+
void OnTick()
  {
   int candles = (int)ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0);
   double pLow[];
   ArraySetAsSeries(pLow,true);
   int copy_low = CopyLow(_Symbol,_Period,0,candles,pLow);
   if(copy_low>0)
     {
      int candleLow = ArrayMinimum(pLow,0,candles);
      MqlRates pArray[];
      ArraySetAsSeries(pArray,true);
      int Data = CopyRates(_Symbol,_Period,0,candles,pArray);
      ObjectDelete(0,"UpwardTrendline");
      ObjectCreate(0,"UpwardTrendline",OBJ_TREND,0,pArray[candleLow].time,pArray[candleLow].low,
                   pArray[0].time,pArray[0].low);
      ObjectSetInteger(0,"UpwardTrendline",OBJPROP_COLOR,Blue);
      ObjectSetInteger(0,"UpwardTrendline",OBJPROP_STYLE,STYLE_SOLID);
      ObjectSetInteger(0,"UpwardTrendline",OBJPROP_WIDTH,3);
      ObjectSetInteger(0,"UpwardTrendline",OBJPROP_RAY_RIGHT,true);
     }
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//|DownwardTrendline System.mq5 |
//+------------------------------------------------------------------+
void OnTick()
  {
   int candles = (int)ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0);
   double pHigh[];
   ArraySetAsSeries(pHigh,true);
   int copy_high = CopyHigh(_Symbol,_Period,0,candles,pHigh);
   if(copy_high>0)
     {
      int candleHigh = ArrayMaximum(pHigh,0,candles);
      MqlRates pArray[];
      ArraySetAsSeries(pArray,true);
      int Data = CopyRates(_Symbol,_Period,0,candles,pArray);
      ObjectDelete(0,"DnwardTrendline");
      ObjectCreate(0,"DnwardTrendline",OBJ_TREND,0,pArray[candleHigh].time,pArray[candleHigh].high,
                   pArray[0].time,pArray[0].high);
      ObjectSetInteger(0,"DnwardTrendline",OBJPROP_COLOR,Blue);
      ObjectSetInteger(0,"DnwardTrendline",OBJPROP_STYLE,STYLE_SOLID);
      ObjectSetInteger(0,"DnwardTrendline",OBJPROP_WIDTH,3);
      ObjectSetInteger(0,"DnwardTrendline",OBJPROP_RAY_RIGHT,true);
     }
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//|Support Line System.mq5 |
//+------------------------------------------------------------------+
void OnTick()
  {
   int candles = (int)ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0);
   double pLow[];
   ArraySetAsSeries(pLow,true);
   int copy_low = CopyLow(_Symbol,_Period,0,candles,pLow);
   if(copy_low>0)
     {
      int candleLow = ArrayMinimum(pLow,0,candles);
      MqlRates pArray[];
      ArraySetAsSeries(pArray,true);
      int Data = CopyRates(_Symbol,_Period,0,candles,pArray);
      ObjectDelete(0,"supportLine");
      ObjectCreate(0,"supportLine",OBJ_HLINE,0,pArray[candleLow].time,pArray[candleLow].low,
                   pArray[0].time,pArray[0].low);
      ObjectSetInteger(0,"supportLine",OBJPROP_COLOR,Green);
      ObjectSetInteger(0,"supportLine",OBJPROP_STYLE,STYLE_SOLID);
      ObjectSetInteger(0,"supportLine",OBJPROP_WIDTH,3);
      ObjectSetInteger(0,"supportLine",OBJPROP_RAY,true);
     }
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//|Resistance Line System.mq5 |
//+------------------------------------------------------------------+
void OnTick()
  {
   int candles=(int)ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR,0);
   double pHigh[];
   ArraySetAsSeries(pHigh,true);
   int copy_high = CopyHigh(_Symbol,_Period,0,candles,pHigh);
   if(copy_high>0)
     {
      int candleHigh = ArrayMaximum(pHigh,0,candles);
      MqlRates pArray[];
      ArraySetAsSeries(pArray,true);
      int Data = CopyRates(_Symbol,_Period,0,candles,pArray);
      ObjectDelete(0,"resistanceLine");
      ObjectCreate(0,"resistanceLine",OBJ_HLINE,0,pArray[candleHigh].time,pArray[candleHigh].high,
                   pArray[0].time,pArray[0].high);
      ObjectSetInteger(0,"resistanceLine",OBJPROP_COLOR,Red);
      ObjectSetInteger(0,"resistanceLine",OBJPROP_STYLE,STYLE_SOLID);
      ObjectSetInteger(0,"resistanceLine",OBJPROP_WIDTH,3);
      ObjectSetInteger(0,"DnwardTrendline",OBJPROP_RAY_RIGHT,true);
     }
  }
//+------------------------------------------------------------------+
 
MrBrooklin #:

Interesting article for beginners, but for EAs to work correctly, a little tweaking of codes is required.

Regards, Vladimir.




Thanks for your kind comment, I will review it.
 
The way you drew the line is very nice. One observation about trend lines: It doesn't do much good if the second anchor point is always the 0 index bar, because with each new bar the trend line will be updated and so the trend line will be of no use. The ideal would be to define the second anchor point based on a specific criterion. For example, the second bar with the highest price, with a minimum distance of 30 bars from the first, or take the bar with the highest price the next day, and so on.

Congratulations on the article.
 
Andrei Pereira trend lines: It doesn't do much good if the second anchor point is always the 0 index bar, because with each new bar the trend line will be updated and so the trend line will be of no use. The ideal would be to define the second anchor point based on a specific criterion. For example, the second bar with the highest price, at least 30 bars away from the first, or take the bar with the highest price the next day, and so on.

Congratulations on the article.

Thanks for your comment, it's a good observation.

 
Mohamed Abdelmaaboud #:
Thanks for the kind comment, I will revise it.

It's been almost 10 months and no changes to his codes have been made by the author of the article. ))

Regards, Vladimir.

 
MrBrooklin #:

Almost 10 months have passed, and the author of the article hasn't made any changes in his codes. ))

Regards, Vladimir.

Thank you for your reminder and contribution. It will be sent for editing.