Tradestation Easy Language: XAverage when using Price Series Provider

if you are using PSP, the XAverage function will not work as the value will be reference to the Data1 chart. Therefore you will need another function to input numeric series of the PSP data to calculate the XAverage.

Below are the function you may create named XAveragePSP

{  
This function calculates XAverage for non-chart data series (i.e., Price Series Providers).  The delivered XAverage only handles chart data.  
}  
  
Using tsdata.marketdata;  
 
XAveragePSP = 0;  
  
Inputs:   
	PriceSeriesProvider PSP(objectref), {Reference to a Price Series Provider}  
	Length(numericsimple) ; {this input must be a constant >= 0}  
  
Variables:   
	IntrabarPersist SmoothingFactor(0),  
	IntrabarPersist PriorXAvg(0),  
	IntrabarPersist CurrentXAvg(0),  
	IntrabarPersist Cnt(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 ;  
  
Begin  
    For Cnt = PSP.Count - 1 DownTo 0   
    	Begin   
  			If cnt = PSP.Count - 1 Then  
  				Begin  
  					PriorXAvg = PSP.Close[Cnt];  
  					CurrentXAvg = PriorXAvg;  
	  			End  
  			Else  
  				Begin  
  					CurrentXAvg = PriorXAvg + SmoothingFactor * (PSP.Close[Cnt] - PriorXAvg);  
  					PriorXAvg = CurrentXAvg;  
  			end;   
 		End;  
	XAveragePSP = CurrentXAvg;  
End;

DISCLAIMER – READ ME!

THESE INDICATORS, SHOW ME STUDIES, STRATEGIES AND OTHER PROGRAMS / ALGORITHMS HAVE BEEN INCLUDED SOLELY FOR EDUCATIONAL PURPOSES.

NIK IZWAN KAMEL ASSUMES NO LIABILITY FOR ANY DAMAGES, DIRECT OR OTHERWISE, RESULTING FROM THE USE OF THIS INFORMATION AND/OR PROGRAM(S) DESCRIBED, AND NO WARRANTY IS MADE REGARDING ITS ACCURACY OR COMPLETENESS. USE OF THIS INFORMATION AND/OR PROGRAMS DESCRIBED IS AT YOUR OWN RISK.

TradeStation®, EasyLanguage® and PowerEditor® are registered trademarks of TradeStation Technologies, Inc. Other brand and product names which appear on this site such as AmiBroker® and MultiCharts® are the trademarks or service marks of their respective owners.  Microsoft® is a registered trademark in the United States Microsoft®Excel® is a registered trademark of Microsoft® Neither TradeStation Technologies nor any of its affiliates has reviewed, certified, endorsed, approved, disapproved or recommended, and neither does or will review, certify, endorse, approve, disapprove or recommend, any product or service that offers training, education or consulting regarding the use of EasyLanguage.  AmiBroker nor any of its affiliates has reviewed, certified, endorsed, approved, disapproved or recommended, and neither does or will review, certify, endorse, approve, disapprove or recommend, any product or service that offers training, education or consulting regarding the use of its proprietary AmiBroker Formula Language. MultiCharts nor any of its affiliates has reviewed, certified, endorsed, approved, disapproved or recommended, and neither does or will review, certify, endorse, approve, disapprove or recommend, any product or service that offers training, education or consulting regarding the use of its PowerLanguage. 

Nik Izwan Kamel is an Entrepreneur who venture in multiple businesses in different industries including IT, Blockchain, E-Commerce, Security, Retail and F&B. A cryptocurrency enthusiast and cooking computer codes at night.

Leave a reply:

Your email address will not be published.

Site Footer