NexusFi: Find Your Edge


Home Menu

 





Convert TradeStation XAverage function to Sierra code


Discussion in Sierra Chart

Updated
      Top Posters
    1. looks_one Renko123 with 11 posts (0 thanks)
    2. looks_two ehlaban with 3 posts (2 thanks)
    3. looks_3 Big Mike with 1 posts (0 thanks)
    4. looks_4 crazybears with 1 posts (0 thanks)
    1. trending_up 4,774 views
    2. thumb_up 2 thanks given
    3. group 4 followers
    1. forum 15 posts
    2. attach_file 0 attachments




 
Search this Thread

Convert TradeStation XAverage function to Sierra code

  #1 (permalink)
Renko123
Washington, DC USA
 
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6

Could someone be so kind as to convert this tradestation function over to a Sierra function?
Thanks in advance.

 
Code
inputs: 
	Price( numericseries ), { price to average }
	Length( numericsimple ) ; { this input must be a constant >= 0 }

variables: 
	intrabarpersist SmoothingFactor( 0 ) ;

once
	begin
	if Length >= 0 then
		SmoothingFactor =  2 / ( Length + 1 )
	else
		RaiseRuntimeError( "The Length input of the XAverage function must be " +
		 "greater than or equal to 0." ) ;
	end ;
	
if CurrentBar = 1 then
	XAverage = Price
else
	XAverage = XAverage[1] + SmoothingFactor * ( Price - XAverage[1] ) ;

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Futures True Range Report
The Elite Circle
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Are there any eval firms that allow you to sink to your …
Traders Hideout
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
25 thanks
The Program
20 thanks
GFIs1 1 DAX trade per day journal
19 thanks
  #2 (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,399 since Jun 2009
Thanks Given: 33,173
Thanks Received: 101,538

Isn't XAverage just an EMA? It's built-in to Sierra as Exponential Moving Average under Moving Averages.

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 Reply With Quote
  #3 (permalink)
Renko123
Washington, DC USA
 
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6


The entire code i posted is the XAverage function itself.
I have no idea if its an Exponential Moving Average or not.
If the sierra Exponential Moving Average returns the exact same value with the same given input then i guess that would work.
However the the function appears to call itself at least twice with its previous value XAverage [1]
and I have no idea how to do that.


Big Mike View Post
Isn't XAverage just an EMA? It's built-in to Sierra as Exponential Moving Average under Moving Averages.

Mike


Reply With Quote
  #4 (permalink)
 crazybears 
Alesia E.U.
 
Experience: Intermediate
Platform: Sierra chart
Trading: Futures
Posts: 168 since Feb 2011
Thanks Given: 146
Thanks Received: 115

Hi

ACSIL Interface Members - Functions - Sierra Chart

XAverage (Function)

Reply With Quote
  #5 (permalink)
Renko123
Washington, DC USA
 
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6

The SC sc.ExponentialMovAvg() takes in arrays and spits out arrays.
The Tradestation XAverage function does not appear to deal with arrays.
As my calling code in my TS indicator is:

Var1 = (HIGH[2] - LOW[4]) ; //one single value not array
Var2 = HIGH - Var1 ; // one single value not array
Var4 = XAverage (Var2, 6) ; // XAverage returns one single value not an array

