Skip to content

Instantly share code, notes, and snippets.

@Duk2
Created June 20, 2018 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Duk2/c1b34fb14f73745fc124d45baa7d9a0d to your computer and use it in GitHub Desktop.
Save Duk2/c1b34fb14f73745fc124d45baa7d9a0d to your computer and use it in GitHub Desktop.
toy example double true range
// Ejemplo de Duk2 para sistema con KASE DEVSTOP//
//*************************************************//
// Esto no es un sistema de trading operable, solo un ejemplo para implementar los dobles rangos verdaderos!!!//
//PARAMETROS
n = 20;
FastMAl= 5;
SlowMAl=21;
/* el rango verdadero toma el mayor valor absoluto entre:
- el rango de la vela( max - min)
- gap alcista
- gap bajista
Adaptado al doble true range*/
rango = Max(H-L, Ref(H,-1) - Ref(L,-1));
GA = Max(H - Ref(C,1), Ref(H,-1)- Ref(C ,-2));
GB = Max(abs(Ref(C,-1) - L), abs(Ref(C,-2) - Ref(L,-1)));
GAPs= IIf(GA > GB, GA, GB);
DTR = IIf (rango > GAPs, rango, GAPS);
LE = MA(DTR,n);
DEV1= MA(DTR,n) + 1* StDev (DTR,n);
DEV2= MA(DTR,n) + 2.2* StDev (DTR,n);
DEV3= MA(DTR,n) + 3.6* StDev (DTR,n);
//sistema cruce de medias básico - LONG ONLY//
FastMA = MA(C,FastMAl);
SlowMA = MA(C,SlowMAl);
BuySignal = FastMA > SlowMA;
Buy = BuySignal;
Sell= 0;
Short=Cover=0;
ApplyStop(stopTypeTrailing,
stopModePoint,
DEV3,2,
True );
Equity( 1);
//plots//
InTrade = Flip( Buy, Sell );
S_DEV3= IIf(InTrade,(HighestSince( Buy, High )- DEV3), Null);//HighestSince( Buy, High )- DEV3;
S_DEV2= IIf(InTrade,(HighestSince( Buy, High )- DEV2),Null);
S_DEV1= IIf(InTrade,(HighestSince( Buy, High )- DEV1),Null);
S_LE= IIf(InTrade,(HighestSince( Buy, High )- LE),Null);
Plot(S_DEV1,"DEV1",colorBlue,styleDashed);
Plot(S_DEV2,"DEV2",colorBlue,styleDashed);
Plot(S_DEV3,"DEV3",colorBlue,styleDashed);
Plot(S_LE,"DEV3",colorRed,styleDashed);
PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
/*plot separado
Plot(ATR(n),"ATR",colorBlack,styleHistogram);
Plot(LE, "linea estab",colorRed, styleLine);
Plot(DEV1,"DEV1",colorBlue,styleLine);
Plot(DEV2,"DEV2",colorBlue,styleLine);
Plot(DEV3,"DEV3",colorBlue,styleLine);*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment