Login Page - Create Account

Support Board


Date/Time: Mon, 23 Dec 2024 15:54:19 +0000



having a problem with abs and plotting

View Count: 1099

[2015-10-07 22:35:26]
KhaosTrader - Posts: 128
Hi,

Having a problem getting this code to draw a line...


sc.ExponentialMovAvg(sc.Close, EMA_Medium, 50);
sc.ExponentialMovAvg(sc.Close, EMA_Long, 200);

float EMAMedium = EMA_Medium[sc.Index];
float EMALong = EMA_Long[sc.Index];
AvgDiff_100percent_Upper[sc.Index]= abs(EMAMedium - EMALong) ;

What am i doing wrong here? please...
[2015-10-08 01:41:20]
Sierra Chart Engineering - Posts: 104368
Debugging is your responsibility. You are in the best position to do this since you understand your own code, you are working with the code, and can see the results of it and can see results as you make changes.

All we can do is give you a debugging strategy. Simplify the study down to the absolute minimum.

Work with the studies that are provided in the /ACS_Source folder to see if you have the same problem. And gradually make changes and additions until the problem occurs to help you isolate the problem.

One thing to make sure is that the sc.Subgraph you are using for the final output has a visible DrawStyle.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2015-10-08 01:42:50
[2015-10-08 08:18:32]
KhaosTrader - Posts: 128
Hi,

I agree, that's a good idea to make a barebones study. So I have done that, and still have problem. Please let me know what I am doing wrong, or how to debug it...

Thank you in advance..

// test bed
SCSFExport scsf_JeffTest(SCStudyInterfaceRef sc)



{



SCSubgraphRef EMA_Medium = sc.Subgraph[2];
SCSubgraphRef EMA_Long = sc.Subgraph[3];

SCSubgraphRef MaxM_100percent_Upper= sc.Subgraph[6];




// Set configuration variables

if (sc.SetDefaults)

{

// Set the configuration and defaults
sc.GraphName = "Jeff Test";
sc.StudyDescription = "Averages used to assit predicting price patterns.";
sc.GraphRegion = 0;
sc.AutoLoop = 1;
sc.AlertOnlyOncePerBar = true;
  sc.FreeDLL = 1;

// Set the color, style and line width for the subgraph
  
  

  MaxM_100percent_Upper.Name = "MMove 100% Upper";
  MaxM_100percent_Upper.PrimaryColor = RGB(20,77,255);
  MaxM_100percent_Upper.DrawStyle = DRAWSTYLE_LINE;
  MaxM_100percent_Upper.LineStyle = LINESTYLE_SOLID;
  MaxM_100percent_Upper.LineWidth = 5;



  EMA_Medium.Name = "EMA Medium";
  EMA_Medium.PrimaryColor = RGB(255,0,0);
  EMA_Medium.DrawStyle = DRAWSTYLE_LINE;
  EMA_Medium.LineStyle = LINESTYLE_SOLID;
  EMA_Medium.LineWidth = 2;

  EMA_Long.Name = "EMA Long";
  EMA_Long.PrimaryColor = RGB(0,0,255);
  EMA_Long.DrawStyle = DRAWSTYLE_LINE;
  EMA_Long.LineStyle = LINESTYLE_SOLID;
  EMA_Long.LineWidth = 2;


  

  
  return;

}

// Do data processing
// Calculate a simple moving average from the base data




sc.ExponentialMovAvg(sc.Close, EMA_Medium, 50);
sc.ExponentialMovAvg(sc.Close, EMA_Long, 200);

float EMAMedium = EMA_Medium[sc.Index];
float EMALong = EMA_Long[sc.Index];


MaxM_100percent_Upper[sc.Index]= abs(EMAMedium - EMALong) ;

//MaxMove_100percent_Upper[sc.Index]= ( EMA_Medium[sc.Index-1] - EMA_Long[sc.Index-1]) ; /// 1.0f;





}

[2015-10-08 09:00:31]
Sierra Chart Engineering - Posts: 104368
The very first step is to simplify the study down to a single Subgraph that uses a fixed value like 10:
sc.Subgraph[0].Data[sc.Index] = 10;

Set sc.GraphRegion = 1.

So you want to see if you can actually get a single line to display.

As a general policy, we are not going to debug your code.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2015-10-08 09:00:53
[2015-10-08 11:52:08]
KhaosTrader - Posts: 128
Understood.

It seems that the absolute value function call is returning 0 and I dont know why.

abs(EMAMedium-EMALong) how do i get a valid absolute value from the difference of these two variables? I did @include math.h
[2015-10-08 17:13:42]
Sierra Chart Engineering - Posts: 104368
Try using:
fabs(EMAMedium-EMALong)
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2015-10-08 19:49:16]
KhaosTrader - Posts: 128
Yes that works! Thanks so much :)

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account