how to get highest number using for loop in EL - EasyLanguage Programming | futures.io
futures io futures trading


how to get highest number using for loop in EL
Started: by Sinuhet Views / Replies:211 / 6
Last Reply: Attachments:1

Welcome to futures io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


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, and we will never resell your private information.

-- Big Mike

Reply
 
Thread Tools Search this Thread
 

how to get highest number using for loop in EL

  #1 (permalink)
Elite Member
London
 
Futures Experience: Advanced
Platform: Multicharts
Favorite Futures: ES
 
Posts: 4 since Oct 2015
Thanks: 2 given, 3 received

how to get highest number using for loop in EL

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

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,260 since Apr 2013
Thanks: 201 given, 711 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

Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #4 (permalink)
Elite Member
London
 
Futures Experience: Advanced
Platform: Multicharts
Favorite Futures: ES
 
Posts: 4 since Oct 2015
Thanks: 2 given, 3 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:
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Reply With Quote
The following user says Thank You to Sinuhet for this post:
 
  #5 (permalink)
Elite Member
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,260 since Apr 2013
Thanks: 201 given, 711 received

Futures Edge on FIO
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

Reply With Quote
The following user says Thank You to ABCTG for this post:
 
  #6 (permalink)
Elite Member
London
 
Futures Experience: Advanced
Platform: Multicharts
Favorite Futures: ES
 
Posts: 4 since Oct 2015
Thanks: 2 given, 3 received

Thank you!
Now works everything as supposed to!
Sinuhet

Reply With Quote
The following user says Thank You to Sinuhet for this post:
 
  #7 (permalink)
Elite Member
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,260 since Apr 2013
Thanks: 201 given, 711 received

Sinuhet,

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

Regards,

ABCTG

Reply With Quote

Reply



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

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)
 

Spring Grains Outlook w/Sean Lusk @ Walsh Trading

Elite only

FIO Video Journal Challenge featuring NinjaTrader ($2,000+ of prizes)

April

Process above all else w/Anthony Crudele @ Futures Radio Show

Elite only

Machine Learning - Quantitative Trading w/Martin Froehler @ Quantiacs

Elite only

Market Dynamics w/Peter Davies @ Jigsaw Trading

Elite only

Ask Me Anything w/Patrick Rooney @ Trading Technologies

Apr 18

Ask Me Anything w/FuturesTrader71

Apr 19

Machine Learning w/Kris Longmore

Elite only

Market Analysis w/Dave Forss

Apr 25

Introducing iSystems with Stage 5 Trading

Apr 27
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
highest bar close occuring within the last X number of bars . . . . jmejedi NinjaTrader Programming 37 October 6th, 2014 12:52 AM
Nested Loop zeller4 NinjaTrader Programming 2 May 28th, 2014 04:15 PM
Avoiding trading loop in script mcteague NinjaTrader Programming 5 December 28th, 2012 02:18 AM
OODA Loop and Trading...... tradersam Psychology and Money Management 1 May 18th, 2011 02:36 PM
foreach loop problem gomad NinjaTrader Programming 14 May 17th, 2011 07:40 PM


All times are GMT -4. The time now is 05:47 PM.

no new posts
Page generated 2017-03-28 in 0.10 seconds with 20 queries on phoenix via your IP 54.205.60.171