How do I add a trendline from start of bull and end of bull bars

 
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   1
#property strict

//--- plot
#property indicator_label1  "N"
#property indicator_type1   DRAW_NONE
#property indicator_color1  C'8,153,129'
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2

//--- input parameters
input int   ObjFs    = 8;              // Font size arrow

input color BullArr  = clrGreen;   // Bull arrow candle
input color BearArr  = clrRed;     // Bear arrow candle
input color CrossArr = clrDarkOrange;  // Cross arrow candle

//--- indicator buffers
double Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {
//--- indicator buffers
   SetIndexBuffer(0,Buffer,INDICATOR_DATA);
   ArraySetAsSeries(Buffer,true);

   IndicatorSetInteger(INDICATOR_DIGITS,0);
   IndicatorSetString(INDICATOR_SHORTNAME,"Numbering Candles:");
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
//--- delete graphics
   ObjectsDeleteAll(0,"Bull_");
   ObjectsDeleteAll(0,"Bear_");
   ObjectsDeleteAll(0,"Cross_");
   ChartRedraw();
//---
}
//+------------------------------------------------------------------+
//| 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 up=0,dn=0,res=0;
   int limit=rates_total-prev_calculated;

   if(limit==0)
      return(rates_total);

   if(limit==1)
      limit=20;
//---
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(time,true);
   
//---
   for(int i=limit-1; i>0; i--) {

      if(open[i]<close[i]) {
         up++;
         SetText("Bull_"+(string)time[i],(string)up,time[i],low[i],BullArr,ANCHOR_UPPER);


      } else up=0;


      if(open[i]>close[i]) {
         dn++;
         SetText("Bear_"+(string)time[i],(string)dn,time[i],high[i],BearArr,ANCHOR_LOWER);
      } else dn=0;


      res=up+dn*-1;
      if(res==0)
         SetText("Cross_"+(string)time[i],(string)res,time[i],high[i],CrossArr,ANCHOR_LOWER);
      Buffer[i]=res;
   }
   Buffer[0]=res;



//--- return value of prev_calculated for next call
   return(rates_total);
}
//+----------------------------------------------------------------------------+
void SetText(string nm,string text,datetime t,double p,color clr, ENUM_ANCHOR_POINT anchor) {
   if(ObjectFind(0,nm)<0) {
      ObjectCreate(0,nm,OBJ_TEXT,0,0,0);
      ObjectSetString(0,nm,OBJPROP_FONT,"Arial");
      ObjectSetInteger(0,nm,OBJPROP_FONTSIZE,ObjFs);
      ObjectSetInteger(0,nm,OBJPROP_ANCHOR,anchor);
      ObjectSetInteger(0,nm,OBJPROP_COLOR,clr);
      ObjectSetInteger(0,nm,OBJPROP_SELECTABLE,true);
      ObjectSetInteger(0,nm,OBJPROP_SELECTED,false);
      ObjectSetInteger(0,nm,OBJPROP_BACK,false);
      ObjectSetInteger(0,nm,OBJPROP_HIDDEN,false);
      ObjectSetString(0,nm,OBJPROP_TEXT,text);
      ObjectSetDouble(0,nm,OBJPROP_PRICE,p);
      ObjectSetInteger(0,nm,OBJPROP_TIME,t);
   }
}

//+----------------------------------------------------------------------------+

Hello, I would like to add a trendline which starts from bull bar and it should end on last bull bar.

How can i do that?


 
Rodger Sen: How can i do that?

Learn to code. Find the last, find the first, create the TL.

You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
          No free help (2017)

Or pay someone. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum (2018)

We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
          No free help (2017)

 
William Roeder #:

Learn to code. Find the last, find the first, create the TL.

Tell me in more detail how to find the first and last, I already know how to code so you may not be required to post code, although you can post code if you think I am lucky,

 
Rodger Sen #: Tell me in more detail how to find the first and last,
int iBeg = 1;    while(!isBull(iBeg) ) ++iBeg;
int iEnd = iBeg; while( isBull(iEnd) ) ++iEnd;
if(iEnd - iFirst > 1) drawLine(iFirst, iEnd);
 
William Roeder #:

this code is totally unrelatable to my code and does not help at all, but thanks for your attempt. Expecting someone else may help in more clear way by at least reading the code which i have posted. Its better if you avoid posting such pathetic code where it is even not defined what is iFirst.

 
Rodger Sen #:

this code is totally unrelatable to my code and does not help at all, but thanks for your attempt. Expecting someone else may help in more clear way by at least reading the code which i have posted. Its better if you avoid posting such pathetic code where it is even not defined what is iFirst.

  1. Please be polite when communicating on this website. Refrain from statements that may offend or insult other users.
  2. Negative discussions of any banking, brokerage and other financial institutions are not allowed.
  3. Any discussions about personal relations between the community members are not tolerated.
  4. Coarse language, advertising messages, spamming and flooding are forbidden.
  5. Repeated violation of the Rules, ignoring moderator's remarks and open disrespect for the website Administration will lead to an account termination.
  6. The website Administration may implement any changes to the Rules it deems necessary.

If you want help on this site you should change your tone. If an answer doesn't suit you, ignore it.

 
Rodger Sen #: this code is totally unrelatable to my code and does not help at all,
Correct, it has nothing to do with your code. It is exactly what your question was.
Rodger Sen #: Tell me in more detail how to find the first and last, I already know how to code

You said you know how to code, so replace the functions with your code. What's the problem?

Or pay (Freelance) someone to code it. Top of every page is the link Freelance.
          Hiring to write script - General - MQL5 programming forum (2019)

We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
          No free help (2017)

 
William Roeder #:
Correct, it has nothing to do with your code. It is exactly what your question was.

You said you know how to code, so replace the functions with your code. What's the problem?

after seeing your code my crystalball cracked 😂 

Reason: