Login Page - Create Account

Support Board


Date/Time: Sat, 20 Apr 2024 08:47:58 +0000



Post From: custom indicator AC

[2013-06-07 08:24:16]
942abel - Posts: 7
hello
my question is on a custom indicator.
I have the problem that the graphical representation is different from another platform.

The indicator is a variation of AC Oscillator.

The formula of the other platform is:

AO = SMA (median price, 5)-SMA (median price, 34)
AC = AO-SMA (AO, 5)

And this is the code:

//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Green
#property indicator_color3 Red
//---- indicator buffers
double ExtBuffer0[];
double ExtBuffer1[];
double ExtBuffer2[];
double ExtBuffer3[];
double ExtBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(5);
//---- drawing settings
SetIndexStyle(0,DRAW_NONE);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);
IndicatorDigits(Digits+2);
SetIndexDrawBegin(0,38);
SetIndexDrawBegin(1,38);
SetIndexDrawBegin(2,38);
//---- 4 indicator buffers mapping
SetIndexBuffer(0,ExtBuffer0);
SetIndexBuffer(1,ExtBuffer1);
SetIndexBuffer(2,ExtBuffer2);
SetIndexBuffer(3,ExtBuffer3);
SetIndexBuffer(4,ExtBuffer4);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("AC");
SetIndexLabel(1,NULL);
SetIndexLabel(2,NULL);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Accelerator/Decelerator Oscillator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
double prev,current;
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st additional buffer

for(int i=0; i<limit; i++)

ExtBuffer3[i]=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,0,34,0,MODE_SMA,PRICE_MEDIAN,i);

//---- signal line counted in the 2-nd additional buffer

for(i=0; i<limit; i++)

ExtBuffer4[i]=iMAOnArray(ExtBuffer3,Bars,5,0,MODE_SMA,i);


//---- dispatch values between 2 buffers
bool up=true;
for(i=limit-1; i>=0; i--)
{
current=ExtBuffer3[i]-ExtBuffer4[i];
prev=ExtBuffer3[i+1]-ExtBuffer4[i+1];
if(current>prev) up=true;
if(current<prev) up=false;
if(!up)
{
ExtBuffer2[i]=current;
ExtBuffer1[i]=0.0;
}
else
{
ExtBuffer1[i]=current;
ExtBuffer2[i]=0.0;
}
ExtBuffer0[i]=current;
}
//---- done
return(0);
}

I have modified and created the code for sierrachart, but as I said before the graphical representation is not the same.
This is the modified code:


/*****************************************************************************

  For reference, please refer to the Advanced Custom Study Interface
  and Language documentation on the Sierra Chart website.
  
*****************************************************************************/

///  AO = SMA(median price, 5)-SMA(median price, 34)
///  AC = AO-SMA(AO, 5)

// This line is required. Change the text within the quote
// marks to what you want to name your group of custom studies.
SCDLLName("Custom Study DLL")


SCSFExport scsf_AC_DC_Histogram3(SCStudyInterfaceRef sc)
{
  SCSubgraphRef ACDC = sc.Subgraph[0];
  SCSubgraphRef Temp3 = sc.Subgraph[3];
  SCSubgraphRef Temp4 = sc.Subgraph[4];
  SCSubgraphRef Temp5 = sc.Subgraph[5];

  SCInputRef InputData = sc.Input[0];  
  SCInputRef MA1Length = sc.Input[2];
  SCInputRef MA2Length = sc.Input[3];
  SCInputRef MA4Length = sc.Input[5];

  if (sc.SetDefaults)
  {
    sc.GraphName = "AC/DC Histogram 3";
    
    sc.GraphRegion = 1;
    sc.ValueFormat = 3;
    sc.AutoLoop = 1;
    sc.FreeDLL = 0;

    ACDC.Name = "AC/DC3";
    ACDC.DrawStyle = DRAWSTYLE_BAR;
    ACDC.SecondaryColor = RGB(255,0,0);
    ACDC.AutoColoring = AUTOCOLOR_SLOPE;
    ACDC.DrawZeros = false;

    InputData.Name = "Input Data";
    InputData.SetInputDataIndex(SC_LAST);

    MA1Length.Name = "Moving Average 1 Length";
    MA1Length.SetInt(34);
    MA1Length.SetIntLimits(1, MAX_STUDY_LENGTH);

    MA2Length.Name = "Moving Average 2 Length";
    MA2Length.SetInt(5);
    MA2Length.SetIntLimits(1, MAX_STUDY_LENGTH);

    MA4Length.Name = "Moving Average 4 Length";
    MA4Length.SetInt(5);
    MA4Length.SetIntLimits(1, MAX_STUDY_LENGTH);

    return;
  }

  sc.DataStartIndex = max(MA1Length.GetInt(), MA2Length.GetInt()) + MA4Length.GetInt();

  sc.SimpleMovAvg(sc.BaseDataIn[InputData.GetInputDataIndex()], Temp3, MA1Length.GetInt());
  sc.SimpleMovAvg(sc.BaseDataIn[InputData.GetInputDataIndex()], Temp4, MA2Length.GetInt());

  if (sc.Index > 0)
    Temp5[sc.Index] = Temp4[sc.Index] - Temp3[sc.Index];
  

  sc.SimpleMovAvg(Temp5, ACDC, MA4Length.GetInt());
}


someone could help me?
Thank you so much