- MetaTrader 5 Python User Group - how to use Python in Metatrader
- How do I remove an element from an array (one-dimensional two-dimensional)?
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
- 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.21Or pay someone. Top of every page is the link Freelance.
Hiring to write script - General - MQL5 programming forum 2018.05.12 - 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.

- www.mql5.com
- 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].
- 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 codeDo 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 problemHow 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 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

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use