Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I have two questions.
1, How can I limit the number of bars the study would use for the calculations. So it wouldn't make a full chart calculation when I open the chartbook, refresh the chart or change the time frame.
2, How can I make a separator line in the Study Settings Menu?
Like this:
I did look through the Input array section but couldn't find anything which would do this.
Can you help answer these questions from other members on NexusFi?
I tried the sc.ArraySize but without the if and the sc.Index part. I thought I have to declare it. And I was trying with the SetString input too but the information on the SC site was not enough for my knowledge.
I still have a lot to learn.
I've run into another puzzle. I'd like make a bar period changer study which works according another chart's bar period.
For this I set this study onto Chart#1:
SCSFExport scsf_BarPeriodReading(SCStudyInterfaceRef sc)
{
SCSubgraphRef TimeFrame = sc.Subgraph[0];
if (sc.SetDefaults)
{
// Set the configuration and defaults.
sc.GraphName = "Bar Period Reading";
sc.AutoLoop = 0;
sc.GraphRegion = 0;
sc.UpdateAlways = 1;
TimeFrame.Name = "TF";
TimeFrame.DrawStyle = DRAWSTYLE_IGNORE;
TimeFrame.PrimaryColor = RGB(0,128,0);
return;
}
n_ACSIL::s_BarPeriod BarPeriod;
sc.GetBarPeriodParameters(BarPeriod);
if (BarPeriod.ChartDataType == INTRADAY_DATA && BarPeriod.IntradayChartBarPeriodType == IBPT_DAYS_MINS_SECS)
{
int SecondsPerBar = BarPeriod.IntradayChartBarPeriodParameter1;
}
TimeFrame[sc.Index] = BarPeriod.IntradayChartBarPeriodParameter1;
}
...and set this study onto Chart#2:
SCSFExport scsf_TF_Receiver2(SCStudyInterfaceRef sc)
{
SCInputRef ChartStudy = sc.Input[0];
SCInputRef MultiPlier = sc.Input[1];
// Set configuration variables
if (sc.SetDefaults)
{
// Set the configuration and defaults
sc.GraphName = "TF Receiver 2";
sc.CalculationPrecedence = LOW_PREC_LEVEL;
sc.StudyVersion = 10;
sc.AutoLoop = 0;
ChartStudy.Name = "Study Reference";
ChartStudy.SetChartStudyValues(1, 1);
MultiPlier.Name = "Multiplier Value";
MultiPlier.SetInt(3);
return;
}
// Array references
// Define a graph data object to get all of the study data
SCGraphData StudyData;
// Get the index in the specified chart that is
// nearest to current index.
int RefChartIndex = sc.GetNearestMatchForDateTimeIndex(ChartStudy.GetChartNumber(), sc.Index);
// Get the study data from the specified chart
sc.GetStudyArraysFromChartUsingID(ChartStudy.GetChartNumber(), ChartStudy.GetStudyID(), StudyData);
// Define a reference to the first Subgraph array
SCFloatArrayRef BarPeriodReference = StudyData[0];
// Array is empty. Nothing to do.
if (BarPeriodReference.GetArraySize() == 0)
return;
// Get the index in the specified chart that is nearest
// to current index.
RefChartIndex = sc.GetNearestMatchForDateTimeIndex(ChartStudy.GetChartNumber(), sc.Index);
float NearestSubgraphValue = BarPeriodReference[RefChartIndex];
// Get the index in the specified chart that contains
// the DateTime of the bar at the current index.
RefChartIndex = sc.GetContainingIndexForDateTimeIndex(ChartStudy.GetChartNumber(), sc.Index);
float ContainingSubgraphValue = BarPeriodReference[RefChartIndex];
// Get the index in the specified chart that exactly
// matches the DateTime of the current index.
RefChartIndex = sc.GetExactMatchForSCDateTime(ChartStudy.GetChartNumber(), sc.BaseDateTimeIn[sc.Index]);
if (RefChartIndex != -1) //-1 means that there was not an exact match and therefore we do not have a valid index to work with
{
float ExactMatchSubgraphValue = BarPeriodReference[RefChartIndex];
}
float NewTF = (BarPeriodReference[RefChartIndex] * MultiPlier.GetInt());
SCString DebugString;
DebugString.Format("TF Ref: %f, NewTF: %f", BarPeriodReference[RefChartIndex], NewTF);
sc.AddMessageToLog(DebugString, 1);
}
When I change the bar period on the Chart#1 the study sets the wanted bar period on the Chart#2 but in that instant something resets the BarPeriodReference[RefChartIndex] to zero which makes the Chart#2 to recalculate. Then the study sets the wanted bar period and make the reset again. And this goes on till the current bar on chart#2 closes and with the new bar stops and stays as it should.
What should I modify to avoid that reset and the whole annoying recalculete process?
It seem for some reason I didn't copy the whole code.
So here it is again:
SCSFExport scsf_TF_Receiver2(SCStudyInterfaceRef sc)
{
SCInputRef ChartStudy = sc.Input[0];
SCInputRef MultiPlier = sc.Input[1];
// Set configuration variables
if (sc.SetDefaults)
{
// Set the configuration and defaults
sc.GraphName = "TF Receiver 2";
sc.CalculationPrecedence = LOW_PREC_LEVEL;
sc.StudyVersion = 10;
sc.AutoLoop = 0;
ChartStudy.Name = "Study Reference";
ChartStudy.SetChartStudyValues(1, 1);
MultiPlier.Name = "Multiplier Value";
MultiPlier.SetInt(3);
return;
}
// Array references
// Define a graph data object to get all of the study data
SCGraphData StudyData;
// Get the index in the specified chart that is
// nearest to current index.
int RefChartIndex = sc.GetNearestMatchForDateTimeIndex(ChartStudy.GetChartNumber(), sc.Index);
// Get the study data from the specified chart
sc.GetStudyArraysFromChartUsingID(ChartStudy.GetChartNumber(), ChartStudy.GetStudyID(), StudyData);
// Define a reference to the first Subgraph array
SCFloatArrayRef BarPeriodReference = StudyData[0];
// Array is empty. Nothing to do.
if (BarPeriodReference.GetArraySize() == 0)
return;
// Get the index in the specified chart that is nearest
// to current index.
RefChartIndex = sc.GetNearestMatchForDateTimeIndex(ChartStudy.GetChartNumber(), sc.Index);
float NearestSubgraphValue = BarPeriodReference[RefChartIndex];
// Get the index in the specified chart that contains
// the DateTime of the bar at the current index.
RefChartIndex = sc.GetContainingIndexForDateTimeIndex(ChartStudy.GetChartNumber(), sc.Index);
float ContainingSubgraphValue = BarPeriodReference[RefChartIndex];
// Get the index in the specified chart that exactly
// matches the DateTime of the current index.
RefChartIndex = sc.GetExactMatchForSCDateTime(ChartStudy.GetChartNumber(), sc.BaseDateTimeIn[sc.Index]);
if (RefChartIndex != -1) //-1 means that there was not an exact match and therefore we do not have a valid index to work with
{
float ExactMatchSubgraphValue = BarPeriodReference[RefChartIndex];
}
float NewTF = (BarPeriodReference[RefChartIndex] * MultiPlier.GetInt());
n_ACSIL::s_BarPeriod BarPeriod;
sc.GetBarPeriodParameters(BarPeriod);
if (BarPeriod.ChartDataType == INTRADAY_DATA && BarPeriod.IntradayChartBarPeriodType == IBPT_DAYS_MINS_SECS)
{
int SecondsPerBar = BarPeriod.IntradayChartBarPeriodParameter1;
}
if (BarPeriod.ChartDataType != INTRADAY_DATA
|| BarPeriod.IntradayChartBarPeriodType != IBPT_DAYS_MINS_SECS
|| BarPeriod.IntradayChartBarPeriodParameter1 != NewTF)
{
n_ACSIL::s_BarPeriod NewBarPeriod;
NewBarPeriod.ChartDataType = INTRADAY_DATA;
NewBarPeriod.IntradayChartBarPeriodType = IBPT_DAYS_MINS_SECS;
NewBarPeriod.IntradayChartBarPeriodParameter1 = NewTF;
//Set the bar period parameters. This will go into effect after the study function returns.
sc.SetBarPeriodParameters(NewBarPeriod);
}
SCString DebugString;
DebugString.Format("TF Ref: %f, NewTF: %f", BarPeriodReference[RefChartIndex], NewTF);
sc.AddMessageToLog(DebugString, 1);
}
I'm trying to write my first study/code but when It shows up in SC studies it says Template Function. What does that mean? It doesn't show anything when added to a chart..
I'm trying to write my first study/code but when It shows up in SC studies it says Template Function. What does that mean? It doesn't show anything when added to a chart..
Thanks
Impossible to tell without you posting your code to check.
Impossible to tell without you posting your code to check.
Hello,
How about my code? The bar period changer. I keep putting aside then try again with renewed enthusiasm but I can't figure out why doesn't work properly.
How about my code? The bar period changer. I keep putting aside then try again with renewed enthusiasm but I can't figure out why doesn't work properly.
Could you have a look at it?
Pleeeeeese
Thanks!
You don't need a study to do that. You can use the link numbers and bar period and chart settings.
You don't need a study to do that. You can use the link numbers and bar period and chart settings.
I can't set any multiplier number in the chart settings.
In nut shell... I want to change a chart's bar period with a pre set multiplier number by changing another chart's bar period.
For example I change the bar period on chart 1 from 25 sec to 30 sec then chart 2's bar period does change from 75 sec to 90 sec because I set the multiplier to 3.
Therefore I wrote a study to read the bar period and put that into a subgraph. This study is on chart 1.
And another study which gets that subgraph multiply it and set the bar period to that number. This study is on chart 2.
But it's not working properly. Sometimes works fine but most of the times something keep makes the chart 2 to recalculate for a while as if I'd press tha 'Insert' button continuously.