Login Page - Create Account

Support Board


Date/Time: Thu, 26 Dec 2024 19:01:19 +0000



Post From: Orderflowanalytics-style reversal bars.

[2013-09-14 00:42:01]
marcovth - Posts: 61
Here is a previous attempt I wrote, but something is missing.

It seems to work, but it's messing up other studies that I add to the chart (which is not the case with the Better Renko or PnF studies.

So if you can detect what's wrong, that would be helpful too.


#include "sierrachart.h"

SCDLLName("DirectionalReversalChart")

SCSFExport scsf_CopyOfBaseGraph(SCStudyInterfaceRef sc){

  SCSubgraphRef Open = sc.Subgraph[0];
  SCSubgraphRef High = sc.Subgraph[1];
  SCSubgraphRef Low = sc.Subgraph[2];
  SCSubgraphRef Close = sc.Subgraph[3];
  SCSubgraphRef Volume = sc.Subgraph[4];
  SCSubgraphRef OpenInterest = sc.Subgraph[5];
  SCSubgraphRef OHLCAvg = sc.Subgraph[6];
  SCSubgraphRef HLCAvg = sc.Subgraph[7];
  SCSubgraphRef HLAvg = sc.Subgraph[8];
  SCSubgraphRef BidVol = sc.Subgraph[9];
  SCSubgraphRef AskVol = sc.Subgraph[10];

  if (sc.SetDefaults){

    sc.GraphName = "Directional Reversal Chart";
    sc.StudyDescription = "";

    sc.IsCustomChart = 1;
    sc.GraphRegion = 0;    
    sc.DrawZeros = 0;
    sc.GraphDrawType = GDT_CANDLESTICK;
    sc.StandardChartHeader = 1;
    sc.DisplayAsMainPriceGraph = 1;
    sc.ValueFormat = sc.BaseGraphValueFormat;

    Open.Name = "Open";
    Open.DrawStyle = DRAWSTYLE_LINE;
    Open.PrimaryColor = RGB(0,200,0);
    
    High.Name = "High";
    High.DrawStyle = DRAWSTYLE_LINE;
    High.PrimaryColor = RGB(0,0,0);

    Low.Name = "Low";
    Low.DrawStyle = DRAWSTYLE_LINE;
    Low.PrimaryColor = RGB(200,0,0);

    Close.Name = "Close";
    Close.DrawStyle = DRAWSTYLE_LINE;
    Close.PrimaryColor = RGB(0,0,0);

    Volume.Name = "Volume";
    Volume.DrawStyle = DRAWSTYLE_IGNORE;

    OpenInterest.Name = "# of Trades / OI";
    OpenInterest.DrawStyle = DRAWSTYLE_IGNORE;

    OHLCAvg.Name = "OHLC Avg";
    OHLCAvg.DrawStyle = DRAWSTYLE_IGNORE;

    HLCAvg.Name = "HLC Avg";
    HLCAvg.DrawStyle = DRAWSTYLE_IGNORE;

    HLAvg.Name = "HL Avg";
    HLAvg.DrawStyle = DRAWSTYLE_IGNORE;

    BidVol.Name = "Bid Vol";
    BidVol.DrawStyle = DRAWSTYLE_IGNORE;

    AskVol.Name = "Ask Vol";
    AskVol.DrawStyle = DRAWSTYLE_IGNORE;
    
    sc.FreeDLL = 1;
    sc.AutoLoop = 1;
    sc.MaintainVolumeAtPriceData = 1;
    
    return;
  }
  
  int i=sc.Index;
  SCString message;
  
  // If our start index is zero, then we want to clear our existing chart
  // data, if any, so we start clean to avoid any possible problems. This
  // is accomplished by using sc.ResizeArrays.
  if (sc.UpdateStartIndex == 0) sc.ResizeArrays(0);
  
  unsigned int AskVolume    = 0;
  unsigned int BidVolume  = 0;
  float Price=0;
  float prevPrice=0;
  
  float& DirectionalMove = sc.PersistVars->f1;
  //float& OpenBar = sc.PersistVars->f2;
  //float& HighBar = sc.PersistVars->f3;
  //float& LowBar = sc.PersistVars->f4;
  
  
  if( i==sc.ArraySize-2 || (i > sc.ArraySize-2) ){ // && sc.GetBarHasClosedStatus(i) == BHCS_BAR_HAS_CLOSED
    sc.ResizeArrays(0);
    //HighBar=0;
    //LowBar=0;
    //OpenBar=0;
    int prevIndex=0;
    int out=-1;
    //for (int n = sc.UpdateStartIndex; n < sc.ArraySize; n++){
    for (int n = 0; n < sc.ArraySize; n++){
  
      if(n==0){
        //HighBar=sc.High[n];
        //LowBar=sc.Low[n];
        //OpenBar=sc.Open[n];
      } else {
      
        float HighBar=sc.GetHighest(sc.High,n,n-prevIndex);
        float LowBar=sc.GetLowest(sc.Low,n,n-prevIndex);
        float OpenBar=sc.Open[prevIndex+1];
        
        if(sc.High[n]>0 and sc.High[n]>HighBar)HighBar=sc.High[n];
        if(sc.Low[n]>0 and sc.Low[n]<LowBar) LowBar=sc.Low[n];
        
        bool PrintBar=false;
        if(sc.Close[n]>0 and (HighBar-LowBar)>(8.0f*sc.TickSize) ){
          if( (HighBar-sc.Close[n])>=(4.0f*sc.TickSize) or (sc.Close[n]-LowBar)>=(4.0f*sc.TickSize) ){
            // 8 tick directional move with 4 tick pullback
            PrintBar=true;
          }
        }


        if(PrintBar){
          //if (sc.OutArraySize-1 < n)
          sc.AddElements(1);
          out++;
          High[out]=HighBar;
          Low[out]=LowBar;
          Open[out]=OpenBar;
          Close[out]=sc.Close[n];
          //HighBar=sc.High[n];
          //LowBar=sc.Low[n];
          //OpenBar=sc.Close[n];
          prevIndex=n;
          //message.Format("%f | %f | %f | %f",OpenBar,HighBar,LowBar,Price);
          //sc.AddMessageToLog(message, 1);
          
          
          sc.DateTimeOut[out] = sc.BaseDateTimeIn[n];
          /*for (int SubGraph = 0; SubGraph <=10; SubGraph++){
            sc.Subgraph[SubGraph][n] = sc.BaseDataIn[SubGraph][n];

            //For testing coloring bars
            //sc.Subgraph[SubGraph].DataColor[i] = RGB(255,255,255);
          }*/
          PrintBar=false;
        }
      }
    }
  }
}