Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Convert TradeStation XAverage function to Sierra code
Updated April 5, 2015
Top Posters
looks_one
Renko123
with 11 posts (0 thanks)
looks_two
ehlaban
with 3 posts (2 thanks)
looks_3
Big Mike
with 1 posts (0 thanks)
looks_4
crazybears
with 1 posts (0 thanks)
trending_up
4,982 views
thumb_up
2 thanks given
group
4 followers
forum
15 posts
attach_file
0 attachments
Convert TradeStation XAverage function to Sierra code
March 23rd, 2015, 05:19 PM
Washington, DC USA
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6
My task now is to get the function to be able to call itself.
This is what i have so far.
Need help with the code section in the red font.
Anyone?
Code
float XAverge(SCStudyInterfaceRef sc,SCFloatArrayRef Arraydata, SCFloatArrayRef Arraydata2, int ndata)
{
float SmoothingFactor = 0;
if (ndata >= 0)
{
SmoothingFactor = 2 / ( ndata + 1 );
}
if (sc.Index == 1)
{
sc.ExponentialMovAvg(Arraydata, Arraydata2, ndata);
return Arraydata2[sc.Index];
}
else
{
//XAverage = XAverage[1] + SmoothingFactor * ( Price - XAverage[1] ) ;//recursive call inside the TS version
// does not work gives an error "expression must have pointer- to- object type" need help with the following line
return XAverge(sc, Arraydata , Arraydata2, ndata)[sc.Index - 1] + SmoothingFactor * ( Arraydata[sc.Index] - XAverge(sc, Arraydata, Arraydata2, ndata)[sc.Index - 1] );
}
}
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
March 27th, 2015, 12:25 PM
Washington, DC USA
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6
Renko123
// does not work gives an error "expression must have pointer- to- object type" need help with the following line
return XAverge(sc, Arraydata , Arraydata2, ndata)[sc.Index - 1] + SmoothingFactor * ( Arraydata[sc.Index] - XAverge(sc, Arraydata, Arraydata2, ndata)[sc.Index - 1] );
Guess that line of code not working has got the pro`s here out of ideas also.
March 27th, 2015, 04:13 PM
Netherlands
Experience: Advanced
Platform: Ensign, Multicharts
Trading: SP500
Posts: 91 since Nov 2009
Thanks Given: 66
Thanks Received: 57
Something like this:
Code
SCFloatArrayRef XAverage(SCFloatArrayRef In, SCFloatArrayRef Out, int Index, int Length)
{
float SmoothingFactor = 0;
if (Index >= In.GetArraySize())
return Out;
if (Index < 1 || Length < 1)
return Out;
if (Index < Length - 1)
Length = Index + 1;
if (Length >= 0)
SmoothingFactor = 2 / (Length + 1);
if (Index < 1)
Out[Index] = In[Index];
else
Out[Index] = Out[Index - 1] + SmoothingFactor * (In[Index] - Out[Index - 1]);
return Out;
}
March 29th, 2015, 09:23 PM
Washington, DC USA
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6
Thanks ehlaban .
Got the function working and returning the correct value.
Here is the completed function for anyone in the future who may need it for a conversion from tradestation EL.
Code
float XAverge(SCStudyInterfaceRef sc,SCFloatArrayRef Arraydata, SCFloatArrayRef Arraydata2, int ndata)
{
float SmoothingFactor = 0;
if (ndata >= 0)
{
SmoothingFactor = 2 / ( ndata + 1 );
}
if (sc.Index == 1)
{
return Arraydata[sc.Index];
}
else
{
sc.ExponentialMovAvg(Arraydata, Arraydata2, ndata);
Arraydata2[sc.Index ] = Arraydata2[sc.Index - 1] + SmoothingFactor * (Arraydata[sc.Index] - Arraydata2[sc.Index- 1]);
return Arraydata2[sc.Index];
}
}
March 29th, 2015, 09:39 PM
Washington, DC USA
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6
Now that the TS XAverge function is converted to SC.
I have a custom TS function that calls the XAverge function and need help with how to call the XAverge function multiple times in one line of code.
Code
float TrendCalu(SCStudyInterfaceRef sc,SCFloatArrayRef Arraydata, SCFloatArrayRef Arraydata2, int ndata)
{
//Variables: Var1(0.0); //tradestation code for a variable
float array1[1]; // create array to replace the simple TS variable
// Var1 = XAverage (XAverage (XAverage (Log (Price), Length), Length), Length) ;// the original TS XAverge calls
array1[1] = log(Arraydata[sc.Index]);//pulled out the log function and did the cal separate
//the follow code line below is what i need help with. Compile errors.
Arraydata2[sc.Index] = XAverge(sc,XAverge(sc,XAverge(sc,array1[1],Arraydata2,ndata),Arraydata2,ndata),Arraydata2,ndata);
return Arraydata2[sc.Index];
if (sc.Index > 1.0)
{
return Arraydata2[sc.Index] = (Arraydata[sc.Index] - Arraydata2[sc.Index- 1]) * 10000.0 ;
}
}
April 5th, 2015, 03:32 PM
Washington, DC USA
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6
Did the line of code not working, finally get the best of the pro`s ?
Renko123
Now that the TS XAverge function is converted to SC.
I have a custom TS function that calls the XAverge function and need help with how to call the XAverge function multiple times in one line of code.
Code
float TrendCalu(SCStudyInterfaceRef sc,SCFloatArrayRef Arraydata, SCFloatArrayRef Arraydata2, int ndata)
{
//Variables: Var1(0.0); //tradestation code for a variable
float array1[1]; // create array to replace the simple TS variable
// Var1 = XAverage (XAverage (XAverage (Log (Price), Length), Length), Length) ;// the original TS XAverge calls
array1[1] = log(Arraydata[sc.Index]);//pulled out the log function and did the cal separate
//the follow code line below is what i need help with. Compile errors.
Arraydata2[sc.Index] = XAverge(sc,XAverge(sc,XAverge(sc,array1[1],Arraydata2,ndata),Arraydata2,ndata),Arraydata2,ndata);
return Arraydata2[sc.Index];
if (sc.Index > 1.0)
{
return Arraydata2[sc.Index] = (Arraydata[sc.Index] - Arraydata2[sc.Index- 1]) * 10000.0 ;
}
}
Last Updated on April 5, 2015