I`m guessing that converting the Tradestation function to a SC function must be a very difficult task, since no one has tried.

If someone could take 60 seconds to post a custom created function as a sample template and tell me in where or what file i need to place it in to be able to call it from my indicator code.
I will tackle the difficult task of converting the XAverage to SC code.

Reply With Quote
  #6 (permalink)
 ehlaban 
Netherlands
 
Experience: Advanced
Platform: Ensign, Multicharts
Trading: SP500
Posts: 91 since Nov 2009
Thanks Given: 66
Thanks Received: 57

I'm no easy language expert but think you are wrong. Almost everything is an array in easy language.

Var4 is also an array and i think you can read former value by Var4[3] etc

Regardless if i look at the XAverage (Function)

I see the line XAverage = XAverage[1] + var0 * ( PriceValue - XAverage[1] ) ;

it references a back value in the input array: XAverage[1] and that shouldn't be possible if the input was only a number

 
Code
SCSubgraphRef 	Renko123 = sc.Subgraph[0];

SCFloatArrayRef Var1 = Renko123.Arrays[0];
SCFloatArrayRef Var2 = Renko123.Arrays[1];
SCFloatArrayRef Var4 = Renko123.Arrays[2];

Var1[sc.Index] = sc.BaseDataIn[SC_HIGH][2] - sc.BaseDataIn[SC_LOW][4];
Var2[sc.Index] = sc.BaseDataIn[SC_HIGH][sc.Index] - Var1[sc.Index];
sc.MovingAverage(Var2, Var4, MOVAVGTYPE_EXPONENTIAL, 6);

Renko123[sc.Index] = Var4[sc.Index];

Reply With Quote
  #7 (permalink)
Renko123
Washington, DC USA
 
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6

In Tradestation if I want a variable.
Variables: Var4(1) ;
Var4 = 1;

If I want to create an Array in Tradestation.
Array: int Var4[2];
Var4[0] = 1
Var4[1] = 2

If tradestation is converting a single created variable into a one dimensional array behind the scenes then i didn't know about that.
I tried to use Var4 as an input to the sc.ExponentialMovAvg and it chocked since Var4 wasn't a manual created array.

Thanks for the code you posted, but it isn't in in the form of a callable function since the XAverage function even calls itself several times.

The code i previous posted is the entire XAverage function itself and i need the converted code to be in the form of a function.
Since I will need to call the converted function several times in my current indicator code and future indicators I need to convert to SC

Thanks again.


ehlaban View Post
I'm no easy language expert but think you are wrong. Almost everything is an array in easy language.

Var4 is also an array and i think you can read former value by Var4[3] etc

Regardless if i look at the XAverage (Function)

I see the line XAverage = XAverage[1] + var0 * ( PriceValue - XAverage[1] ) ;

it references a back value in the input array: XAverage[1] and that shouldn't be possible if the input was only a number

 
Code
SCSubgraphRef 	Renko123 = sc.Subgraph[0];

SCFloatArrayRef Var1 = Renko123.Arrays[0];
SCFloatArrayRef Var2 = Renko123.Arrays[1];
SCFloatArrayRef Var4 = Renko123.Arrays[2];

Var1[sc.Index] = sc.BaseDataIn[SC_HIGH][2] - sc.BaseDataIn[SC_LOW][4];
Var2[sc.Index] = sc.BaseDataIn[SC_HIGH][sc.Index] - Var1[sc.Index];
sc.MovingAverage(Var2, Var4, MOVAVGTYPE_EXPONENTIAL, 6);

Renko123[sc.Index] = Var4[sc.Index];


Reply With Quote
  #8 (permalink)
Renko123
Washington, DC USA
 
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6

Do anyone know how to create a SC function that takes 2 inputs an array and an Integer?
Also what file do I place the function in to be able to call it via a indicator or another function?

Reply With Quote
  #9 (permalink)
 ehlaban 
Netherlands
 
Experience: Advanced
Platform: Ensign, Multicharts
Trading: SP500
Posts: 91 since Nov 2009
Thanks Given: 66
Thanks Received: 57

Place the function before the Sierra Chart function call: SCSFExport scsf_MyFunction(SCStudyInterfaceRef sc)
just like the example in the link below.


float Renko123function(float data[], int ndata)
{
float x = a * b;

return x;
}

Sierra Chart
Functions - C++ Tutorials

Reply With Quote
Thanked by:
  #10 (permalink)
Renko123
Washington, DC USA
 
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6


Thanks.


ehlaban View Post
Place the function before the Sierra Chart function call: SCSFExport scsf_MyFunction(SCStudyInterfaceRef sc)
just like the example in the link below.


float Renko123function(float data[], int ndata)
{
float x = a * b;

return x;
}

Sierra Chart
Functions - C++ Tutorials


Reply With Quote




Last Updated on April 5, 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