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 2,102 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread
  #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: 535

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?
Iran Airspace Collapses 18 Points to 15.5% While Hormuz …
Prediction Markets & Event Contracts
Sundays Verdict: Lebanon Locked at 99.85% as Iran June 7 …
Prediction Markets & Event Contracts
April CPI Preview: +3.7% YoY Expected at 8:30 AM ET -- C …
Traders Hideout
Strike Pause Holds, Oil Erases Monday Spike -- May CPI W …
Traders Hideout
Iran Peace Expired NO: Ceasefire on Life Support, OPEC a …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
13 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 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: 535


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


© 2026 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 - Downloads - Top
no new posts