Login Page - Create Account

Support Board


Date/Time: Fri, 07 Feb 2025 18:12:43 +0000



Post From: Bar based on midpoint

[2022-01-07 18:57:17]
Tony - Posts: 549
I wrote this code which is exactly what you need,

//code start
SCSFExport scsf_Open_MidPoint_At_Last_Bar(SCStudyInterfaceRef sc)
{
  SCSubgraphRef MyBarTop = sc.Subgraph[0];
  SCSubgraphRef MyBarBottom = sc.Subgraph[1];
  
  if (sc.SetDefaults) {
    sc.GraphName = "Last Bar Open Midpoint";
    sc.AutoLoop = 1;
    sc.GraphRegion = 0;
    sc.UpdateAlways = 1;

    MyBarTop.Name = "My Bar Top";
    MyBarBottom.Name = "My Bar Bottom";
    MyBarTop.DrawStyle = DRAWSTYLE_BAR_TOP;
    MyBarBottom.DrawStyle = DRAWSTYLE_BAR_BOTTOM;
    MyBarTop.LineWidth = 4;
    MyBarBottom.LineWidth = 4;
    return;
  }

  for (int IndexCount=0; IndexCount<=sc.Index; IndexCount++) {
    if (IndexCount==sc.Index)
      MyBarTop[IndexCount] = (sc.Bid + sc.Ask) / 2;
    else
      MyBarTop[IndexCount] = sc.Close[IndexCount];
    MyBarBottom[IndexCount] = sc.Open[IndexCount];
    if (MyBarTop[IndexCount]>MyBarBottom[IndexCount])
      MyBarTop.DataColor[IndexCount] = RGB(0, 255, 0);
    else
      MyBarBottom.DataColor[IndexCount] = RGB(255, 0, 0);
  }
}
//code end

1, Remote build the above code,
2, Set Main Graph' graph draw type as HL bars and line width to 1
3, Load this custom study to your chart and make sure "Draw Study Underneath
Main Price Graph" is unchecked
Date Time Of Last Edit: 2022-01-07 19:10:51