Login Page - Create Account

Support Board


Date/Time: Mon, 25 Nov 2024 16:33:03 +0000



Post From: Back Adjusted Gap Fill

[2024-02-24 08:33:57]
esMike - Posts: 69
I created a study to do it... Feel free to modify/include it in user contributed studies if you want.




SCSFExport scsf_MVNoGaps(SCStudyInterfaceRef sc)
{
//Copyright @meanVelocity - Free for personal use.

  SCSubgraphRef Subgraph_Open = sc.Subgraph[0];
  SCSubgraphRef Subgraph_High = sc.Subgraph[1];
  SCSubgraphRef Subgraph_Low = sc.Subgraph[2];
  SCSubgraphRef Subgraph_Last = sc.Subgraph[3];
  SCSubgraphRef Subgraph_Volume = sc.Subgraph[4];
  SCSubgraphRef Subgraph_NumTrades = sc.Subgraph[5];
  SCSubgraphRef Subgraph_OHLCAvg = sc.Subgraph[6];
  SCSubgraphRef Subgraph_HLCAvg = sc.Subgraph[7];
  SCSubgraphRef Subgraph_HLAvg = sc.Subgraph[8];
  SCSubgraphRef Subgraph_BidVol = sc.Subgraph[9];
  SCSubgraphRef Subgraph_AskVol = sc.Subgraph[10];

  SCFloatArrayRef barDate = sc.Subgraph[11].Arrays[0];

  if (sc.SetDefaults)
  {
    // Set the configuration and defaults

    sc.GraphName = "MV NoGaps";
    sc.StudyDescription = "MV NoGaps";

    sc.AutoLoop = 1;
    sc.FreeDLL = 0;
    sc.DisplayStudyName = 0;
    sc.DisplayStudyInputValues = 0;
    sc.GlobalDisplayStudySubgraphsNameAndValue = 0;
    sc.DisplayAsMainPriceGraph = 1;

    sc.GraphDrawType = GDT_BLANK;
    sc.StandardChartHeader = 1;
    sc.GraphRegion = 0;
    sc.ValueFormat = VALUEFORMAT_INHERITED;

    Subgraph_Open.Name = "Open";
    Subgraph_Open.DrawStyle = DRAWSTYLE_LINE;
    Subgraph_Open.PrimaryColor = RGB(0, 255, 0);
    Subgraph_Open.SecondaryColorUsed = true;
    Subgraph_Open.SecondaryColor = RGB(0, 255, 0);

    Subgraph_High.Name = "High";
    Subgraph_High.DrawStyle = DRAWSTYLE_LINE;
    Subgraph_High.PrimaryColor = RGB(128, 255, 128);

    Subgraph_Low.Name = "Low";
    Subgraph_Low.DrawStyle = DRAWSTYLE_LINE;
    Subgraph_Low.PrimaryColor = RGB(255, 0, 0);
    Subgraph_Low.SecondaryColorUsed = true;
    Subgraph_Low.SecondaryColor = RGB(255, 0, 0);

    Subgraph_Last.Name = "Last";
    Subgraph_Last.DrawStyle = DRAWSTYLE_LINE;
    Subgraph_Last.PrimaryColor = RGB(255, 128, 128);

    Subgraph_Volume.Name = "Volume";
    Subgraph_Volume.DrawStyle = DRAWSTYLE_IGNORE;
    Subgraph_Volume.PrimaryColor = RGB(255, 0, 0);

    Subgraph_NumTrades.Name = "NumTrades";
    Subgraph_NumTrades.DrawStyle = DRAWSTYLE_IGNORE;
    Subgraph_NumTrades.PrimaryColor = RGB(0, 0, 255);

    Subgraph_OHLCAvg.Name = "OHLC Avg";
    Subgraph_OHLCAvg.DrawStyle = DRAWSTYLE_IGNORE;
    Subgraph_OHLCAvg.PrimaryColor = RGB(127, 0, 255);

    Subgraph_HLCAvg.Name = "HLC Avg";
    Subgraph_HLCAvg.DrawStyle = DRAWSTYLE_IGNORE;
    Subgraph_HLCAvg.PrimaryColor = RGB(0, 255, 255);

    Subgraph_HLAvg.Name = "HL Avg";
    Subgraph_HLAvg.DrawStyle = DRAWSTYLE_IGNORE;
    Subgraph_HLAvg.PrimaryColor = RGB(0, 127, 255);

    Subgraph_BidVol.Name = "Bid Vol";
    Subgraph_BidVol.DrawStyle = DRAWSTYLE_IGNORE;
    Subgraph_BidVol.PrimaryColor = RGB(0, 255, 0);

    Subgraph_AskVol.Name = "Ask Vol";
    Subgraph_AskVol.DrawStyle = DRAWSTYLE_IGNORE;
    Subgraph_AskVol.PrimaryColor = RGB(0, 255, 0);

    return;
  }

  Subgraph_Open[sc.Index] = sc.Open[sc.Index];
  Subgraph_High[sc.Index] = sc.High[sc.Index];
  Subgraph_Low[sc.Index] = sc.Low[sc.Index];
  Subgraph_Last[sc.Index] = sc.Close[sc.Index];
  Subgraph_Volume[sc.Index] = sc.Volume[sc.Index];
  Subgraph_NumTrades[sc.Index] = sc.NumberOfTrades[sc.Index];

  barDate[sc.Index] = float(sc.BaseDateTimeIn.DateAt(sc.Index));

  if (barDate[sc.Index] != barDate[sc.Index - 1]) {
    if (Subgraph_Open[sc.Index] > Subgraph_Last[sc.Index - 1] || Subgraph_Open[sc.Index] < Subgraph_Last[sc.Index - 1]) {
      float gapAmount = Subgraph_Open[sc.Index] - Subgraph_Last[sc.Index - 1];

        for (int Index = sc.Index - 1; Index > 0; Index--) {
          Subgraph_Open[Index] = Subgraph_Open[Index] + gapAmount;
          Subgraph_High[Index] = Subgraph_High[Index] + gapAmount;
          Subgraph_Low[Index] = Subgraph_Low[Index] + gapAmount;
          Subgraph_Last[Index] = Subgraph_Last[Index] + gapAmount;
        }
    }
  }

  sc.CalculateOHLCAverages();
}

Date Time Of Last Edit: 2024-02-24 08:36:45