NexusFi: Find Your Edge


Home Menu

 





Question with arrays in MultiCharts


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one insideday with 2 posts (7 thanks)
    2. looks_two Xyzzy with 2 posts (2 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 crazybears with 1 posts (2 thanks)
    1. trending_up 7,248 views
    2. thumb_up 11 thanks given
    3. group 3 followers
    1. forum 5 posts
    2. attach_file 2 attachments




 
Search this Thread

Question with arrays in MultiCharts

(login for full post details)
  #1 (permalink)
 Xyzzy 
Seattle, WA
 
Experience: Advanced
Platform: MultiCharts
Broker: IB/IQFeed
Trading: ES
Posts: 24 since Dec 2010
Thanks Given: 27
Thanks Received: 22

Hi all,

I apologize in advance for a newbie question -- I have a C# background, but I'm just getting started with MultiCharts/EasyLanguage.

I'm trying to create a modified version of the built-in "Mov Av Exp Ribbon" indicator. I've defined a numeric array of eight elements called "XAvg." The program then assigns each element an exponential moving average of a different length based on the inputs "Price" and "Length," and then plots the contents of that array.

This code works fine, and gives me the results I expect:

 
Code
XAvg[1] = XAverage( Price, Length ) ;
XAvg[2] = XAverage( Price, Length * 2 ) ;
XAvg[3] = XAverage( Price, Length * 3 ) ;
XAvg[4] = XAverage( Price, Length * 4 ) ;
XAvg[5] = XAverage( Price, Length * 5 ) ;
XAvg[6] = XAverage( Price, Length * 6 ) ;
XAvg[7] = XAverage( Price, Length * 7 ) ;
XAvg[8] = XAverage( Price, Length * 8 ) ;
However, I tried to shorten the block of array-assignment code with a for loop, below. When I comment out that code and use the for loop instead, I get completely different and unpredicted results.

 
Code
for index = 1 to 8 begin 
	XAvg[ index ] = XAverage( Price, Length * index ) ;
end;
At least in C#, the comparable code for these two blocks of code are equivalent and would give the same results. However, they don't seem to be working that way here. In particular, in the "for loop" code, it looks like XAvg[1] to AXvg[8] are each getting assigned the same value (i.e., the same moving average), rather than different moving averages. Consequently, I'm not seeing a ribbon effect plotted on the graph, but just eight lines that all have the same value.

Is there some difference here that I'm missing between these two blocks of code? Perhaps is there some difference in the way that the XAverage function is being called, or that results from that function are getting assigned to the array elements? I'm stumped. Many thanks.

Attached Files
Register to download File Type: pla Xyzzy Mov Avg Exp Ribbon.pla (6.2 KB, 18 views)
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
News alerts
Traders Hideout
Request for MACD with option to use different MAs for fa …
NinjaTrader
Searching for CurrentMonthOHL Indicator
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Trader Dale [email protected] or Scammer Dale
Trading Reviews and Vendors
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Tao te Trade: way of the WLD
37 thanks
Deaddogs Stock Trading
27 thanks
GFIs1 1 DAX trade per day journal
26 thanks
Supertradersams Thread Journal on NQ/MNQ
24 thanks
Leaving CFD trading and learning futures
10 thanks

(login for full post details)
  #3 (permalink)
 crazybears 
Alesia E.U.
 
Experience: Intermediate
Platform: Sierra chart
Trading: Futures
Posts: 168 since Feb 2011
Thanks Given: 146
Thanks Received: 115


Hi
maybe i didn't understand well your question , but if you use
 
Code
XAvg[8] = XAverage( Price, Length * 8 ) ;
you use a prebuilt function of MC as array. is not possible( i think)
try this code
 
Code
Inputs:Length(3),price(close); 
variables:index(0),cont(0);
array:a1[7](0);
cont=1;
for index = 0 to 7 begin 
 a1[ index ] = XAverage( Price, Length * cont ) ;
 cont=cont+1;
end;
plot1(a1[ 0 ]);plot2(a1[ 7 ]);plot3(a1[ 1 ]);plot2(a1[ 6 ]);

Reply With Quote
The following 2 users say Thank You to crazybears for this post:
(login for full post details)
  #4 (permalink)
insideday
vienna
 
Posts: 22 since Aug 2009
Thanks Given: 0
Thanks Received: 38

Series functions will return incorrect results if called within loop, last Point 7
Best Practice for working with Functions

at

https://www.tradestation.com:443/wiki/display/EasyLanguage/Understanding+Functions

Reply With Quote
(login for full post details)
  #5 (permalink)
 Xyzzy 
Seattle, WA
 
Experience: Advanced
Platform: MultiCharts
Broker: IB/IQFeed
Trading: ES
Posts: 24 since Dec 2010
Thanks Given: 27
Thanks Received: 22

Thanks everyone. Insideday, I can't access the link, which might be caused by my not having a TradeStation account. (I'm using MultiCharts instead.)

Regardless, I found a post here that describes the source of my problem. Specifically, there's some bad juju with using recursive functions within a For... next loop.

http://jurikres.com/down/Some Programming Issues in Easy Language.pdf

I'm still trying to figure out the subtleties of EasyLanguage programming, but for now the short answer seems to be don't use loops for situations like this. It makes the code a bit less elegant, but oh well.

Started this thread Reply With Quote
The following 2 users say Thank You to Xyzzy for this post:
(login for full post details)
  #6 (permalink)
insideday
vienna
 
Posts: 22 since Aug 2009
Thanks Given: 0
Thanks Received: 38

Best Practice for working with Functions

Attached Thumbnails
Click image for larger version

Name:	Best Practice for working with Functions.jpg
Views:	499
Size:	138.7 KB
ID:	33723  
Reply With Quote





Last Updated on March 14, 2011


© 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