Get elements in an array

 
I would like to increment in the array. For instance, if the low of LF[0] is greater than the low of LF[1] then increment to LF[2]. And how do I draw a trendline from one element in the array to another.
//+------------------------------------------------------------------+
//|                                                        1Frac.mq4 |
//|                                       Copyright 2020, YarnnyArmy |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, YarnnyArmy"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrBlue
#property indicator_width1 3

double LF[];
double LowerFrac;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,LF);
   SetIndexArrow(0,222);
   SetIndexLabel(0,"First Frac");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   for (int i = 200;i > 3; i--)
         {
              if (Low[i-2] > Low[i-1])
              {
                  if (Low[i-1] > Low[i])
                  {
                     if (Low[i] < Low[i+1])
                     {
                        if (Low[i+1] < Low[i+2])
                        {
                           LF[i] = Low[i];
                        }
                     }
                  }
              }
             
         }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
  1. yarnnyarmy: I would like to increment in the array. For instance, if the low of LF[0] is greater than the low of LF[1] then increment to LF[2].
    So do it. You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
              No free help 2017.04.21

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

  2. yarnnyarmy: And how do I draw a trendline from one element in the array to another.

    You don't. Your arrays have nothing to do with trendlines.

    If your array has prices, you can draw a trendline from one price to another. Perhaps you should read the manual.
       How To Ask Questions The Smart Way. 2004
          How To Interpret Answers.
              RTFM and STFW: How To Tell You've Seriously Screwed Up.

 
//+------------------------------------------------------------------+
//|                                                      Samarai.mq4 |
//|                                       Copyright 2020, YarnnyArmy |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, YarnnyArmy"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrGreen
#property indicator_type1 DRAW_ARROW
#property indicator_width1 3
#property indicator_color2 clrBlue
#property indicator_type2 DRAW_ARROW
#property indicator_width2 3

double LF1[];
double LF2[];

int LowerFrac1;
int LowerFrac2;
double BarsforFormation = 2;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//++++++++++------------------------------------+*+/------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,LF1);
   SetIndexArrow(0,222);
   SetIndexLabel(0,"First Frac");
    SetIndexBuffer(1,LF2);
   SetIndexArrow(1,222);
   SetIndexLabel(1,"Sec Frac");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//--
   for (int i = Bars-3;i > 3; i--)
         {
              if (down(Low,i))
              {
                  LF1[i] = Low[i];
                  LowerFrac1=i;
              }
         }
         
   for (int n = Bars; n > LowerFrac1; n--)//since I found the first Fractal, I will only loop to it and no farther
         {
            if (down(Low,n))//refer to line 114
            {
               if (Low[n] < Low[LowerFrac1])//if the new Fractal is lower than the first Fractal I found
                  {
                     LowerFrac2 = n;//store the value as LowerFrac2
                     //the next information will be used to calculate the slope of the bars between the two Fractals
                     //I am using the slope formula y2-y1/x2-x1
                     double SecPoint = Low[LowerFrac2];//
                     double FirstPoint= Low[LowerFrac1];
                     double Yvalue = FirstPoint - SecPoint;
                     double Xvalue = MathAbs((LowerFrac1 - LowerFrac2));//using mathAbs so x won't return a negative value
                     double slope = Yvalue / Xvalue;//the slope formula for the numbers i found
                     double slopeA;//if the slope is less than the slope between the two Fractals the return false
                     bool valid = true;
                     for (int a = LowerFrac2 -1 ; a > LowerFrac1; a--)
                     {
                      //a is the bars counting to the lowerfract1
                      //if the slope from a to lowerfract1 is less than the slope from lowerfract2 to lowerfract1
                      //then the trend is invalid
                      //which means that a bar between the two Fractals is lower than the slope
                              slopeA = ((Low[a] - SecPoint) / MathAbs(( a - LowerFrac2)));
                              if (slopeA < slope)
                              { 
                               valid = false;
                               break;
                              }  
                      }
                     if(valid == true)
                     {
                        LF2[n] = Low[LowerFrac2]-40*_Point;//if a bar did not break the trendline then set LF2[n] is the Low of LowerFrac2
                        //the reason I set it that is because I wanted to be able to see it on the chart.
                        Comment(LowerFrac2);
                     }
                  }//end second if
            }//end first if0
         }//end for loop
//--- return value of prev_calculated for next call
   return(rates_total);
  }
  //calculate if bar is a fractal
  //if the low is lower the the previous 2 bars and 2 bars following
  //then mark it
     bool down(const double &h[],int q)
  {
   if(q>=ArraySize(h)-2)return(false);
   if(h[q]<h[q-1])
      if(h[q-1]<h[q-2])
         if(h[q]<h[q+1])
            if(h[q+1]<h[q+2])
               return(true);
   return(false);
         }
//+------------------------------------------------------------------+
//I would like for the code to be able to draw a line
//from all Fractal1s and Fractal2s that meet the conditions.
//as long as a bar does not break the trendline
//I want it to draw a trendline.
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Dozens of new automated trading applications appear in the MQL5 Market every day. Choose the right app among 10,000 products and forget about unnecessary routine operations of manual trading. Sell your algorithmic trading programs through the largest store of trading applications! One Click Close The script allows users to easily close...
 
This is the code that I written myself. I have one array that stores the lowerfrac, I have another array that stores another lowerfrac from the first lowerfrac. If a bar's low breaks the trendline the first lowerfrac then it will not store that information in the array. My problem is I want to know how to get increment from one array to another. I guess I do not completely understand arrays. When I comment or print the information for an array I do not get my desired information. I do not want someone to write it for me because I am trying to learn. I just asked, how do I get different values in an array. I want to know if I comment LF1[0], how to get the first element in the array. If I comment LF1[1] get the second and so on. And if there is a way to increment from 1 element to another.
 
  1. yarnnyarmy I just asked, how do I get different values in an array. I want to know if I comment LF1[0],

    You already know how, you've just wrote LF1[0].

  2. yarnnyarmy: array I do not get my desired information.

    "Doesn't work" is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. 2004
              When asking about code

    Do you really expect an answer? There are no mind readers here and our crystal balls are cracked.
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

    How can we know what it's doing and what you want it to do?

    Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?

 
I do not want you to debug my code. That's why I wrote a simple code the first time and posted it. But don't worry about it I will figure it out, go about your happy day.
 
yarnnyarmy:
I would like to increment in the array. For instance, if the low of LF[0] is greater than the low of LF[1] then increment to LF[2]. And how do I draw a trendline from one element in the array to another.

You have actually built it .

Only thing you need to change is this :

#property indicator_type1 DRAW_ARROW

to this :

#property indicator_type1 DRAW_SECTION
Reason: