NexusFi: Find Your Edge


Home Menu

 





Moving average- Absolute


Discussion in Sierra Chart

Updated
      Top Posters
    1. looks_one yonatan with 2 posts (1 thanks)
    2. looks_two Neo1 with 2 posts (1 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 mkata with 1 posts (1 thanks)
    1. trending_up 1,246 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread

Moving average- Absolute

  #1 (permalink)
 
Neo1's Avatar
 Neo1 
Christchurch, New Zealand
 
Experience: Beginner
Platform: SC
Broker: IB, BC, Dx Feed
Trading: US Equities
Posts: 428 since Jul 2014
Thanks Given: 471
Thanks Received: 531

I want to return the absolute value of a moving average, so based on a length of "1", input values -1,-2, 3, 4 = 10

I know I need to include the math.h library, and use the fabs() function. When I adjust the code and try to implement fabs() I end up with compiler errors. Can someone please show me how this should be implemented.

Here is the basic code without using fabs().

 
Code
// Test
#include "sierrachart.h"
#include "math.h"

SCDLLName("MABS")
   
SCSFExport scsf_MovingAverageSimple(SCStudyInterfaceRef sc)
{
	SCSubgraphRef Avg = sc.Subgraph[0];

	SCInputRef InputData = sc.Input[0];
	SCInputRef Length = sc.Input[3];

	if (sc.SetDefaults)
	{
		sc.GraphName = "Moving Average - ABS";

		sc.GraphRegion = 0;
		sc.ValueFormat = 2;
		sc.AutoLoop = 1;

		Avg.Name = "Avg";
		Avg.DrawStyle = DRAWSTYLE_LINE;
		Avg.PrimaryColor = RGB(0, 255, 0);
		Avg.LineWidth = 1;
		Avg.DrawZeros = true;

		InputData.Name = "Input Data";
		InputData.SetInputDataIndex(SC_LAST);

		Length.Name = "Length";
		Length.SetInt(10);
		Length.SetIntLimits(1, MAX_STUDY_LENGTH);
		
		sc.FreeDLL = 0;

		return;
	}

		sc.DataStartIndex = Length.GetInt() - 1;

		sc.SimpleMovAvg(sc.BaseDataIn[InputData.GetInputDataIndex()], Avg,  Length.GetInt());
}

"Free markets work because they allow people to be lucky, thanks to aggressive trial and error, not by giving rewards or incentives for skill. The strategy is, then, to tinker as much as possible and try to collect as many Black Swan opportunities as you can"
Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Are there any eval firms that allow you to sink to your …
Traders Hideout
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Exit Strategy
NinjaTrader
Deepmoney LLM
Elite Quantitative GenAI/LLM
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
 
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
37 thanks
NexusFi site changelog and issues/problem reporting
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #3 (permalink)
 yonatan 
Haifa Israel
 
Experience: Beginner
Platform: sierra chart
Broker: Optimus Trading Group/Rithmic
Trading: es
Posts: 91 since Apr 2012
Thanks Given: 50
Thanks Received: 71


Are you aware that you are using sc.FreeDLL = 0 ?
This in itself can be the reason for the compiling problems.

Reply With Quote
  #4 (permalink)
 yonatan 
Haifa Israel
 
Experience: Beginner
Platform: sierra chart
Broker: Optimus Trading Group/Rithmic
Trading: es
Posts: 91 since Apr 2012
Thanks Given: 50
Thanks Received: 71

...also, in my studies I use fabs() without including math.h

Reply With Quote
Thanked by:
  #5 (permalink)
 mkata 
Columbus, OH
 
Experience: Intermediate
Platform: SierraChart
Trading: CL
Posts: 35 since May 2013
Thanks Given: 153
Thanks Received: 24

I think the following may be what your looking for:

To your existing code,
Add this:
SCSubgraphRef Temp1 = sc.Subgraph[1];

and Change the last line to This:

sc.SimpleMovAvg(sc.BaseDataIn[InputData.GetInputDataIndex()], Temp1, Length.GetInt());
Avg[sc.Index] = fabs(Temp1[sc.Index]);

Reply With Quote
Thanked by:
  #6 (permalink)
 
Neo1's Avatar
 Neo1 
Christchurch, New Zealand
 
Experience: Beginner
Platform: SC
Broker: IB, BC, Dx Feed
Trading: US Equities
Posts: 428 since Jul 2014
Thanks Given: 471
Thanks Received: 531


mkata View Post
I think the following may be what your looking for:

To your existing code,
Add this:
SCSubgraphRef Temp1 = sc.Subgraph[1];

and Change the last line to This:

sc.SimpleMovAvg(sc.BaseDataIn[InputData.GetInputDataIndex()], Temp1, Length.GetInt());
Avg[sc.Index] = fabs(Temp1[sc.Index]);

Nice one @mkata, you nailed it. Thanks.

"Free markets work because they allow people to be lucky, thanks to aggressive trial and error, not by giving rewards or incentives for skill. The strategy is, then, to tinker as much as possible and try to collect as many Black Swan opportunities as you can"
Started this thread Reply With Quote
Thanked by:




Last Updated on June 11, 2017


© 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