NexusFi: Find Your Edge


Home Menu

 





XAverage array in EasyLanguage


Discussion in EasyLanguage Programming

Updated
      Top Posters
    1. looks_one Big Mike with 6 posts (0 thanks)
    2. looks_two ValutaTrader with 5 posts (2 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 dnsarkis with 1 posts (0 thanks)
    1. trending_up 9,454 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 13 posts
    2. attach_file 0 attachments




 
Search this Thread

XAverage array in EasyLanguage

  #1 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,444 since Jun 2009
Thanks Given: 33,217
Thanks Received: 101,608

Anyone have some helpful code for XAverage of an array in EasyLanguage?

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Exit Strategy
NinjaTrader
ZombieSqueeze
Platforms and Indicators
REcommedations for programming help
Sierra Chart
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
33 thanks
Just another trading journal: PA, Wyckoff & Trends
28 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
21 thanks
  #3 (permalink)
 
ValutaTrader's Avatar
 ValutaTrader 
Oslo,Norway
 
Experience: Intermediate
Platform: NinjaTrader
Trading: EUR/USD
Posts: 66 since Apr 2011
Thanks Given: 4
Thanks Received: 52


I think this is close to what you are looking for (function XAverage_a). I am struggling myself to come to terms with the syntax of EasyLanguage, while trying to implement the QQE indicator, so please test it to see if you are comfortable with the result compared to the ordinary EMA

inputs:
PriceValue[M](numericArrayRef),
Len( numericsimple ) ;

variables:
factor( 2 / ( Len + 1 ) ) ;
if CurrentBar = 1 then
XAverage_a = PriceValue[M]
else
XAverage_a = XAverage_a[1] + factor * ( PriceValue[1] - XAverage_a[1] ) ;

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
 
ValutaTrader's Avatar
 ValutaTrader 
Oslo,Norway
 
Experience: Intermediate
Platform: NinjaTrader
Trading: EUR/USD
Posts: 66 since Apr 2011
Thanks Given: 4
Thanks Received: 52

I created a test myself, and I am disappointed to see that they are not 100% identical. The code is based on XAverage, and I cannot yet see where the small difference come from, but it is slightly different. Perhaps I will know when I have gained more experience with EasyLanguage myself.
Here is the indicator used to compare the two

inputs:
Price( Close ),
Value1Color( green ),
Value2Color( Yellow ) ;
Arrays:
buffer[100](0);
variables:
emaNormal( 0 ), j(0) , emaArr(0);

emaNormal=XAverage(Price,13);

For j=0 to 99
begin
buffer[j]=Price[j];
end;

emaArr=XAverage_a(buffer,13);

Plot1( emaNormal[0], "EMA normal" ) ;
Plot2( emaArr[0], "EMA array" ) ;

SetPlotColor( 1, Value1Color);
SetPlotColor( 2, Value2Color);

Follow me on Twitter Reply With Quote
  #5 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,444 since Jun 2009
Thanks Given: 33,217
Thanks Received: 101,608


ValutaTrader View Post
I think this is close to what you are looking for (function XAverage_a). I am struggling myself to come to terms with the syntax of EasyLanguage, while trying to implement the QQE indicator, so please test it to see if you are comfortable with the result compared to the ordinary EMA

inputs:
PriceValue[M](numericArrayRef),
Len( numericsimple ) ;

variables:
factor( 2 / ( Len + 1 ) ) ;
if CurrentBar = 1 then
XAverage_a = PriceValue[M]
else
XAverage_a = XAverage_a[1] + factor * ( PriceValue[1] - XAverage_a[1] ) ;

I tried this at first glance, too. But I think the problem is that the XAverage code is looking at the previous value in the dataseries [1], whereas when you use the array it is incremented so that the most recent value is not [0] or [1] but is instead the currentbar number.

So you would need to inverse the array, or the XAverage math, and this is where I got stuck.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #6 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,444 since Jun 2009
Thanks Given: 33,217
Thanks Received: 101,608

This code works, but it is painfully slow.

 
Code
// function
inputs:
PriceValue[M](numericArrayRef),
Len( numericsimple ) ;

variables:
factor( 2 / ( Len + 1 ) ) ;
if CurrentBar = 1 then
XAverage_Array = PriceValue[M]
else
XAverage_Array = XAverage_Array[1] + factor * ( PriceValue[Array_GetMaxIndex(PriceValue)-1] - XAverage_Array[1] ) ;
It matches the built-in XAverage EMA. But it is unusable because it is so slow.

The small change is:
PriceValue[Array_GetMaxIndex(PriceValue)-1]

I also tried creating a new array and just copying the last 'length' into it, but because this happens on every new bar, it is equally as slow. The issue seems to be moving to the end of array backwards.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #7 (permalink)
 
ValutaTrader's Avatar
 ValutaTrader 
Oslo,Norway
 
Experience: Intermediate
Platform: NinjaTrader
Trading: EUR/USD
Posts: 66 since Apr 2011
Thanks Given: 4
Thanks Received: 52

Played around with it, and referring to index 0 of price seems to do the trick. Not sure why though

XAverage_a = XAverage_a[1] + factor * ( PriceValue[0] - XAverage_a[1] ) ;

Follow me on Twitter Reply With Quote
  #8 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,444 since Jun 2009
Thanks Given: 33,217
Thanks Received: 101,608


ValutaTrader View Post
Played around with it, and referring to index 0 of price seems to do the trick. Not sure why though

XAverage_a = XAverage_a[1] + factor * ( PriceValue[0] - XAverage_a[1] ) ;

Not for me, that produced very wrong results.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #9 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,444 since Jun 2009
Thanks Given: 33,217
Thanks Received: 101,608

If your array size matches the currentbar figure, you could skip the Array_GetMaxIndex() function and just use currentbar, it is faster - but still somewhat slow.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #10 (permalink)
 
ValutaTrader's Avatar
 ValutaTrader 
Oslo,Norway
 
Experience: Intermediate
Platform: NinjaTrader
Trading: EUR/USD
Posts: 66 since Apr 2011
Thanks Given: 4
Thanks Received: 52


Ok, I see why we got different results. Your function did not give the correct result on my side, and it is because the array that I tested with had the last price in index 0 and not the other way around. Not sure how to speed up the lookup of the last/max index when the data is stored the other way around.

Follow me on Twitter Reply With Quote




Last Updated on December 16, 2015


© 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