[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Plugin dll



PureBytes Links

Trading Reference Links

Thanks ,
I try to write a volatility trailing stop

stephane

> 
> Maybe this will help??
> It is a calculation of Wilders Swing Index ... takes O/H/L/C arrays 
> as input. See in 'FunctionTag gFunctionTable[]' below that the 
number 
> of arrays is defined as 4.... then you can access each array byu 
> their index [ .. ].
> 
> Cliff Elion
> 
> 
> 
> AmiVar SI_si( int NumArgs, AmiVar *ArgsTable )
> {
> int i, j, L1;
> double si, K1, R1, R2, R3, R;
> AmiVar result;
> 
> result = gSite.AllocArrayResult();
> 
> int nSize = gSite.GetArraySize();
> int nLookBack = 1;	//number of 
> lookback bars in function
> 
> float *O = ArgsTable[ 0 ].array;
> float *H = ArgsTable[ 1 ].array;
> float *L = ArgsTable[ 2 ].array;
> float *C = ArgsTable[ 3 ].array;
> 
> j = SkipEmptyValues( nSize, C, result.array );
> 
> L1 = 3;
> 
> for( i = j; i < nSize; i++ )
> {
> if(i<(j+nLookBack)) {result.array[i] = 
> EMPTY_VAL;continue;}
> 
> K1 = max ( fabs( H[i] - C[i-1] ), fabs( L[i] - C[i-
> 1] ) );
> R1 = fabs ( H[i] - C[i-1] );
> R2 = fabs ( L[i] - C[i-1] );
> R3 = fabs ( H[i] - L[i] );
> 
> if ( (R1 > R2) & (R1 > R3) )
> R = fabs(H[i]-C[i-1])-.5*fabs(L[i]-C[i-1])
> +.25*fabs(C[i-1]-O[i-1]);
> else if ( (R2 > R1) & (R2 > R3) )
> R = fabs(L[i]-C[i-1])-.5*fabs(H[i]-C[i-1])
> +.25*fabs(C[i-1]-O[i-1]);
> else if ( (R3 > R1) & (R3 > R2) )
> R = fabs(H[i]-L[i])+.25*fabs(C[i-1]-O[i-1]);
> 
> si = C[i]-C[i-1] + 0.5*(C[i]-O[i]) + 0.25*(C[i-1]-O[i-
> 1]);
> si = (50 * si / R) * (K1/L1);
> 
> result.array[i] = (float) si;
> }
> return result;
> }
> 
> 
> FunctionTag gFunctionTable[] = {
> 
> "SI",	{ SI_si, 4, 0, 0, 0, NULL },
> 
> "SI_System",	{ SI_System, 4, 0, 2, 0, NULL }
> };
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> --- In amibroker@xxxx, "Stephane Carrasset" <nenapacwanfr@xxxx> 
wrote:
> > Tomacz,
> > 
> > is it possible that you give us some more example of plugin dlls, 
> > today I want to write a dll with two "arrays"
> > myatr(array, K)
> > where array is close ot low or..
> > and K is a numeric value in fact an atr value.
> > 
> > with the relation below :
> > 
> > (float) stop ;
> > if(L[i] < prev1)
> > (float) stop= SrcArray[i] - k ;
> > else
> > (float) stop= prev1;
> > if((SrcArray[i] - k) > prev2)
> > (float) stop= SrcArray[i] - k;
> > else
> > (float) stop=prev3;
> > 
> > 
> > 
> > /******************full code**************************/
> > AmiVar VMyAtr( int NumArgs, AmiVar *ArgsTable )
> > {
> > int i,j,k;
> > float prev1,prev2,prev3,stop;
> > AmiVar result;
> > 
> > result = gSite.AllocArrayResult();
> > 
> > int nSize = gSite.GetArraySize();
> > 
> > float *L = ArgsTable[ 0 ].array;
> > float *SrcArray = ArgsTable[ 1 ].array;
> > 
> > int nRange = (int) ArgsTable[ 1 ].val;
> > 
> > j = SkipEmptyValues( nSize, SrcArray, result.array );
> > 
> > for( i = j; i < nSize; i++ )
> > {
> > ////////////////////////////
> > // check if there is enough data to calculate average
> > // skip elsewhere
> > ////////////////////////////
> > if( i < j + nRange ) 
> > {
> > result.array[ i ] = EMPTY_VAL;
> > continue;
> > }
> > for( k = 0; k < nRange; k++ )
> > ////////////////////////////////
> > // calculate Stop
> > ////////////////////////////////
> > {
> > prev1=0;
> > prev2=0;
> > prev3=0;
> > 
> > (float) stop ;
> > if(L[i] < prev1)
> > (float) stop= SrcArray[i] - k ;
> > else
> > (float) stop= prev1;
> > if((SrcArray[i] - k) > prev2)
> > (float) stop= SrcArray[i] - k;
> > else
> > (float) stop=prev3;
> > 
> > prev3 = prev2;
> > prev2 = prev1;
> > prev1 = stop;
> > }
> > /////////////////////////////////
> > result.array[ i ] = (float) stop;
> > }
> > return result;
> > }