NexusFi: Find Your Edge


Home Menu

 





how to get highest number using for loop in EL


Discussion in EasyLanguage Programming

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




 
Search this Thread

how to get highest number using for loop in EL

  #1 (permalink)
 Sinuhet 
London
 
Experience: Advanced
Platform: Multicharts
Trading: ES
Posts: 4 since Oct 2015
Thanks Given: 2
Thanks Received: 4

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

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Any futures traders in Texas looking to give back to tho …
Traders Hideout
Better Renko Gaps
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
20 thanks
Just another trading journal: PA, Wyckoff & Trends
16 thanks
My NQ Trading Journal
15 thanks
Coding money management strategies.
14 thanks
HumbleTraders next chapter
9 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,626


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
Thanked by:
  #4 (permalink)
 Sinuhet 
London
 
Experience: Advanced
Platform: Multicharts
Trading: ES
Posts: 4 since Oct 2015
Thanks Given: 2
Thanks Received: 4

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
Thanked by:
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,626

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
Thanked by:
  #6 (permalink)
 Sinuhet 
London
 
Experience: Advanced
Platform: Multicharts
Trading: ES
Posts: 4 since Oct 2015
Thanks Given: 2
Thanks Received: 4

Thank you!
Now works everything as supposed to!
Sinuhet

Started this thread Reply With Quote
Thanked by:
  #7 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,626

Sinuhet,

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

Regards,

ABCTG

Follow me on Twitter Reply With Quote




Last Updated on September 20, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts