SCSFExport scsf_EMotion(SCStudyGraphRef sg)
{
// Section 1 - Set the configuration variables
SCString Buffer;
if (sg.SetDefaults) // This section only run once upon adding an instance of the study to a chart
{
// Set the configuration and defaults
// Please see 'scsf_MovingAverageExample1' for comments on 'sg.SetDefaults'.
sg.GraphName = "Market E-Motion";
sg.StudyDescription = "Market E-Motion: High, Low and midpoints of the day.";
sg.CalculationPrecedence = LOW_PREC_LEVEL;
sg.AutoLoop = 0; // Enable auto-looping
sg.UpdateAlways = 0; // Set this study to update always
sg.FreeDLL = 1; // must be set to zero, it makes calling the function faster
// Set the region to draw the graph in. Region zero is the main
// price graph region.
sg.GraphRegion = 0;
// Set the name of the first subgraph
sg.Subgraph[0].Name = "High";
// Set the color and style of the graph line. If these are not set
// the default will be used.
sg.Subgraph[0].PrimaryColor = RGB(255,0,0); // Red
sg.Subgraph[0].DrawStyle = DRAWSTYLE_LINE;
sg.Subgraph[0].Caption = CAPTION_VALUE;
sg.Subgraph[1].Name = "Low";
sg.Subgraph[1].PrimaryColor = RGB(0,255,0); // Green
sg.Subgraph[1].DrawStyle = DRAWSTYLE_LINE;
sg.Subgraph[1].Caption = CAPTION_VALUE;
sg.Subgraph[2].Name = "Mid";
sg.Subgraph[2].PrimaryColor = RGB(128,0,0); // Dark Red
sg.Subgraph[2].SecondaryColor = RGB(0,128,0); // Dark Green
sg.Subgraph[2].DrawStyle = DRAWSTYLE_LINE;
sg.Subgraph[2].Caption = CAPTION_VALUE;
sg.Subgraph[2].SecondaryColorUsed = 1; // true
sg.Subgraph[3].Name = "Mid+";
sg.Subgraph[3].PrimaryColor = RGB(128,0,0); // Dark Red
sg.Subgraph[3].SecondaryColor = RGB(0,128,0); // Dark Green
sg.Subgraph[3].DrawStyle = DRAWSTYLE_LINE;
sg.Subgraph[3].Caption = CAPTION_VALUE;
sg.Subgraph[3].SecondaryColorUsed = 1; // true
sg.Subgraph[4].Name = "Mid-";
sg.Subgraph[4].PrimaryColor = RGB(128,0,0); // Dark Red
sg.Subgraph[4].SecondaryColor = RGB(0,128,0); // Dark Green
sg.Subgraph[4].DrawStyle = DRAWSTYLE_LINE;
sg.Subgraph[4].Caption = CAPTION_VALUE;
sg.Subgraph[4].SecondaryColorUsed = 1; // true
// Must return before doing any data processing if sg.SetDefaults is set
return;
}
// Section 2 - Do data processing
// Everything below here is run on every chart update or when the chart is
// reloaded.
if (sg.Symbol.CompareNoCase("ER2", 3) == 0) sg.ValueFormat = 1;
if (sg.Symbol.CompareNoCase("YM", 2) == 0) sg.ValueFormat = 0;
if (sg.Symbol.CompareNoCase("EUR", 3) == 0) sg.ValueFormat = 4;
//Buffer.Format("Start %d: %s", sg.Symbol.CompareNoCase("YM", 2), sg.Symbol);
//sg.AddMessageToLog(Buffer, 0);
// Get the inputs
//int InMALength = sg.Input[0].GetInt(); // Input 0 - "Length"
//sg.Subgraph[0].Name.Format("Volume: %1.0f", sg.BaseDataIn[SC_VOLUME][sg.ArraySize-1]);
sg.GraphName.Format("Volume: %1.0f", sg.BaseDataIn[SC_VOLUME][sg.ArraySize-1]);
// Set the index of the first array element to begin drawing at.
// Setting the variable sg.DataStartIndex ensures that we start far enough
// from the beginning of the array to create valid plots.
//sg.DataStartIndex = InMALength - 1;
// Calculate a simple moving average for the input array
// InMALength is 30 by default. Therefore, the 1st data element plotted begins with element
// 29 (InMALength - 1). If there are 1000 bars in the chart, then the last data element
// plotted begins with element 970 (999 - (InMALength - 1)) and goes to element 999.
// Don't do anything until we have enough bars for calculating our average.
//if (sg.CurrentIndex < InMALength - 1) return;
// Add together the closing prices over the length for the prior bars
//float Sum = 0;
float MID = 0;
float LOW = 0;
float HIGH = 0;
int DATE = 0;
LOW = 5000000; //sg.BaseDataIn[SC_LOW][1];
HIGH = 0; //sg.BaseDataIn[SC_HIGH][1];
//Buffer.Format("Size %d", sg.ArraySize);
//sg.AddMessageToLog(Buffer, 0);
//Buffer.Format("Start %s", sg.Symbol);
//sg.AddMessageToLog(Buffer, 0);
for (int i = 0; i <= sg.ArraySize-1; i++)
{
//Buffer.Format("HIGH %f", HIGH);
//sg.AddMessageToLog(Buffer, 0);
//Buffer.Format("LOW %f", LOW);
//sg.AddMessageToLog(Buffer, 0);
if (sg.BaseDateTimeIn.DateAt(i) != DATE) {
LOW = 5000000; //sg.BaseDataIn[SC_LOW][1];
HIGH = 0; //sg.BaseDataIn[SC_HIGH][1];
DATE = sg.BaseDateTimeIn.DateAt(i);
}
if (sg.BaseDataIn[SC_LOW][i] < LOW) LOW = sg.BaseDataIn[SC_LOW][i];
if (sg.BaseDataIn[SC_HIGH][i] > HIGH) HIGH = sg.BaseDataIn[SC_HIGH][i];
}
//Buffer.Format("Size %d",sg.ArraySize);
//sg.AddMessageToLog(Buffer, 0);
//Buffer.Format("HIGH %f", HIGH);
//sg.AddMessageToLog(Buffer, 0);
//Buffer.Format("LOW %f", LOW);
//sg.AddMessageToLog(Buffer, 0);
//Buffer.Format("Start %d: %s", sg.Symbol.CompareNoCase("ES", 2), sg.Symbol);
//sg.AddMessageToLog(Buffer, 0);
for (int i = sg.UpdateStartIndex+1; i <= sg.ArraySize; i++)
{
//Buffer.Format("HIGH %f", sg.BaseDataIn[SC_HIGH][i]);
//sg.AddMessageToLog(Buffer, 0);
//Buffer.Format("LOW %f", sg.BaseDataIn[SC_LOW][i]);
//sg.AddMessageToLog(Buffer, 0);
if (sg.BaseDateTimeIn.DateAt(i) != DATE) {
LOW = 5000000; //sg.BaseDataIn[SC_LOW][1];
HIGH = 0; //sg.BaseDataIn[SC_HIGH][1];
DATE = sg.BaseDateTimeIn.DateAt(i);
}
if (sg.BaseDataIn[SC_LOW][i] < LOW) LOW = sg.BaseDataIn[SC_LOW][i];
if (sg.BaseDataIn[SC_HIGH][i] > HIGH) HIGH = sg.BaseDataIn[SC_HIGH][i];
sg.Subgraph[0][i] = HIGH;
sg.Subgraph[1][i] = LOW;
MID = (LOW+HIGH)/2;
sg.Subgraph[2][i] = MID;
if (sg.BaseDataIn[SC_LAST][i] < MID) sg.Subgraph[2].DataColor[i] = sg.Subgraph[2].PrimaryColor; // Dark Red
else sg.Subgraph[2].DataColor[i] = sg.Subgraph[2].SecondaryColor; //Dark Green
sg.Subgraph[3][i] = (MID+HIGH)/2;
if (sg.BaseDataIn[SC_LAST][i] < (MID+HIGH)/2) sg.Subgraph[3].DataColor[i] = sg.Subgraph[3].PrimaryColor; // Dark Red
else sg.Subgraph[3].DataColor[i] = sg.Subgraph[3].SecondaryColor; //Dark Green
sg.Subgraph[4][i] = (MID+LOW)/2;
if (sg.BaseDataIn[SC_LAST][i] < (MID+LOW)/2) sg.Subgraph[4].DataColor[i] = sg.Subgraph[4].PrimaryColor; // Dark Red
else sg.Subgraph[4].DataColor[i] = sg.Subgraph[4].SecondaryColor; //Dark Green
}
}