NexusFi: Find Your Edge


Home Menu

 





Passing array to function such as average or RSI?


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one maisatomai with 3 posts (0 thanks)
    2. looks_two ABCTG with 3 posts (0 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 shodson with 1 posts (0 thanks)
    1. trending_up 4,155 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 7 posts
    2. attach_file 0 attachments




 
Search this Thread

Passing array to function such as average or RSI?

  #1 (permalink)
maisatomai
Singapore
 
Posts: 3 since Apr 2014
Thanks Given: 0
Thanks Received: 0

 
Code
Hivalue10=average(HighDaily[0],2); 
value11=(HighDaily[0]+HighDaily[1])/2;
This works as value10 has same value as value11

 
Code
value10=average(HighDaily[0],3); 
value11=(HighDaily[0]+HighDaily[1]+HighDaily[2])/3;
This don't work as value10 has different value as value11

HighDaily is of type Array. Anyone know why and how can I fix it? I hope to convert array into a PriceSeries as I suspect we need to pass PriceSeries into average for it to work well. I need this to work as I need it to use on other functions like RSI

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
The choice of instruments to trade
Psychology and Money Management
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
MC PL editor upgrade
MultiCharts
Better Renko Gaps
The Elite Circle
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
31 thanks
My NQ Trading Journal
21 thanks
Just another trading journal: PA, Wyckoff & Trends
17 thanks
Tao te Trade: way of the WLD
13 thanks
Daytrading ES & NQ
9 thanks
  #3 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709


instead of

 
Code
value10=average(HighDaily[0],3);
I think you should try

 
Code
value10=average(HighDaily,3);
If you call average on HighDaily[0] it's just averaging 1 value I suppose. I'm not a EL programmer but either way it just doesn't look right.

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

maisatomai,

in my opinion it's just a coincidence that your first example gives the correct result.

 
Code
Arrays:
	HighDaily[2]	(0);
	
once 
begin
	HighDaily[0] = 100 ;
	HighDaily[1] = 200 ;	
	HighDaily[2] = 300 ;
	
	Value1 = Average(HighDaily[0],2); 
	Value2 = (HighDaily[0]+HighDaily[1])/2;
	
	Print("Value1: ", Value1, "; Value2: ", Value2);

end;
The output looks like this: Value1: 50.00; Value2: 150.00

This example also demonstrates why what you are trying doesn't work, the functions don't cycle through your arrays, but reference the previous bar's value for the same position in the array.

You can pass arrays to functions, but you'd need to rewrite those functions to handle the array properly.

Regards,
ABCTG





maisatomai View Post
 
Code
Hivalue10=average(HighDaily[0],2); 
value11=(HighDaily[0]+HighDaily[1])/2;
This works as value10 has same value as value11

 
Code
value10=average(HighDaily[0],3); 
value11=(HighDaily[0]+HighDaily[1]+HighDaily[2])/3;
This don't work as value10 has different value as value11

HighDaily is of type Array. Anyone know why and how can I fix it? I hope to convert array into a PriceSeries as I suspect we need to pass PriceSeries into average for it to work well. I need this to work as I need it to use on other functions like RSI


Follow me on Twitter Reply With Quote
  #5 (permalink)
maisatomai
Singapore
 
Posts: 3 since Apr 2014
Thanks Given: 0
Thanks Received: 0

@ABCTG

I understand what you mean. So is there any way I can pass my array into default function such as RSI and average? Or must I write my own RSI as RSI seems to take in NumericSeries and Array is NumericSimple

Reply With Quote
  #6 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

maisatomai,

in my opinion you'll have to rewrite/adapt the functions.

Regards,
ABCTG

Follow me on Twitter Reply With Quote
  #7 (permalink)
maisatomai
Singapore
 
Posts: 3 since Apr 2014
Thanks Given: 0
Thanks Received: 0


ABCTG View Post
maisatomai,

in my opinion you'll have to rewrite/adapt the functions.

Regards,
ABCTG

thanks a lot for your help

Reply With Quote
  #8 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

maisatomai,

you are welcome. In case you run into any issues with the rewrite, just post back here and I am sure someone is able to steer you into the right direction.

Regards,
ABCTG

Follow me on Twitter Reply With Quote




Last Updated on April 24, 2014


© 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