Indicators: AutoTrendLines

 

AutoTrendLines:

Indicator automatically identifies points and it draws support and resistance trend lines on them. There are two type of calculation lines.

AutoTrendLines type 1 (EXM_EXM)

Author: Serhii Ivanenko

 

How to Exit While Trading with Trendlines

Talking Points:

  • Traders should focus on their exit plan just as much as their trade entries.
  • Trendline traders could set their stop losses beyond the nearest support or resistance level and set their limits within the nearest support or resistance level.
  • Setting exit prices according to support and resistance levels could tip the odds in your favor.
How Important Is Your Exit Strategy?

Many traders have a strong set of rules that they follow to enter trades, but have difficulty in selecting their exits. This is troubling because how we exit a trade should be just as important, if not more important than how a trade is entered. After all, our exits ultimately determine if our trades are profitable for us or not. So we need to make sure our exit strategy is just as logical as our entry strategy.

When we place our trades based on trendlines, we are placing them based on support and resistance levels. We are thinking the price will bounce off a trendline like it did in the past. I propose we use the same logic when setting our stops and limits.


In the example above, it’s easy to see the sell entry that was given to us based on the bearish trendline. We entered right at the trendline looking for a bounce back down, but where do we want to exit? When do we call it quits if the trade goes against us? Where do we place our profit target? Let’s take a look.

Setting Stops Beyond Support/Resistance

We need to look at placing our stop somewhere above this trendline. If the resistance is broken through, we were wrong on the trade and should accept the loss quickly. It’s possible that price could return back to profitable territory after breaking this resistance, but we cannot rely on being lucky. We can only trade based on what we see.



