#define ASKCOLOR RGB(255, 128, 128) #define BIDCOLOR RGB(128, 255, 128) #define POSDELTACOLOR RGB(32, 255, 32) #define NEGDELTACOLOR RGB(255, 32, 32) SCSFExport scsf_DeltaMomentum(SCStudyGraphRef sc) { SCSubgraphRef askVol = sc.Subgraph[0]; SCSubgraphRef bidVol = sc.Subgraph[1]; SCSubgraphRef deltaVol = sc.Subgraph[2]; SCSubgraphRef deltaMomentum = sc.Subgraph[3]; if (sc.SetDefaults) { sc.GraphName = "DeltaMomentum"; sc.GraphRegion = 1; sc.ScaleRangeType = SCALE_AUTO; sc.StudyDescription = "DeltaMomentum"; sc.FreeDLL = 0; sc.AutoLoop = 0; // Manual looping askVol.Name = "Ask Volume"; askVol.PrimaryColor = ASKCOLOR; askVol.DrawStyle = DRAWSTYLE_IGNORE; bidVol.Name = "Bid Volume"; bidVol.PrimaryColor = BIDCOLOR; bidVol.DrawStyle = DRAWSTYLE_IGNORE; deltaVol.Name = "Delta"; deltaVol.DrawStyle = DRAWSTYLE_IGNORE; deltaMomentum.Name = "Delta Momentum"; deltaMomentum.PrimaryColor = POSDELTACOLOR; deltaMomentum.SecondaryColor = NEGDELTACOLOR; deltaMomentum.LineWidth = 2; deltaMomentum.DrawStyle = DRAWSTYLE_BAR; deltaMomentum.AutoColoring = AUTOCOLOR_POSNEG; return; } int ind = sc.UpdateStartIndex; if (ind == 0) { askVol[ind] = sc.BaseDataIn[SC_ASKVOL][ind]; bidVol[ind] = -sc.BaseDataIn[SC_BIDVOL][ind]; deltaVol[ind] = askVol[ind] + bidVol[ind]; deltaMomentum[ind] = deltaVol[ind]; ++ind; } for (; ind < sc.ArraySize; ++ind) { askVol[ind] = sc.BaseDataIn[SC_ASKVOL][ind]; bidVol[ind] = -sc.BaseDataIn[SC_BIDVOL][ind]; deltaVol[ind] = askVol[ind] + bidVol[ind]; if (deltaVol[ind] > 0) { if (deltaMomentum[ind-1] >= 0) { deltaMomentum[ind] = deltaMomentum[ind-1] + deltaVol[ind]; } else { deltaMomentum[ind] = deltaVol[ind]; } } else if (deltaVol[ind] < 0) { if (deltaMomentum[ind-1] <= 0) { deltaMomentum[ind] = deltaMomentum[ind-1] + deltaVol[ind]; } else { deltaMomentum[ind] = deltaVol[ind]; } } else { deltaMomentum[ind] = deltaMomentum[ind-1]; } } }