andrew oliveira - supertrend

Posted By: nanotir

andrew oliveira - supertrend - 11/22/15 11:41

Hi

I dont know if some of you is familiar with that indicador.
Does it work for you?
Can you post the script here?

I dont want to spend time coding it or playing with it if someone already tried to and it is workless.
Posted By: nanotir

Re: andrew oliveira - supertrend - 12/17/15 03:10

well... here is the code for it

Quote:
function run()
{
set(PLOTNOW);

StartDate = 20150101;
LookBack = 500;
BarPeriod = 30;
NumYears = 1;


PlotBars = 1000;

vars Price= series(price());

int factor =3;
int Period = 10;

TimeFrame = 1;

vars UpBand = series();
vars DnBand = series();
UpBand[0] = (priceHigh()+priceLow())/2 + factor*ATR(Period);
DnBand[0] = (priceHigh()+priceLow())/2 - factor*ATR(Period);

vars ST = series();
ST[0] = 0;

vars Direction = series();
Direction[0] = 1;//just to initialize

vars PriceC = series(priceClose());

// Begin Direction calculation
if ( PriceC[0] > UpBand[1] )
Direction[0] = 1;
else
if ( PriceC[0] < DnBand[1] )
Direction[0] = -1;
else
Direction[0] = Direction[1];
// End Direction calculation

// Begin SuperTrend calculation
if ( Direction[0] == 1 )
{
if ( DnBand[1] > DnBand[0] )
DnBand[0] = DnBand[1];

ST[0] = DnBand[0];
plot("ST",ST[0],0,GREEN);

}
else
if ( Direction[0] == -1 )
{
if ( UpBand[1] < UpBand[0] )
UpBand[0] = UpBand[1];

ST[0] = UpBand[0];
plot("ST2",ST[0],0,RED);
}
// End SuperTrend calculation


plot("ST3",ST[0],0,DARKGREEN);


}
Posted By: mey

Re: andrew oliveira - supertrend - 12/18/16 01:10

Hi Nanitek,

thanks a lot for sharing this code.
I would like to use it in function run() by call-by reference function call and also plot it from here.
But I fail miserably to declare the function.
The handing-over parameters from new function “Supertrend” should be “ST and color flag”.
In function run() I only receive the data by the call and I don’t know how the statement should like like, I always receive pointer errors.

function definition:
var Supertrend (vars ST, vars color)

call function in function run():
vars Super = series();
vars ST = series();
vars Color = series();
ST = series(Supertrend(Super[0]),Color());


Trading conditions (simplified):
if (priceClose() > ST)
enterLong();
else
enterShort();

Can you or somebody else help me as lite-C beginner?

Thanks again in advance.
© 2024 lite-C Forums