I like to set my stop 5-25 pips from the closest support/resistance level depending on the time frame I am trading. The smaller the time frame of the chart, the tighter I will place my stops. On this trade, I set my stop 5-6 pips away from my entry since that was beyond the resistance line as well as the previous swing high (Bounce #2).

Remember that when we set our Stop loss, this is also setting our monetary risk on the trade. So we also need to consider our trade side in respect to our Stop loss distance.

Setting Limits Within Support/Resistance


Now that our stop is set, we need to focus on our profit target. For our limit placement, we have two objectives:

  • Our limit’s distance needs to be further than our stop’s distance.
  • Our limit needs to be placed within the closest support/resistance (by at least 5 pips).
The reason we want our limit further than our stop is because we always want to try to make more money than what we are risking on each individual trade. This is something we discuss heavily at DailyFX so I will say it again here. We want a positive risk/reward ratio.

And the reason we want our limit to be placed within the closest support/resistance level (by at least 5 pips) is for the exact same rationale we used to open this trade to begin with. We know prices have a tendency to bounce off price levels they have bounced off of before, so we want to make sure that no support/resistance is in between our entry and our limit level. In the example below you can see I placed my limit 5 pips above the swing low (potential support). This gives price a clear path to a profitable trade.


Trendline Strategy Complete

This trendline strategy is one that can be used universally across all currency pairs and time frames so it is definitely a worthwhile style of trading to learn. The logic behind the entry and exit rules is also something that can be tailored to other types of strategies as well. Good trading!



 
Is there a version for MT4 using this indicator?
 
I do not know same indicator for MT4. There are similar indicator uploaded on this page
 
How can I use it for an Expert Advisor?
 
Aira MJ:
How can I use it for an Expert Advisor?

double valors = ObjectGetDouble(0, "Current_Support", OBJPROP_PRICE, 0);
   double valorr = ObjectGetDouble(0, "Current_Resistance", OBJPROP_PRICE, 0);
   
      //Comment("Suporte: "+valors + " resistência; "+valorr);
      
   
   double diff =    (PriceInfo1[0].low -valors);

Buy 64%

if(
      PositionsTotal() == 0
      ....
       && diff <=  valordim



Sell 72% precision

if(
      PositionsTotal() == 0
       ...
        && PriceInfo1[0].high >=  valorr

 
Jacinto José:

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post.

Please only post code that will compile.

Please also format your code to make it easier to read - it is very untidy.

 
Autotrendlines is one of the best free indicators. Many thanks to the creator of this indicator. But it has a big problem! It removes any trend line that the user itself draws. I have been waiting a long time for being fix of this problem. So I'll be very thankful if this problem is solved in the new update.
 
Autotrendlines is one of the best free indicators. Many thanks to the creator of this indicator. But it has a big problem! It removes any trend line that the user itself draws. I have been waiting a long time for being fix of this problem. So I'll be very thankful if this problem is solved in the new update.
 
Here the review thath delete only the line created by the indicator and leave other trend on the chart //+------------------------------------------------------------------+ //| AutoTrendLines.mq5 | //| Copyright 2012, Rone. | //| rone.sergey@gmail.com | //+------------------------------------------------------------------+ // https://www.mql5.com/en/code/1220 //+------------------------------------------------------------------+ //| Automatic trend lines. | //| Type 1. With two extremums. | //| 1) From the current bar "go" to the left and look for the first | //| (right) extremum point with the InpRightExmSide bars on both | //| sides. | //| 2) From the first point again "go" to the left and look for the | //| second (left) extremum point with the InpLeftExmSide bars on | //| both sides. | //| 3) Draw a trend lines. | //| | //| Type 2. With extremum and delta. | //| 1) From the current bar "go" to the left and look for the second | //| (left) extremum point with the InpLeftExmSide bars on both sides.| //| 2) Starting with the InpFromCurrent bar from the current bar and | //| to the second extremum point find the bar with minimal delta. | //| 3) Draw a trend lines. | //| | //| NOTE: | //| 1) The lines are recalculated only when a new bar appears | //| 2) The current unformed bar does not included in the calculations| //| 3) The extremum means a bar, for which the left and right | //| N bars have minimums above and maximums | //| below. | //+------------------------------------------------------------------+ #property copyright "Copyright 2012, Rone." #property link "rone.sergey@gmail.com" #property version "1.00" #property description "Automatic trend lines" //--- #property indicator_chart_window //--- string prefisso="AUTO_TRND"; enum ENUM_LINE_TYPE { EXM_EXM, // 1: By 2 extremums EXM_DELTA // 2: Extremum and delta }; //+------------------------------------------------------------------+ //| Class CPoint | //+------------------------------------------------------------------+ class CPoint { private: double price; datetime time; public: CPoint(); CPoint(const double p, const datetime t); ~CPoint() {}; void setPoint(const double p, const datetime t); bool operator==(const CPoint &other) const; bool operator!=(const CPoint &other) const; void operator=(const CPoint &other); double getPrice() const; datetime getTime() const; }; //--- CPoint::CPoint(void) { price = 0; time = 0; } //--- CPoint::CPoint(const double p, const datetime t) { price = p; time = t; } //--- void CPoint::setPoint(const double p, const datetime t) { price = p; time = t; } //--- bool CPoint::operator==(const CPoint &other) const { return price == other.price && time == other.time; } //--- bool CPoint::operator!=(const CPoint &other) const { return !operator==(other); } //--- void CPoint::operator=(const CPoint &other) { price = other.price; time = other.time; } //--- double CPoint::getPrice(void) const { return(price); } //--- datetime CPoint::getTime(void) const { return(time); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ CPoint curLeftSup, curRightSup, curLeftRes, curRightRes, nullPoint; //+------------------------------------------------------------------+ //| input parameters | //+------------------------------------------------------------------+ input ENUM_LINE_TYPE InpLineType = EXM_DELTA;// Line type input int InpLeftExmSide = 10; // Left extremum side (Type 1, 2) input int InpRightExmSide = 3; // Right extremum side (Type 1) input int InpFromCurrent = 3; // Offset from the current barà (Type 2) input bool InpPrevExmBar = false; // Account for the bar before the extremum (Type 2) //--- input int InpLinesWidth = 2; // lines width input color InpSupColor = clrRed; // Support line color input color InpResColor = clrBlue; // Resistance line color //--- global variables int minRequiredBars; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- minRequiredBars = InpLeftExmSide * 2 + MathMax(InpRightExmSide, InpFromCurrent) * 2; //--- indicator buffers mapping //--- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- int obj_total = ObjectsTotal(0,0); for(int i=obj_total -1; i>=0; i--) { string name= ObjectName(0,i); if(StringFind(name,prefisso,0) == 0) ObjectDelete(0, name); } //--- } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- int leftIndex, rightIndex; double delta, tmpDelta; //--- if ( rates_total < minRequiredBars ) { Print("Not enough data to calculate"); return(0); } //--- if ( prev_calculated != rates_total ) { switch ( InpLineType ) { case EXM_DELTA: //--- Support Left Point leftIndex = rates_total - InpLeftExmSide - 2; for ( ; !isLowestLow(leftIndex, InpLeftExmSide, low) && leftIndex > minRequiredBars; leftIndex-- ); curLeftSup.setPoint(low[leftIndex], time[leftIndex]); //--- Support Right Point rightIndex = rates_total - InpFromCurrent - 2; delta = (low[rightIndex] - low[leftIndex]) / (rightIndex - leftIndex); if ( !InpPrevExmBar ) { leftIndex += 1; } for ( int tmpIndex = rightIndex - 1; tmpIndex > leftIndex; tmpIndex-- ) { tmpDelta = (low[tmpIndex] - curLeftSup.getPrice()) / (tmpIndex - leftIndex); if ( tmpDelta < delta ) { delta = tmpDelta; rightIndex = tmpIndex; } } curRightSup.setPoint(low[rightIndex], time[rightIndex]); //--- Resistance Left Point leftIndex = rates_total - InpLeftExmSide - 2; for ( ; !isHighestHigh(leftIndex, InpLeftExmSide, high) && leftIndex > minRequiredBars; leftIndex-- ); curLeftRes.setPoint(high[leftIndex], time[leftIndex]); //--- Resistance Right Point rightIndex = rates_total - InpFromCurrent - 2; delta = (high[leftIndex] - high[rightIndex]) / (rightIndex - leftIndex); if ( !InpPrevExmBar ) { leftIndex += 1; } for ( int tmpIndex = rightIndex - 1; tmpIndex > leftIndex; tmpIndex-- ) { tmpDelta = (curLeftRes.getPrice() - high[tmpIndex]) / (tmpIndex - leftIndex); if ( tmpDelta < delta ) { delta = tmpDelta; rightIndex = tmpIndex; } } curRightRes.setPoint(high[rightIndex], time[rightIndex]); //--- break; case EXM_EXM: default: //--- Support Right Point rightIndex = rates_total - InpRightExmSide - 2; for ( ; !isLowestLow(rightIndex, InpRightExmSide, low) && rightIndex > minRequiredBars; rightIndex-- ); curRightSup.setPoint(low[rightIndex], time[rightIndex]); //--- Support Left Point leftIndex = rightIndex - InpRightExmSide; for ( ; !isLowestLow(leftIndex, InpLeftExmSide, low) && leftIndex > minRequiredBars; leftIndex-- ); curLeftSup.setPoint(low[leftIndex], time[leftIndex]); //--- Resistance Right Point rightIndex = rates_total - InpRightExmSide - 2; for ( ; !isHighestHigh(rightIndex, InpRightExmSide, high) && rightIndex > minRequiredBars; rightIndex-- ); curRightRes.setPoint(high[rightIndex], time[rightIndex]); //--- Resistance Left Point leftIndex = rightIndex - InpRightExmSide; for ( ; !isHighestHigh(leftIndex, InpLeftExmSide, high) && leftIndex > minRequiredBars; leftIndex-- ); curLeftRes.setPoint(high[leftIndex], time[leftIndex]); //--- break; } //--- Draw Support & Resistance if ( curLeftSup != nullPoint && curRightSup != nullPoint ) { drawLine(prefisso+"Current_Support", curRightSup, curLeftSup, InpSupColor); } if ( curLeftRes != nullPoint && curRightRes != nullPoint ) { drawLine(prefisso+"Current_Resistance", curRightRes, curLeftRes, InpResColor); } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| The Local Low search function | //+------------------------------------------------------------------+ bool isLowestLow(int bar, int side, const double &Low[]) { //--- for ( int i = 1; i <= side; i++ ) { if ( Low[bar] > Low[bar-i] || Low[bar] > Low[bar+i] ) { return(false); } } //--- return(true); } //+------------------------------------------------------------------+ //| The Local High search function | //+------------------------------------------------------------------+ bool isHighestHigh(int bar, int side, const double &High[]) { //--- for ( int i = 1; i <= side; i++ ) { if ( High[bar] < High[bar-i] || High[bar] < High[bar+i] ) { return(false); } } //--- return(true); } //+------------------------------------------------------------------+ //| Draw trend line function | //+------------------------------------------------------------------+ void drawLine(string name, CPoint &right, CPoint &left, color clr) { //--- ObjectDelete(0, name); //--- ObjectCreate(0, name, OBJ_TREND, 0, right.getTime(), right.getPrice(), left.getTime(), left.getPrice()); ObjectSetInteger(0, name, OBJPROP_WIDTH, InpLinesWidth); ObjectSetInteger(0, name, OBJPROP_COLOR, clr); ObjectSetInteger(0, name, OBJPROP_RAY_LEFT, true); ObjectSetInteger(0, name, OBJPROP_SELECTABLE, true); //--- } //+------------------------------------------------------------------+