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,854 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

  #11 (permalink)
Renko123
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] );
 

	  }

}

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
REcommedations for programming help
Sierra Chart
ZombieSqueeze
Platforms and Indicators
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #12 (permalink)
Renko123
Washington, DC USA
 
Posts: 64 since Nov 2013
Thanks Given: 12
Thanks Received: 6


Renko123 View Post

// 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.

Reply With Quote
  #13 (permalink)
 ehlaban 
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;
}

Reply With Quote
Thanked by:
  #14 (permalink)
Renko123
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];
	                }
}

Reply With Quote
  #15 (permalink)
Renko123
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 ;
                         }
	
}

Reply With Quote
  #16 (permalink)
Renko123
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 View Post
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 ;
                         }
	
}


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