how to get highest number using for loop in EL - futures io
futures io futures trading



how to get highest number using for loop in EL


Discussion in EasyLanguage Programming

Updated
    1. trending_up 1,519 views
    2. thumb_up 6 thanks given
    3. group 2 followers
    1. forum 6 posts
    2. attach_file 1 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

how to get highest number using for loop in EL

(login for full post details)
  #1 (permalink)
London
 
Experience: Advanced
Platform: Multicharts
Trading: ES
 
Posts: 4 since Oct 2015
Thanks: 2 given, 4 received

Dear all
I would like to ask for help.
I have a "For loop"with for x =0 to 9 returning correctly 10 different numbers on each bar (confirmed by Print).
I need to pick up the highest number from these 10 numbers and do some further computing with it.
I have tried with Highest function and with Maxlist function, but so far failed.
Any help would be highly appreciated.
Thank you

Started this thread Reply With Quote

Journal Challenge February 2021 results:
Competing for $1500 in prizes from Topstep
looks_oneSBtrader82 's Trading Journalby SBtrader82
(173 thanks from 31 posts)
looks_twoJust BEING a Trader: Letting Go!!by iqgod
(120 thanks from 33 posts)
looks_3Wisdom is Emptinessby Mtype
(68 thanks from 25 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(35 thanks from 17 posts)
looks_5Journal for peanuts1956by peanuts1956
(23 thanks from 13 posts)
 
 
(login for full post details)
  #3 (permalink)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,471 received


Sinuhet,

the easiest will likely be to use a variable and compare during the loop if the current loop value is higher than the stored value in the variable. Make sure to remember resetting the variable each time before you enter the loop.

Something along the lines of this should do it:
 
Code
myTrackingVariable = -999999 ;

for ii = 0 to 9 
begin 
   //update the tracking variable
   if High[ii] > myTrackingVariable then
      myTrackingVariable = High[ii] ;
 end ;
At the end of this loop myTrackingVariable will hold the highest high of the last ten bars.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
The following user says Thank You to ABCTG for this post:
 
(login for full post details)
  #4 (permalink)
London
 
Experience: Advanced
Platform: Multicharts
Trading: ES
 
Posts: 4 since Oct 2015
Thanks: 2 given, 4 received

Thx ABCTG. I am afraid I still do something wrong, since getting only the last value in the loop. I have created code as an example and a screenshot to it. I simply would like to get at the end of the loop the highest Bar Range which occured during the looping.
Would be great if you could look where I am wrong.
Thank you
Sinuhet

 
Code
Code:
Inputs: Strength(3), 	                // bars on either side of the swing 
	    Length(250);		// within "length" trailing bars

Vars:    SHBB1(0),		       //number of bars ago the last Swing High occurred
            SHBB2(0),		       //number of bars ago 2nd last Swing High occurred
            MaxRange(-999999),//Value of max Bar Range
            RangeX(0),		      //Bar (price) Range
            x(0);			      //Counter for "FOR LOOP"

{define Swing Highs}
SHBB1 = (SwingHighBar(1,High,Strength,Length));
SHBB2 = (SwingHighBar(2,High,Strength,Length));

{paint Swing High Bars}
If SHBB1 = Strength then
PlotPaintBar[SHBB1](high[SHBB1],low[SHBB1],open[SHBB1],close[SHBB1], "Swing High Bar",Red);


{Find Max Range Bar if trend UP}
If high[SHBB1] > high[SHBB2] {= last Swing High > previous Swing High} then 
Begin
     if SHBB1 = Strength {new Last Swing High just created} then
     begin
	   MaxRange = -999999;	//reset before loop begins!
	   For x = 0 to SHBB2       //loop from the current bar to the 2nd last Swing High 
          begin
		 RangeX = High[x] - Low[x];		// define Range first
		 If RangeX[x] > MaxRange then
		 MaxRange = RangeX[x];		
          end;
     end;
End;
//**************************************************************************************
//DEBUG:
// Display MaxRange over the last Bar
If MaxRange <> MaxRange[1] then
Text_New(date,time,high,NumToStr(MaxRange,6)+"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");

// For control display Range over each Bar
Text_New(date,time,high,NumToStr(High-Low,6)+"\n\n\n\n\n\n");
Screenshot:

Started this thread Reply With Quote
The following 2 users say Thank You to Sinuhet for this post:
 
(login for full post details)
  #5 (permalink)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,471 received

Sinuhet,

you are welcome.
What's the purpose of using RangeX[x] in your loop instead of RangeX? The values can/will be different and from your code it appears you are looking for
 
Code
RangeX = High[x] - Low[x];	
if RangeX > MaxRange then 
    MaxRange = RangeX;
This should give you the bar range within the bars you loop over.
By the way you can show your appreciation for posts on futures.io by clicking the "Thanks" button next to a post.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
The following 2 users say Thank You to ABCTG for this post:
 
(login for full post details)
  #6 (permalink)
London
 
Experience: Advanced
Platform: Multicharts
Trading: ES
 
Posts: 4 since Oct 2015
Thanks: 2 given, 4 received

Thank you!
Now works everything as supposed to!
Sinuhet

Started this thread Reply With Quote
The following user says Thank You to Sinuhet for this post:
 
(login for full post details)
  #7 (permalink)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,471 received

Sinuhet,

great, I am glad to hear that. Thanks for letting me know.

Regards,

ABCTG

Follow me on Twitter Reply With Quote


futures io Trading Community Platforms and Indicators EasyLanguage Programming > how to get highest number using for loop in EL


Last Updated on September 20, 2016


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Call Option Buying: The New Pain Trade? w/Carley Garner

Elite only
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

New Challenge (TBD)

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts