You are on page 1of 33

/////////////////////////////////////////////

// //
// INDICADOR //
// E BACKTEST //
// SUPER_T //
// //
/////////////////////////////////////////////
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © rcarqurbanismo
// @version=4
//study("Variação do Range anterior", "RANGE01", overlay=true)
//indicator("RANGE01", overlay = true)
strategy("Super_T")

float linhac = 0
float linhav = 0
float linhar = 0
float linhat = 0
float totc = 0
float totv = 0
float lc = 0
float lv = 0
//float ltv = 0
//float ltc = 0
//float ltmarkup = 0
//float ltmarkdown = 0
float linha_entra_c = na
float linha_entra_v = na
float linha_entra = na

//var1 = ema(close,108)/ema(close,270)
//var2 = ema(close,270)/ema(close,540)
// original var1 = ema(ema(close,108)/ema(close,270),108)

var1 = ema(close,270)/ema(close,540)
var2 = ema(ema(close,270)/ema(close,540),108)

// INDICADOR RANGE01
range_long = 270
range_short = 54
range_super_short = 27

rb_high_long = highest(close,range_long)
rb_low_long = lowest(close,range_long)
//rb_open = open(close,range)
//rb_close = close(close,range)
rb_med_long = (rb_high_long+rb_low_long)/2

rb_high_short = highest(close,range_short)
rb_low_short = lowest(close,range_short)
//rb_open = open(close,range)
//rb_close = close(close,range)
rb_med_short = (rb_high_short+rb_low_short)/2

rb_high_super_short = highest(close,range_super_short)
rb_low_super_short = lowest(close,range_super_short)
rb_med_super_short = (rb_high_super_short+rb_low_super_short)/2
super_med = (ema((rb_med_short+rb_med_long)/2,270)/ema((rb_med_short+rb_med_long)/
2,540))*10000
super_med2 = (ema(
(ema((rb_med_short+rb_med_long)/2,270)/ema((rb_med_short+rb_med_long)/
2,540)) ,108))*10000
super_med3 = (ema(
(ema((rb_med_super_short+rb_med_short)/2,270)/ema((rb_med_short+rb_med_short)/
2,540)) ,54))*10000

// INDICADOR FR-02
tf = 32400
acel = (high-low)/tf
massa = (close-open)
forca = massa * acel

// INDICADOR FR-01
totc := valuewhen(forca > 0, (high+(massa*forca/100)), 0)
totv := valuewhen(forca < 0, (low-(massa*forca/100)), 0)
linhav := valuewhen(high > totc, high, 0)
linhac := valuewhen(low < totv, low, 0)
linhar := valuewhen(linhac > linhav, ((high+low)/2),0 )

//ltv := valuewhen(super_med2 > super_med3, 3, 0)


//ltc := valuewhen(super_med2 <= super_med3, 2, 0)

//ltv = super_med2 > super_med3


//ltc = super_med2 < super_med3

//ltmark = ltv ? ltc ? 1 : 2 : 3

lc := valuewhen (((close == low) and (open > close) and (high > open) and ((open-
close)>(high-open))), high, 0)
lv := valuewhen (((close == high) and (open < close) and (low < open) and ((close-
open)>(open-low))), low, 0)

cor = color.black
cor2 = color.orange
cor3 = color.black

// testa candle de fechamento


//barcolor( ((close == high) and (open < close) and (low < open) and ((close-
open)>(open-low))) ? (open < close) ? (open > close) ? color.orange : color.green :
color.red : color.black )
//barcolor( ((close == low) and (open > close) and (high > open) and ((open-
close)>(high-open))) ? color.green : na )
//barcolor( ((close == high) and (open < close) and (low < open) and ((close-
open)>(open-low))) ? color.red : na )

testa_v = ((close == high) and (open < close) and (low < open) and ((close-
open)>(open-low)))

linha = 1
ztc_linha = 0
ztv_linha = 0
//faixa = 1 // faixa com porcentagem de variação do dia

//ztc_linha = close
//ztv_linha = close

// ZONAS de compra
zt1 = var1 > 1
zt2 = var2 > 1
zt3 = var2 < var1
//ZONAS de venda
zt4 = var1 < 1
zt5 = var2 < 1
zt6 = var2 > var1

linha_compra = zt1 ? zt2 ? zt3 ? 1 : 2 : 3 : 4


linha_venda = zt4 ? zt5 ? zt6 ? 1 : 2 : 3 : 4
//hora_abre = hour==18 and minute == 00
// testa cor

// ORIGINAIS
long = linha_compra == 2
short = linha_venda == 2

// ANTECIPAÇÃO DE ENTRADA
//long = linha_compra == 3
//short = linha_venda == 3

lote = 1.0

strategy.entry("ZT-Compra", strategy.long, lote, when = short )


strategy.entry("ZT-Venda", strategy.short, lote, when = long )

//strategy.exit("Saída_Compra", "Compra", profit = 500, loss = 1000)


//strategy.exit("Saída_Venda", "Venda", profit = 500, loss = 1000)

//strategy.close("ZT-Compra", when = long)


//strategy.close("ZT-Venda", when = short)

//labeltext = ""
//labeltextztcompra = "ZT-COMPRA"
//labeltextztvenda = "ZT-VENDA"

//ourLabel = label.new(x=bar_index, y=na, text=labeltext, yloc=yloc.belowbar,


color=color.green, textcolor=color.white, style=label.style_label_up,
size=size.normal)

// ORIGINAIS
//ztc_linha := valuewhen(linha_compra == 1, bar_index, 0)
//ztv_linha := valuewhen(linha_venda == 1, bar_index, 0)

// ANTECIPAÇÃO DE ENTRADA
ztc_linha := valuewhen(linha_compra == 1, bar_index, 0)
ztv_linha := valuewhen(linha_venda == 1, bar_index, 0)

ltmarkup = if(crossover(super_med2, super_med3))


1

ltmarkdown = if(crossover(super_med3, super_med2))


1

linha_entra_v_barra = valuewhen(ltmarkup, bar_index, 0)


linha_entra_v_valor = valuewhen(ltmarkup, close, 0)
linha_entra_c_barra = valuewhen(ltmarkdown, bar_index, 0)
linha_entra_c_valor = valuewhen(ltmarkdown, close, 0)

barra_linha_venda = line.new(linha_entra_v_barra, linha_entra_v_valor, bar_index,


linha_entra_v_valor, color = color.green, extend = extend.right, style =
line.style_dashed)
barra_linha_compra = line.new(linha_entra_c_barra, linha_entra_c_valor, bar_index,
linha_entra_c_valor, color = color.red, extend = extend.right, style =
line.style_dashed)

///
if (ltmarkup == 1)
cor3 := color.red
linha_entra := close

if (ltmarkdown == 1)
cor3 := color.green
linha_entra := close

//ZT
if (linha_compra == 1)
cor := color.blue
linha := 4
//ourLabel := label.new(x=bar_index, y=na, text=labeltextztcompra,
yloc=yloc.belowbar, color=color.blue, textcolor=color.white,
style=label.style_label_up, size=size.normal)

if (linha_venda == 1)
cor := color.red
linha := 4
//ourLabel := label.new(x=bar_index, y=na, text=labeltextztvenda,
yloc=yloc.belowbar, color=color.red, textcolor=color.white,
style=label.style_label_up, size=size.normal)

//ZMT
if (linha_compra == 2)
cor := color.red

if (linha_venda == 2)
cor := color.blue

//ZR
if (linha_compra == 3)
// original cor := color.yellow
cor := color.blue

if (linha_venda == 3)
// originalcor := color.yellow
cor := color.red
// EMAS
//plot(ema(close,216),"",color.green )
//plot(ema(close,108),"",color.red )
plot(ema(close,270),"",color=cor, linewidth = 4)

plot(linhar, "", color.orange)

// lc e lv
//plot(lc, "", color.blue) //, linewidth = 2)
//plot(lv, "", color.purple) //, linewidth = 2)
plot(linha_entra, "", color = cor3, linewidth = 1)
//plot(ltmarkup, "", color.black)
//plot(ltmarkdown, "", color.black)
//plot(ltv, "", color.black)
//plot(ltc, "", color.black)

// PLOTA RANGE
//plot(close, "", color.black)

plot(rb_high_long, "", color.green, linewidth = 2)


plot(rb_low_long, "", color.red, linewidth = 2)
plot(rb_high_short, "", color.green)
plot(rb_low_short, "", color.red)
plot(rb_high_super_short, "", color.green)
plot(rb_low_super_short, "", color.red)

//plot(ltv, "", color.red,4)


//plot(ltc, "", color.green, 4)

//plot(super_med*1000, "", color.black)


plot(super_med2, "", color.blue)
plot(super_med3, "", color.red)
//plot(1/super_med, "", color.red)
//plot(1/super_med2, "", color.orange)
//plot(1/super_med3, "", color.blue)

///////////////////////////////////////////////////////////////////
// //
// SUPER TENDÊNCIA //
// T07 //
// //
///////////////////////////////////////////////////////////////////
var

//ABAIXO
media_k_abaixo : float;
i480_abaixo : integer;
fech_hoje_k_abaixo : float;
min_480_abaixo : float;
max_480_abaixo : float;

//ponto_480 : float;
teste_k_abaixo : float;

//ACIMA
media_k_acima : float;
i480_acima : integer;
fech_hoje_k_acima : float;
min_480_acima : float;
max_480_acima : float;

//ponto_480 : float;
teste_k_acima : float;

sma_med : float;
sma_v : float;
sma_c : float;
sma_v1 : float;
sma_c1 : float;

// SUPER_T06
sma1 : float;
sma2 : float;
fc : float;
fv : float;
spread : float;
sto1 : float;
sto2 : float;
sto3 : float;
cor_vermelho : integer;
zt : float;
op_c : float;
op_v : float;

//MEDIA
smavar_acima : float;
smavar_abaixo : float;

begin
//ABAIXO
i480_abaixo:=0;
for i480_abaixo := 1 to 480 do
fech_hoje_k_abaixo := close[i480_abaixo];
min_480_abaixo := lowest(close, i480_abaixo);
max_480_abaixo := highest(close, i480_abaixo);
if (max_480_abaixo-min_480_abaixo) = 0 then teste_k_abaixo := 0 else
teste_k_abaixo := -1*((((slowstochastic(480)/100))*1/(max_480_abaixo-
min_480_abaixo))-min_480_abaixo);

//smavar_abaixo :=
((teste_k_abaixo+teste_l_abaixo+teste_m_abaixo+teste_n_abaixo)/4);

//ACIMA
i480_acima:=0;
for i480_acima := 1 to 480 do
fech_hoje_k_acima := close[i480_acima];
min_480_acima := highest(close, i480_acima);
max_480_acima := lowest(close, i480_acima);
if (max_480_acima-min_480_acima) = 0 then teste_k_acima := 0 else
teste_k_acima := -1*((((slowstochastic(480)/100))*1/(max_480_acima-min_480_acima))-
min_480_acima);

//smavar_acima := ((teste_k_acima+teste_l_acima+teste_m_acima+teste_n_acima)/4);

//if (teste_k_acima+teste_k_abaixo) <> 0 then


plot( ((smavar_acima+smavar_abaixo)/2) / ((teste_k_acima+teste_k_abaixo)/2));
sma_med := ((teste_k_abaixo+teste_k_acima)/2);
sma_v := (sma_med-(minima-teste_k_abaixo));
sma_c := (sma_med+(teste_k_acima-maxima));
sma_v1 := ((sma_med/sma_v)/(media(54,((sma_med/sma_v)+2-((sma_med/sma_c)))/2)));
sma_c1 := ((2-(sma_med/sma_c)) /
(media(54,((sma_med/sma_v)+2-((sma_med/sma_c)))/2)));
//if (teste_k_acima - close) < (close - teste_k_abaixo) then paintbar(clteal)
else paintbar(clred);

plot(1);
//plot2(media(108,sma_v1));
//plot3(media(108,sma_c1));
plot4(media(270,sma_v1));
plot5(media(270,sma_c1));
//plot6(media(18,sma_v1));
//plot7(media(18,sma_c1));
plot8(media(54,sma_v1));
plot9(media(54,sma_c1));
//plot10(sma_v1);
//plot11(sma_c1);

end;

///////////////////////////////////////////////////////////////////
// //
// SUPER TENDÊNCIA //
// T06 //
// //
///////////////////////////////////////////////////////////////////
var

sma1 : float;
sma2 : float;
fc : float;
fv : float;
spread : float;
sto1 : float;
sto2 : float;
sto3 : float;
cor_vermelho : integer;
zt : float;
op_c : float;
op_v : float;

begin

//sma1 := ema(close,270)/ema(close,540);
if (media(270,close)<>0) and (media(540,close)<>0) then sma1 :=
(media(270,close)/media(540,close));
//sma2 := ema(ema(close,270)/ema(close,540),108);
if (media(108,sma1))<>0 then sma2 := media(108,sma1);
if (SlowStochastic(108) <> 0) and (SlowStochastic(270) <> 0) then sto1 :=
SlowStochastic(108)/SlowStochastic(270);
if (SlowStochastic(270) <> 0) and (SlowStochastic(540) <> 0)then sto2 :=
SlowStochastic(270)/SlowStochastic(540);
if (SlowStochastic(18) <> 0) and (SlowStochastic(36) <> 0) then sto3 :=
SlowStochastic(18)/SlowStochastic(36);

plot(sma1);
plot2(sma2);
plot3(1);

cor_vermelho := rgb(255, 128, 128);


zt := ((sto1+sto2)/2);

if zt < 1 then
begin;
setplotcolor(4,clteal);
setplotcolor(5,clteal);
setplotcolor(6,clteal);
end;

if zt > 1 then
begin;
setplotcolor(4,cor_vermelho);
setplotcolor(5,cor_vermelho);
setplotcolor(6,cor_vermelho);
end;

spread := 3000;
// ZT - ZONA DE TRADING
// zt - compra
if (sma1 >= 1) and (sma2 >= 1) and (sma1 > sma2) and (op_c = 1) then
begin;
fv := 0;
paintbar(clblue);
setplotcolor(2,clblue);
if not isbought then
begin;
buystop(high, high);
op_c := 1;
op_v := 0;
end;
//if (isbought) and (close >= buyprice+spread) then //or (close <= buyprice-
spread) then
// begin;
// op_c := 0;
// selltocoverstop(close, close);
// end;
end;

// zt - venda
if (sma1 <= 1) and (sma2 <= 1) and (sma1 < sma2) and (op_v = 1) then
begin;
fc := 0;
setplotcolor(2,clred);
paintbar(clred);
if not issold then
begin;
sellshortstop(low, low);
op_v := 1;
op_c := 0;
end;
//if issold and ((close <= sellprice-spread)) then //or ((close >=
sellprice+spread)) then
// begin;
// op_v := 0;
// buytocoverstop(close, close);
// end;
end;

//ZMT - ZONA DE MITIGAÇÃO


//zmt - inferior
if (sma1 < 1) and (sma2 < 1) and (sma1 > sma2) then
begin;
paintbar(clblack);
op_v := 0;
op_c := 1;
buytocoverstop(close, close);
end;

// zt - superior
if (sma1 > 1) and (sma2 > 1) and (sma1 < sma2) then
begin;
paintbar(clblack);
op_c := 0;
op_v := 1;
selltocoverstop(close, close);
end;

end;

///////////////////////////////////////////////////////////////////
// //
// SUPER TENDÊNCIA //
// T05 //
// //
///////////////////////////////////////////////////////////////////
var

sma1 : float;
sma2 : float;
fc : float;
fv : float;
spread : float;

sto1 : float;
sto2 : float;
sto3 : float;
cor_vermelho : integer;

zt : float;

//plot(ema(close,108)/ema(close,270), "", color.blue)


//plot(ema(ema(close,108)/ema(close,270),108), "", color.red, 2)
//plot(ema(ema(close,270)/ema(close,540),108));
//plot(1.01, "", color.gray)
//plot(1.02, "", color.gray)
//plot(1.03, "", color.gray)
//plot(1, "", color.black,2)
//plot(0.99, "", color.gray)
//plot(0.98, "", color.gray)
//plot(0.97, "", color.gray)

begin

//sma1 := ema(close,270)/ema(close,540);
if (media(270,close)<>0) and (media(540,close)<>0) then sma1 :=
(media(270,close)/media(540,close));
//sma2 := ema(ema(close,270)/ema(close,540),108);
if (media(108,sma1))<>0 then sma2 := media(108,sma1);

if (SlowStochastic(108) <> 0) and (SlowStochastic(270) <> 0) then sto1 :=


SlowStochastic(108)/SlowStochastic(270);
if (SlowStochastic(270) <> 0) and (SlowStochastic(540) <> 0)then sto2 :=
SlowStochastic(270)/SlowStochastic(540);
if (SlowStochastic(18) <> 0) and (SlowStochastic(36) <> 0) then sto3 :=
SlowStochastic(18)/SlowStochastic(36);
//plot(sma1);
//plot2(sma2);
plot3(1);
plot7(sto3);
plot8(1.5);
plot9(0.5);

cor_vermelho := rgb(255, 128, 128);


zt := ((sto1+sto2)/2);

if zt < 1 then
begin;
setplotcolor(4,clteal);
setplotcolor(5,clteal);
setplotcolor(6,clteal);
end;
if zt > 1 then
begin;
setplotcolor(4,cor_vermelho);
setplotcolor(5,cor_vermelho);
setplotcolor(6,cor_vermelho);
end;

plot4(media(36 , ((sto1+sto2)/2)));
plot5(media(540, ((sto1+sto2)/2)));
plot6(media(792, ((sto1+sto2)/2)));

spread := 1000;
// ZT - ZONA DE TRADING
// zt - compra
if (sma1 >= 1) and (sma2 >= 1) and (sma1 > sma2) then
begin;
//plot4(linha_op);
fv := 0;
paintbar(clblue);
//setplotcolor(12,clblue);
setplotcolor(2,clblue);

//if fc = 0 then
// begin;
// buystop(high, high);
// fc := 1;
//linha_op := sma270;
//setplotcolor(4,clblue);
// end;
if not isbought then buystop(high, high)
else if isbought then
begin;
if (close >= buyprice+spread) then selltocoverstop(close, close);
if (close <= buyprice-spread) then selltocoverstop(close, close);
end;

end;

// zt - venda
if (sma1 <= 1) and (sma2 <= 1) and (sma1 < sma2) then
begin;
//plot4(linha_op);
fc := 0;
setplotcolor(2,clred);
paintbar(clred);
//setplotcolor(12,clred);

// cor 255,128,128

//if fv = 0 then
// begin;
// sellshortstop(low, low);
// fv := 1;
//linha_op := sma270;
//setplotcolor(4,clred);
//end;
if not issold then sellshortstop(low, low)
else if issold then
begin;
if (close <= sellprice-spread) then buytocoverstop(close, close);
if (close >= sellprice+spread) then buytocoverstop(close, close);
end;
end;

//ZMT - ZONA DE MITIGAÇÃO


//zmt - inferior
if (sma1 < 1) and (sma2 < 1) and (sma1 > sma2) then
begin;
paintbar(clblack);
//setplotcolor(12,clyellow);
//setplotcolor(13,clyellow);
if isbought or issold then closeposition;
//fv := 0;
//fc := 0;
end;
// zt - superior
if (sma1 > 1) and (sma2 > 1) and (sma1 < sma2) then
begin;
paintbar(clblack);
//setplotcolor(12,clyellow);
//setplotcolor(13,clyellow);
if isbought or issold then closeposition;
//fc := 0;
//fv := 0;
end;
end;

///////////////////////////////////////////////////////////////////
// //
// SUPER TENDÊNCIA //
// T04 //
// //
///////////////////////////////////////////////////////////////////
var

//SMAVAR03
sma108 : float;
sma270 : float;
smamax : float;
smamin : float;
linha_c : float;
linha_v : float;
fc : integer;
fv : integer;
spread : integer;
linha_op : float;

//ABAIXO
media_k_abaixo : float;
media_l_abaixo : float;
media_m_abaixo : float;
media_n_abaixo : float;
i480_abaixo : integer;
i108_abaixo : integer;
i54_abaixo : integer;
i21_abaixo : integer;

fech_hoje_k_abaixo : float;
fech_hoje_l_abaixo : float;
fech_hoje_m_abaixo : float;
fech_hoje_n_abaixo : float;

min_480_abaixo : float;
max_480_abaixo : float;
min_108_abaixo : float;
max_108_abaixo : float;
min_54_abaixo : float;
max_54_abaixo : float;
min_21_abaixo : float;
max_21_abaixo : float;

//ponto_480 : float;
teste_k_abaixo : float;
teste_l_abaixo : float;
teste_m_abaixo : float;
teste_n_abaixo : float;

spread_abaixo : float;

//ACIMA
media_k_acima : float;
media_l_acima : float;
media_m_acima : float;
media_n_acima : float;
i480_acima : integer;
i108_acima : integer;
i54_acima : integer;
i21_acima : integer;

fech_hoje_k_acima : float;
fech_hoje_l_acima : float;
fech_hoje_m_acima : float;
fech_hoje_n_acima : float;

min_480_acima : float;
max_480_acima : float;
min_108_acima : float;
max_108_acima : float;
min_54_acima : float;
max_54_acima : float;
min_21_acima : float;
max_21_acima : float;

//ponto_480 : float;
teste_k_acima : float;
teste_l_acima : float;
teste_m_acima : float;
teste_n_acima : float;

spread_acima : float;

//MEDIA

smavar_acima : float;
smavar_abaixo : float;

begin
//ABAIXO
i480_abaixo:=0;
for i480_abaixo := 1 to 480 do
fech_hoje_k_abaixo := close[i480_abaixo];
min_480_abaixo := lowest(close, i480_abaixo);
max_480_abaixo := highest(close, i480_abaixo);
if (max_480_abaixo-min_480_abaixo) = 0 then teste_k_abaixo := 0 else
teste_k_abaixo := -1*((((slowstochastic(480)/100))*1/(max_480_abaixo-
min_480_abaixo))-min_480_abaixo);

i108_abaixo:=0;
for i108_abaixo := 1 to 108 do
fech_hoje_l_abaixo := close[i108_abaixo];
min_108_abaixo := lowest(close, i108_abaixo);
max_108_abaixo := highest(close, i108_abaixo);
if (max_108_abaixo-min_108_abaixo) = 0 then teste_l_abaixo := 0 else
teste_l_abaixo := -1*(((slowstochastic(108)/100)*1/(max_108_abaixo-
min_108_abaixo))-min_108_abaixo);

i54_abaixo:=0;
for i54_abaixo := 1 to 54 do
fech_hoje_m_abaixo := close[i54_abaixo];
min_54_abaixo := lowest(close, i54_abaixo);
max_54_abaixo := highest(close, i54_abaixo);
if (max_54_abaixo-min_54_abaixo) = 0 then teste_m_abaixo := 0 else
teste_m_abaixo := -1*(((slowstochastic(54)/100)*1/(max_54_abaixo-min_54_abaixo))-
min_54_abaixo);

i21_abaixo:=0;
for i21_abaixo := 1 to 21 do
fech_hoje_n_abaixo := close[i21_abaixo];
min_21_abaixo := lowest(close, i21_abaixo);
max_21_abaixo := highest(close, i21_abaixo);
if (max_21_abaixo-min_21_abaixo) = 0 then teste_n_abaixo := 0 else
teste_n_abaixo := -1*(((slowstochastic(21)/100)*1/(max_21_abaixo-min_21_abaixo))-
min_21_abaixo);

smavar_abaixo :=
((teste_k_abaixo+teste_l_abaixo+teste_m_abaixo+teste_n_abaixo)/4);

//ACIMA
i480_acima:=0;
for i480_acima := 1 to 480 do
fech_hoje_k_acima := close[i480_acima];
min_480_acima := highest(close, i480_acima);
max_480_acima := lowest(close, i480_acima);
if (max_480_acima-min_480_acima) = 0 then teste_k_acima := 0 else
teste_k_acima := -1*((((slowstochastic(480)/100))*1/(max_480_acima-min_480_acima))-
min_480_acima);

i108_acima:=0;
for i108_acima := 1 to 108 do
fech_hoje_l_acima := close[i108_acima];
min_108_acima := highest(close, i108_acima);
max_108_acima := lowest(close, i108_acima);
if (max_108_acima-min_108_acima) = 0 then teste_l_acima := 0 else
teste_l_acima := -1*(((slowstochastic(108)/100)*1/(max_108_acima-min_108_acima))-
min_108_acima);

i54_acima:=0;
for i54_acima := 1 to 54 do
fech_hoje_m_acima := close[i54_acima];
min_54_acima := highest(close, i54_acima);
max_54_acima := lowest(close, i54_acima);
if (max_54_acima-min_54_acima) = 0 then teste_m_acima := 0 else teste_m_acima
:= -1*(((slowstochastic(54)/100)*1/(max_54_acima-min_54_acima))-min_54_acima);

i21_acima:=0;
for i21_acima := 1 to 21 do
fech_hoje_n_acima := close[i21_acima];
min_21_acima := highest(close, i21_acima);
max_21_acima := lowest(close, i21_acima);
if (max_21_acima-min_21_acima) = 0 then teste_n_acima := 0 else teste_n_acima
:= -1*(((slowstochastic(21)/100)*1/(max_21_acima-min_21_acima))-min_21_acima);

//MEDIA
smavar_acima := ((teste_k_acima+teste_l_acima+teste_m_acima+teste_n_acima)/4);

if (teste_k_acima+teste_k_abaixo) <> 0 then


begin;
plot( ((smavar_acima+smavar_abaixo)/2) /
((teste_k_acima+teste_k_abaixo)/2));
plot2(
((teste_k_acima+teste_k_abaixo)/2)/((smavar_acima+smavar_abaixo)/2));
end;
plot11(1);

//if (year(date)>=2022) then // APENAS PARA O BACKTEST


//begin;
if (mediaexp(270,close)) <> 0 then sma108 := mediaexp(108,close) /
mediaexp(270,close);
if (mediaexp(540,close)) <> 0 then sma270 := mediaexp(270,close) /
mediaexp(540,close);
//end;
plot12(sma108);
plot13(sma270); //SINAL

spread := 1000;
// ZT - ZONA DE TRADING
// zt - compra
if (sma270 >= 1) and (sma108 >= 1) and (sma270 < sma108) then
begin;
//plot4(linha_op);
fv := 0;
paintbar(clblue);
//setplotcolor(12,clblue);
setplotcolor(13,clblue);
//if fc = 0 then
// begin;
// buystop(high, high);
// fc := 1;
//linha_op := sma270;
//setplotcolor(4,clblue);
// end;
if not isbought then buystop(high, high)
else if isbought then
begin;
if (close >= buyprice+spread) then selltocoverstop(close, close);
if (close <= buyprice-spread) then selltocoverstop(close, close);
end;

end;
// zt - venda
if (sma270 <= 1) and (sma108 <= 1) and (sma270 > sma108) then
begin;
//plot4(linha_op);
fc := 0;
paintbar(clred);
//setplotcolor(12,clred);
setplotcolor(13,clred);
//if fv = 0 then
// begin;
// sellshortstop(low, low);
// fv := 1;
//linha_op := sma270;
//setplotcolor(4,clred);
//end;
if not issold then sellshortstop(low, low)
else if issold then
begin;
if (close <= sellprice-spread) then buytocoverstop(close, close);
if (close >= sellprice+spread) then buytocoverstop(close, close);
end;
end;

//ZMT - ZONA DE MITIGAÇÃO


//zmt - inferior
if (sma270 < 1) and (sma108 < 1) and (sma270 < sma108) then
begin;
paintbar(clyellow);
//setplotcolor(12,clyellow);
//setplotcolor(13,clyellow);
if isbought or issold then closeposition;
//fv := 0;
//fc := 0;
end;
// zt - superior
if (sma270 > 1) and (sma108 > 1) and (sma270 > sma108) then
begin;
paintbar(clyellow);
//setplotcolor(12,clyellow);
//setplotcolor(13,clyellow);
if isbought or issold then closeposition;
//fc := 0;
//fv := 0;
end;
end;

///////////////////////////////////////////////////////////////////
// //
// SUPER TENDÊNCIA //
// T03 //
// //
///////////////////////////////////////////////////////////////////
var

//SMAVAR03
sma108 : float;
sma270 : float;
smamax : float;
smamin : float;
linha_c : float;
linha_v : float;
fc : integer;
fv : integer;
spread : integer;
linha_op : float;

//ABAIXO
media_k_abaixo : float;
media_l_abaixo : float;
media_m_abaixo : float;
media_n_abaixo : float;
i480_abaixo : integer;
i108_abaixo : integer;
i54_abaixo : integer;
i21_abaixo : integer;

fech_hoje_k_abaixo : float;
fech_hoje_l_abaixo : float;
fech_hoje_m_abaixo : float;
fech_hoje_n_abaixo : float;

min_480_abaixo : float;
max_480_abaixo : float;
min_108_abaixo : float;
max_108_abaixo : float;
min_54_abaixo : float;
max_54_abaixo : float;
min_21_abaixo : float;
max_21_abaixo : float;

//ponto_480 : float;
teste_k_abaixo : float;
teste_l_abaixo : float;
teste_m_abaixo : float;
teste_n_abaixo : float;

spread_abaixo : float;

//ACIMA
media_k_acima : float;
media_l_acima : float;
media_m_acima : float;
media_n_acima : float;
i480_acima : integer;
i108_acima : integer;
i54_acima : integer;
i21_acima : integer;

fech_hoje_k_acima : float;
fech_hoje_l_acima : float;
fech_hoje_m_acima : float;
fech_hoje_n_acima : float;
min_480_acima : float;
max_480_acima : float;
min_108_acima : float;
max_108_acima : float;
min_54_acima : float;
max_54_acima : float;
min_21_acima : float;
max_21_acima : float;

//ponto_480 : float;
teste_k_acima : float;
teste_l_acima : float;
teste_m_acima : float;
teste_n_acima : float;

spread_acima : float;

//MEDIA

smavar_acima : float;
smavar_abaixo : float;

begin
//ABAIXO
i480_abaixo:=0;
for i480_abaixo := 1 to 480 do
fech_hoje_k_abaixo := close[i480_abaixo];
min_480_abaixo := lowest(close, i480_abaixo);
max_480_abaixo := highest(close, i480_abaixo);
if (max_480_abaixo-min_480_abaixo) = 0 then teste_k_abaixo := 0 else
teste_k_abaixo := -1*((((slowstochastic(480)/100))*1/(max_480_abaixo-
min_480_abaixo))-min_480_abaixo);

i108_abaixo:=0;
for i108_abaixo := 1 to 108 do
fech_hoje_l_abaixo := close[i108_abaixo];
min_108_abaixo := lowest(close, i108_abaixo);
max_108_abaixo := highest(close, i108_abaixo);
if (max_108_abaixo-min_108_abaixo) = 0 then teste_l_abaixo := 0 else
teste_l_abaixo := -1*(((slowstochastic(108)/100)*1/(max_108_abaixo-
min_108_abaixo))-min_108_abaixo);

i54_abaixo:=0;
for i54_abaixo := 1 to 54 do
fech_hoje_m_abaixo := close[i54_abaixo];
min_54_abaixo := lowest(close, i54_abaixo);
max_54_abaixo := highest(close, i54_abaixo);
if (max_54_abaixo-min_54_abaixo) = 0 then teste_m_abaixo := 0 else
teste_m_abaixo := -1*(((slowstochastic(54)/100)*1/(max_54_abaixo-min_54_abaixo))-
min_54_abaixo);

i21_abaixo:=0;
for i21_abaixo := 1 to 21 do
fech_hoje_n_abaixo := close[i21_abaixo];
min_21_abaixo := lowest(close, i21_abaixo);
max_21_abaixo := highest(close, i21_abaixo);
if (max_21_abaixo-min_21_abaixo) = 0 then teste_n_abaixo := 0 else
teste_n_abaixo := -1*(((slowstochastic(21)/100)*1/(max_21_abaixo-min_21_abaixo))-
min_21_abaixo);
smavar_abaixo :=
((teste_k_abaixo+teste_l_abaixo+teste_m_abaixo+teste_n_abaixo)/4);

//ACIMA
i480_acima:=0;
for i480_acima := 1 to 480 do
fech_hoje_k_acima := close[i480_acima];
min_480_acima := highest(close, i480_acima);
max_480_acima := lowest(close, i480_acima);
if (max_480_acima-min_480_acima) = 0 then teste_k_acima := 0 else
teste_k_acima := -1*((((slowstochastic(480)/100))*1/(max_480_acima-min_480_acima))-
min_480_acima);

i108_acima:=0;
for i108_acima := 1 to 108 do
fech_hoje_l_acima := close[i108_acima];
min_108_acima := highest(close, i108_acima);
max_108_acima := lowest(close, i108_acima);
if (max_108_acima-min_108_acima) = 0 then teste_l_acima := 0 else
teste_l_acima := -1*(((slowstochastic(108)/100)*1/(max_108_acima-min_108_acima))-
min_108_acima);

i54_acima:=0;
for i54_acima := 1 to 54 do
fech_hoje_m_acima := close[i54_acima];
min_54_acima := highest(close, i54_acima);
max_54_acima := lowest(close, i54_acima);
if (max_54_acima-min_54_acima) = 0 then teste_m_acima := 0 else teste_m_acima
:= -1*(((slowstochastic(54)/100)*1/(max_54_acima-min_54_acima))-min_54_acima);

i21_acima:=0;
for i21_acima := 1 to 21 do
fech_hoje_n_acima := close[i21_acima];
min_21_acima := highest(close, i21_acima);
max_21_acima := lowest(close, i21_acima);
if (max_21_acima-min_21_acima) = 0 then teste_n_acima := 0 else teste_n_acima
:= -1*(((slowstochastic(21)/100)*1/(max_21_acima-min_21_acima))-min_21_acima);

//MEDIA
smavar_acima := ((teste_k_acima+teste_l_acima+teste_m_acima+teste_n_acima)/4);

if (teste_k_acima+teste_k_abaixo) <> 0 then


plot( ((smavar_acima+smavar_abaixo)/2) / ((teste_k_acima+teste_k_abaixo)/2));

plot11(1);

//if (year(date)>=2022) then // APENAS PARA O BACKTEST


//begin;
if (mediaexp(270,close)) <> 0 then sma108 := mediaexp(108,close) /
mediaexp(270,close);
if (mediaexp(540,close)) <> 0 then sma270 := mediaexp(270,close) /
mediaexp(540,close);
//end;
plot12(sma108);
plot13(sma270); //SINAL

spread := 1000;
// ZT - ZONA DE TRADING
// zt - compra
if (sma270 >= 1) and (sma108 >= 1) and (sma270 < sma108) then
begin;
//plot4(linha_op);
fv := 0;
paintbar(clblue);
//setplotcolor(12,clblue);
setplotcolor(13,clblue);
//if fc = 0 then
// begin;
// buystop(high, high);
// fc := 1;
//linha_op := sma270;
//setplotcolor(4,clblue);
// end;
if not isbought then buystop(high, high)
else if isbought then
begin;
if (close >= buyprice+spread) then selltocoverstop(close, close);
if (close <= buyprice-spread) then selltocoverstop(close, close);
end;

end;

// zt - venda
if (sma270 <= 1) and (sma108 <= 1) and (sma270 > sma108) then
begin;
//plot4(linha_op);
fc := 0;
paintbar(clred);
//setplotcolor(12,clred);
setplotcolor(13,clred);
//if fv = 0 then
// begin;
// sellshortstop(low, low);
// fv := 1;
//linha_op := sma270;
//setplotcolor(4,clred);
//end;
if not issold then sellshortstop(low, low)
else if issold then
begin;
if (close <= sellprice-spread) then buytocoverstop(close, close);
if (close >= sellprice+spread) then buytocoverstop(close, close);
end;
end;

//ZMT - ZONA DE MITIGAÇÃO


//zmt - inferior
if (sma270 < 1) and (sma108 < 1) and (sma270 < sma108) then
begin;
paintbar(clyellow);
//setplotcolor(12,clyellow);
//setplotcolor(13,clyellow);
if isbought or issold then closeposition;
//fv := 0;
//fc := 0;
end;
// zt - superior
if (sma270 > 1) and (sma108 > 1) and (sma270 > sma108) then
begin;
paintbar(clyellow);
//setplotcolor(12,clyellow);
//setplotcolor(13,clyellow);
if isbought or issold then closeposition;
//fc := 0;
//fv := 0;
end;
end;

///////////////////////////////////////////////////////////////////
// //
// SUPER TENDÊNCIA //
// T02 //
// //
///////////////////////////////////////////////////////////////////
var

//SMAVAR03
sma108 : float;
sma270 : float;
smamax : float;
smamin : float;
linha_c : float;
linha_v : float;
fc : integer;
fv : integer;
spread : integer;
linha_op : float;

//ABAIXO
media_k_abaixo : float;
media_l_abaixo : float;
media_m_abaixo : float;
media_n_abaixo : float;
i480_abaixo : integer;
i108_abaixo : integer;
i54_abaixo : integer;
i21_abaixo : integer;

fech_hoje_k_abaixo : float;
fech_hoje_l_abaixo : float;
fech_hoje_m_abaixo : float;
fech_hoje_n_abaixo : float;

min_480_abaixo : float;
max_480_abaixo : float;
min_108_abaixo : float;
max_108_abaixo : float;
min_54_abaixo : float;
max_54_abaixo : float;
min_21_abaixo : float;
max_21_abaixo : float;

//ponto_480 : float;
teste_k_abaixo : float;
teste_l_abaixo : float;
teste_m_abaixo : float;
teste_n_abaixo : float;

spread_abaixo : float;

//ACIMA
media_k_acima : float;
media_l_acima : float;
media_m_acima : float;
media_n_acima : float;
i480_acima : integer;
i108_acima : integer;
i54_acima : integer;
i21_acima : integer;

fech_hoje_k_acima : float;
fech_hoje_l_acima : float;
fech_hoje_m_acima : float;
fech_hoje_n_acima : float;

min_480_acima : float;
max_480_acima : float;
min_108_acima : float;
max_108_acima : float;
min_54_acima : float;
max_54_acima : float;
min_21_acima : float;
max_21_acima : float;

//ponto_480 : float;
teste_k_acima : float;
teste_l_acima : float;
teste_m_acima : float;
teste_n_acima : float;

spread_acima : float;

//MEDIA

smavar_acima : float;
smavar_abaixo : float;

begin
//ABAIXO
i480_abaixo:=0;
for i480_abaixo := 1 to 480 do
fech_hoje_k_abaixo := close[i480_abaixo];
min_480_abaixo := lowest(close, i480_abaixo);
max_480_abaixo := highest(close, i480_abaixo);
//media_k := (fech_hoje_k-min_480)/(max_480-min_480)*100;
//teste_k := -1*(((slowstochastic(480)/100)*(max_480-min_480))-min_480);
if (max_480_abaixo-min_480_abaixo) = 0 then teste_k_abaixo := 0 else
teste_k_abaixo := -1*((((slowstochastic(480)/100))*1/(max_480_abaixo-
min_480_abaixo))-min_480_abaixo);
i108_abaixo:=0;
for i108_abaixo := 1 to 108 do
fech_hoje_l_abaixo := close[i108_abaixo];
min_108_abaixo := lowest(close, i108_abaixo);
max_108_abaixo := highest(close, i108_abaixo);
//media_l := (fech_hoje_l-min_108)/(max_108-min_108)*100;
//teste_l := -1*(((slowstochastic(108)/100)*(max_108-min_108))-min_108);
if (max_108_abaixo-min_108_abaixo) = 0 then teste_l_abaixo := 0 else
teste_l_abaixo := -1*(((slowstochastic(108)/100)*1/(max_108_abaixo-
min_108_abaixo))-min_108_abaixo);

i54_abaixo:=0;
for i54_abaixo := 1 to 54 do
//for i54 := 1 to 54 do
fech_hoje_m_abaixo := close[i54_abaixo];
min_54_abaixo := lowest(close, i54_abaixo);
max_54_abaixo := highest(close, i54_abaixo);
//media_m := (fech_hoje_m-min_54)/(max_54-min_54)*100;
//teste_m := -1*(((slowstochastic(54)/100)*(max_54-min_54))-min_54);
if (max_54_abaixo-min_54_abaixo) = 0 then teste_m_abaixo := 0 else
teste_m_abaixo := -1*(((slowstochastic(54)/100)*1/(max_54_abaixo-min_54_abaixo))-
min_54_abaixo);

i21_abaixo:=0;
for i21_abaixo := 1 to 21 do
//for i21 := 1 to 21 do
fech_hoje_n_abaixo := close[i21_abaixo];
min_21_abaixo := lowest(close, i21_abaixo);
max_21_abaixo := highest(close, i21_abaixo);
//media_n := (fech_hoje_n-min_21)/(max_21-min_21)*100;
//teste_n := -1*(((slowstochastic(21)/100)*(max_21-min_21))-min_21);
if (max_21_abaixo-min_21_abaixo) = 0 then teste_n_abaixo := 0 else
teste_n_abaixo := -1*(((slowstochastic(21)/100)*1/(max_21_abaixo-min_21_abaixo))-
min_21_abaixo);

//plot(teste_k_abaixo); //480
//plot2(teste_l_abaixo); //108
//plot3(teste_m_abaixo); //54
//plot4(teste_n_abaixo); //21
//spread_abaixo := 50;
//if (minima < teste_k_abaixo-spread_abaixo) or (minima < teste_l_abaixo-
spread_abaixo) or (minima < teste_m_abaixo-spread_abaixo) or (minima <
teste_n_abaixo-spread_abaixo) then
//paintbar(clblue);
smavar_abaixo :=
((teste_k_abaixo+teste_l_abaixo+teste_m_abaixo+teste_n_abaixo)/4);

//ACIMA
i480_acima:=0;
for i480_acima := 1 to 480 do
fech_hoje_k_acima := close[i480_acima];
min_480_acima := highest(close, i480_acima);
max_480_acima := lowest(close, i480_acima);
//media_k := (fech_hoje_k-min_480)/(max_480-min_480)*100;
//teste_k := -1*(((slowstochastic(480)/100)*(max_480-min_480))-min_480);
if (max_480_acima-min_480_acima) = 0 then teste_k_acima := 0 else
teste_k_acima := -1*((((slowstochastic(480)/100))*1/(max_480_acima-min_480_acima))-
min_480_acima);
i108_acima:=0;
for i108_acima := 1 to 108 do
fech_hoje_l_acima := close[i108_acima];
min_108_acima := highest(close, i108_acima);
max_108_acima := lowest(close, i108_acima);
//media_l := (fech_hoje_l-min_108)/(max_108-min_108)*100;
//teste_l := -1*(((slowstochastic(108)/100)*(max_108-min_108))-min_108);
if (max_108_acima-min_108_acima) = 0 then teste_l_acima := 0 else
teste_l_acima := -1*(((slowstochastic(108)/100)*1/(max_108_acima-min_108_acima))-
min_108_acima);

i54_acima:=0;
for i54_acima := 1 to 54 do
//for i54 := 1 to 54 do
fech_hoje_m_acima := close[i54_acima];
min_54_acima := highest(close, i54_acima);
max_54_acima := lowest(close, i54_acima);
//media_m := (fech_hoje_m-min_54)/(max_54-min_54)*100;
//teste_m := -1*(((slowstochastic(54)/100)*(max_54-min_54))-min_54);
if (max_54_acima-min_54_acima) = 0 then teste_m_acima := 0 else teste_m_acima
:= -1*(((slowstochastic(54)/100)*1/(max_54_acima-min_54_acima))-min_54_acima);

i21_acima:=0;
for i21_acima := 1 to 21 do
//for i21 := 1 to 21 do
fech_hoje_n_acima := close[i21_acima];
min_21_acima := highest(close, i21_acima);
max_21_acima := lowest(close, i21_acima);
//media_n := (fech_hoje_n-min_21)/(max_21-min_21)*100;
//teste_n := -1*(((slowstochastic(21)/100)*(max_21-min_21))-min_21);
if (max_21_acima-min_21_acima) = 0 then teste_n_acima := 0 else teste_n_acima
:= -1*(((slowstochastic(21)/100)*1/(max_21_acima-min_21_acima))-min_21_acima);

//plot5(teste_k_acima); //480
//plot6(teste_l_acima); //108
//plot7(teste_m_acima); //54
//plot8(teste_n_acima); //21
//spread_acima := 50;
//if (maxima > teste_k_acima+spread_acima) or (maxima >
teste_l_acima+spread_acima) or (maxima > teste_m_acima+spread_acima) or (maxima >
teste_n_acima+spread_acima) then
//paintbar(clred);

//MEDIA
smavar_acima := ((teste_k_acima+teste_l_acima+teste_m_acima+teste_n_acima)/4);

//plot11((smavar_acima+smavar_abaixo)/2);
//plot12((teste_k_acima+teste_k_abaixo)/2);
if (teste_k_acima+teste_k_abaixo) <> 0 then
plot( ((smavar_acima+smavar_abaixo)/2) / ((teste_k_acima+teste_k_abaixo)/2));

//plot13((teste_l_acima+teste_l_abaixo)/2);
//plot14((teste_m_acima+teste_m_abaixo)/2);
//plot15((teste_n_acima+teste_n_abaixo)/2);
//plot6(smavar_abaixo);
//plot5(teste_k_abaixo/teste_l_abaixo);
//plot6(teste_l_abaixo/teste_m_abaixo);
//plot7(teste_m_abaixo/teste_n_abaixo);

//plot9(teste_k_acima/teste_l_acima);
//plot10(teste_l_acima/teste_m_acima);
//plot11(teste_m_acima/teste_n_acima);

plot11(1);

//if (year(date)>=2022) then // APENAS PARA O BACKTEST


//begin;
if (mediaexp(270,close)) <> 0 then sma108 := mediaexp(108,close) /
mediaexp(270,close);
if (mediaexp(540,close)) <> 0 then sma270 := mediaexp(270,close) /
mediaexp(540,close);
//end;
plot12(sma108);
//plot2(1);
plot13(sma270); //SINAL

spread := 2000;
// ZT - ZONA DE TRADING
// zt - compra
if (sma270 >= 1) and (sma108 >= 1) and (sma270 < sma108) then
begin;
//plot4(linha_op);
fv := 0;
paintbar(clblue);
//setplotcolor(12,clblue);
setplotcolor(13,clblue);
if fc = 0 then
begin;
buystop(high, high);
fc := 1;
//linha_op := sma270;
//setplotcolor(4,clblue);
end;
//if isbought then
// begin;
// if (close >= buyprice+spread) then selltocoverstop(close, close);
// if (close <= buyprice-spread) then selltocoverstop(close, close);
// end;
end;

// zt - venda
if (sma270 <= 1) and (sma108 <= 1) and (sma270 > sma108) then
begin;
//plot4(linha_op);
fc := 0;
paintbar(clred);
//setplotcolor(12,clred);
setplotcolor(13,clred);
if fv = 0 then
begin;
sellshortstop(low, low);
fv := 1;
//linha_op := sma270;
//setplotcolor(4,clred);
end;
//if issold then
// begin;
// if (close <= sellprice-spread) then buytocoverstop(close, close);
// if (close >= sellprice+spread) then buytocoverstop(close, close);
// end;
end;

//ZMT - ZONA DE MITIGAÇÃO


//zmt - inferior
if (sma270 < 1) and (sma108 < 1) and (sma270 < sma108) then
begin;
paintbar(clyellow);
//setplotcolor(12,clyellow);
//setplotcolor(13,clyellow);
if isbought or issold then closeposition;
fv := 0;
fc := 0;
end;
// zt - superior
if (sma270 > 1) and (sma108 > 1) and (sma270 > sma108) then
begin;
paintbar(clyellow);
//setplotcolor(12,clyellow);
//setplotcolor(13,clyellow);
if isbought or issold then closeposition;
fc := 0;
fv := 0;
end;
end;

///////////////////////////////////////////////////////////////////
// SUPER TENDÊNCIA //
///////////////////////////////////////////////////////////////////
var

//ABAIXO
media_k_abaixo : float;
media_l_abaixo : float;
media_m_abaixo : float;
media_n_abaixo : float;
i480_abaixo : integer;
i108_abaixo : integer;
i54_abaixo : integer;
i21_abaixo : integer;

fech_hoje_k_abaixo : float;
fech_hoje_l_abaixo : float;
fech_hoje_m_abaixo : float;
fech_hoje_n_abaixo : float;

min_480_abaixo : float;
max_480_abaixo : float;
min_108_abaixo : float;
max_108_abaixo : float;
min_54_abaixo : float;
max_54_abaixo : float;
min_21_abaixo : float;
max_21_abaixo : float;

//ponto_480 : float;
teste_k_abaixo : float;
teste_l_abaixo : float;
teste_m_abaixo : float;
teste_n_abaixo : float;

spread_abaixo : float;

//ACIMA
media_k_acima : float;
media_l_acima : float;
media_m_acima : float;
media_n_acima : float;
i480_acima : integer;
i108_acima : integer;
i54_acima : integer;
i21_acima : integer;

fech_hoje_k_acima : float;
fech_hoje_l_acima : float;
fech_hoje_m_acima : float;
fech_hoje_n_acima : float;

min_480_acima : float;
max_480_acima : float;
min_108_acima : float;
max_108_acima : float;
min_54_acima : float;
max_54_acima : float;
min_21_acima : float;
max_21_acima : float;

//ponto_480 : float;
teste_k_acima : float;
teste_l_acima : float;
teste_m_acima : float;
teste_n_acima : float;

spread_acima : float;

//MEDIA

smavar_acima : float;
smavar_abaixo : float;
begin
//ABAIXO
i480_abaixo:=0;
for i480_abaixo := 1 to 480 do
fech_hoje_k_abaixo := close[i480_abaixo];
min_480_abaixo := lowest(close, i480_abaixo);
max_480_abaixo := highest(close, i480_abaixo);
//media_k := (fech_hoje_k-min_480)/(max_480-min_480)*100;
//teste_k := -1*(((slowstochastic(480)/100)*(max_480-min_480))-min_480);
teste_k_abaixo := -1*((((slowstochastic(480)/100))*1/(max_480_abaixo-
min_480_abaixo))-min_480_abaixo);

i108_abaixo:=0;
for i108_abaixo := 1 to 108 do
fech_hoje_l_abaixo := close[i108_abaixo];
min_108_abaixo := lowest(close, i108_abaixo);
max_108_abaixo := highest(close, i108_abaixo);
//media_l := (fech_hoje_l-min_108)/(max_108-min_108)*100;
//teste_l := -1*(((slowstochastic(108)/100)*(max_108-min_108))-min_108);
teste_l_abaixo := -1*(((slowstochastic(108)/100)*1/(max_108_abaixo-
min_108_abaixo))-min_108_abaixo);

i54_abaixo:=0;
for i54_abaixo := 1 to 54 do
//for i54 := 1 to 54 do
fech_hoje_m_abaixo := close[i54_abaixo];
min_54_abaixo := lowest(close, i54_abaixo);
max_54_abaixo := highest(close, i54_abaixo);
//media_m := (fech_hoje_m-min_54)/(max_54-min_54)*100;
//teste_m := -1*(((slowstochastic(54)/100)*(max_54-min_54))-min_54);
teste_m_abaixo := -1*(((slowstochastic(54)/100)*1/(max_54_abaixo-
min_54_abaixo))-min_54_abaixo);

i21_abaixo:=0;
for i21_abaixo := 1 to 21 do
//for i21 := 1 to 21 do
fech_hoje_n_abaixo := close[i21_abaixo];
min_21_abaixo := lowest(close, i21_abaixo);
max_21_abaixo := highest(close, i21_abaixo);
//media_n := (fech_hoje_n-min_21)/(max_21-min_21)*100;
//teste_n := -1*(((slowstochastic(21)/100)*(max_21-min_21))-min_21);
teste_n_abaixo := -1*(((slowstochastic(21)/100)*1/(max_21_abaixo-
min_21_abaixo))-min_21_abaixo);

//plot(teste_k_abaixo); //480
//plot2(teste_l_abaixo); //108
//plot3(teste_m_abaixo); //54
//plot4(teste_n_abaixo); //21
//spread_abaixo := 50;
//if (minima < teste_k_abaixo-spread_abaixo) or (minima < teste_l_abaixo-
spread_abaixo) or (minima < teste_m_abaixo-spread_abaixo) or (minima <
teste_n_abaixo-spread_abaixo) then
//paintbar(clblue);
smavar_abaixo :=
((teste_k_abaixo+teste_l_abaixo+teste_m_abaixo+teste_n_abaixo)/4);

//ACIMA
i480_acima:=0;
for i480_acima := 1 to 480 do
fech_hoje_k_acima := close[i480_acima];
min_480_acima := highest(close, i480_acima);
max_480_acima := lowest(close, i480_acima);
//media_k := (fech_hoje_k-min_480)/(max_480-min_480)*100;
//teste_k := -1*(((slowstochastic(480)/100)*(max_480-min_480))-min_480);
teste_k_acima := -1*((((slowstochastic(480)/100))*1/(max_480_acima-
min_480_acima))-min_480_acima);

i108_acima:=0;
for i108_acima := 1 to 108 do
fech_hoje_l_acima := close[i108_acima];
min_108_acima := highest(close, i108_acima);
max_108_acima := lowest(close, i108_acima);
//media_l := (fech_hoje_l-min_108)/(max_108-min_108)*100;
//teste_l := -1*(((slowstochastic(108)/100)*(max_108-min_108))-min_108);
teste_l_acima := -1*(((slowstochastic(108)/100)*1/(max_108_acima-
min_108_acima))-min_108_acima);

i54_acima:=0;
for i54_acima := 1 to 54 do
//for i54 := 1 to 54 do
fech_hoje_m_acima := close[i54_acima];
min_54_acima := highest(close, i54_acima);
max_54_acima := lowest(close, i54_acima);
//media_m := (fech_hoje_m-min_54)/(max_54-min_54)*100;
//teste_m := -1*(((slowstochastic(54)/100)*(max_54-min_54))-min_54);
teste_m_acima := -1*(((slowstochastic(54)/100)*1/(max_54_acima-
min_54_acima))-min_54_acima);

i21_acima:=0;
for i21_acima := 1 to 21 do
//for i21 := 1 to 21 do
fech_hoje_n_acima := close[i21_acima];
min_21_acima := highest(close, i21_acima);
max_21_acima := lowest(close, i21_acima);
//media_n := (fech_hoje_n-min_21)/(max_21-min_21)*100;
//teste_n := -1*(((slowstochastic(21)/100)*(max_21-min_21))-min_21);
teste_n_acima := -1*(((slowstochastic(21)/100)*1/(max_21_acima-
min_21_acima))-min_21_acima);

//plot5(teste_k_acima); //480
//plot6(teste_l_acima); //108
//plot7(teste_m_acima); //54
//plot8(teste_n_acima); //21
//spread_acima := 50;
//if (maxima > teste_k_acima+spread_acima) or (maxima >
teste_l_acima+spread_acima) or (maxima > teste_m_acima+spread_acima) or (maxima >
teste_n_acima+spread_acima) then
//paintbar(clred);

//MEDIA
smavar_acima := ((teste_k_acima+teste_l_acima+teste_m_acima+teste_n_acima)/4);

//plot11((smavar_acima+smavar_abaixo)/2);
//plot12((teste_k_acima+teste_k_abaixo)/2);
plot13( ((smavar_acima+smavar_abaixo)/2) / ((teste_k_acima+teste_k_abaixo)/2));
//plot13((teste_l_acima+teste_l_abaixo)/2);
//plot14((teste_m_acima+teste_m_abaixo)/2);
//plot15((teste_n_acima+teste_n_abaixo)/2);

//plot6(smavar_abaixo);
//plot5(teste_k_abaixo/teste_l_abaixo);
//plot6(teste_l_abaixo/teste_m_abaixo);
//plot7(teste_m_abaixo/teste_n_abaixo);

//plot9(teste_k_acima/teste_l_acima);
//plot10(teste_l_acima/teste_m_acima);
//plot11(teste_m_acima/teste_n_acima);

plot11(1);
end;

/////////////////////////////////////////////
// //
// INDICADOR //
// E BACKTEST //
// SUPER_T //
// //
/////////////////////////////////////////////
// This source code is subject to the terms of the Mozilla Public License 2.0 at
https://mozilla.org/MPL/2.0/
// © rcarqurbanismo
// @version=4
//study("Variação do Range anterior", "RANGE01", overlay=true)
//indicator("RANGE01", overlay = true)
strategy("Super_T")

//var1 = ema(close,108)/ema(close,270)
//var2 = ema(close,270)/ema(close,540)
// original var1 = ema(ema(close,108)/ema(close,270),108)

var1 = ema(close,270)/ema(close,540)
var2 = ema(ema(close,270)/ema(close,540),108)

// INDICADOR RANGE01
range_long = 216
range_short = 54

rb_high_long = highest(close,range_long)
rb_low_long = lowest(close,range_long)
//rb_open = open(close,range)
//rb_close = close(close,range)
rb_med_long = (rb_high_long+rb_low_long)/2

rb_high_short = highest(close,range_short)
rb_low_short = lowest(close,range_short)
//rb_open = open(close,range)
//rb_close = close(close,range)
rb_med_short = (rb_high_short+rb_low_short)/2
super_med = (ema((rb_med_short+rb_med_long)/2,270)/ema((rb_med_short+rb_med_long)/
2,540))
super_med2 =(ema(
(ema((rb_med_short+rb_med_long)/2,270)/ema((rb_med_short+rb_med_long)/
2,540)) ,108))

// INDICADOR FR-02
tf = 32400
acel = (high-low)/tf
massa = (close-open)
forca = massa * acel
float linhac = 0
float linhav = 0
float linhar = 0
float totc = 0
float totv = 0
float lc = 0
float lv = 0

// INDICADOR FR-01
totc := valuewhen(forca > 0, (high+(massa*forca/100)), 0)
totv := valuewhen(forca < 0, (low-(massa*forca/100)), 0)
linhav := valuewhen(high > totc, high, 0)
linhac := valuewhen(low < totv, low, 0)
linhar := valuewhen(linhac > linhav, ((high+low)/2),0 )

lc := valuewhen (((close == low) and (open > close) and (high > open) and ((open-
close)>(high-open))), high, 0)
lv := valuewhen (((close == high) and (open < close) and (low < open) and ((close-
open)>(open-low))), low, 0)

cor = color.black
cor2 = color.orange

// testa candle de fechamento


//barcolor( ((close == high) and (open < close) and (low < open) and ((close-
open)>(open-low))) ? (open < close) ? (open > close) ? color.orange : color.green :
color.red : color.black )
barcolor( ((close == low) and (open > close) and (high > open) and ((open-
close)>(high-open))) ? color.green : na )
barcolor( ((close == high) and (open < close) and (low < open) and ((close-
open)>(open-low))) ? color.red : na )

testa_v = ((close == high) and (open < close) and (low < open) and ((close-
open)>(open-low)))

linha = 1
ztc_linha = 0
ztv_linha = 0
//faixa = 1 // faixa com porcentagem de variação do dia

//ztc_linha = close
//ztv_linha = close
// ZONAS de compra
zt1 = var1 > 1
zt2 = var2 > 1
zt3 = var2 < var1
//ZONAS de venda
zt4 = var1 < 1
zt5 = var2 < 1
zt6 = var2 > var1

linha_compra = zt1 ? zt2 ? zt3 ? 1 : 2 : 3 : 4


linha_venda = zt4 ? zt5 ? zt6 ? 1 : 2 : 3 : 4
//hora_abre = hour==18 and minute == 00
// testa cor

// ORIGINAIS
long = linha_compra == 1
short = linha_venda == 1

// ANTECIPAÇÃO DE ENTRADA
//long = linha_compra == 3
//short = linha_venda == 3

lote = 1.0

strategy.entry("ZT-Compra", strategy.long, lote, when = long )


strategy.entry("ZT-Venda", strategy.short, lote, when = short )

//strategy.exit("Saída_Compra", "Compra", profit = 500, loss = 1000)


//strategy.exit("Saída_Venda", "Venda", profit = 500, loss = 1000)

strategy.close("Compra", when = short)


strategy.close("Venda", when = long)

//labeltext = ""
//labeltextztcompra = "ZT-COMPRA"
//labeltextztvenda = "ZT-VENDA"

//ourLabel = label.new(x=bar_index, y=na, text=labeltext, yloc=yloc.belowbar,


color=color.green, textcolor=color.white, style=label.style_label_up,
size=size.normal)

// ORIGINAIS
//ztc_linha := valuewhen(linha_compra == 1, bar_index, 0)
//ztv_linha := valuewhen(linha_venda == 1, bar_index, 0)

// ANTECIPAÇÃO DE ENTRADA
ztc_linha := valuewhen(linha_compra == 1, bar_index, 0)
ztv_linha := valuewhen(linha_venda == 1, bar_index, 0)

//ZT
if (linha_compra == 1)
cor := color.blue
linha := 4
//ourLabel := label.new(x=bar_index, y=na, text=labeltextztcompra,
yloc=yloc.belowbar, color=color.blue, textcolor=color.white,
style=label.style_label_up, size=size.normal)

if (linha_venda == 1)
cor := color.red
linha := 4
//ourLabel := label.new(x=bar_index, y=na, text=labeltextztvenda,
yloc=yloc.belowbar, color=color.red, textcolor=color.white,
style=label.style_label_up, size=size.normal)

//ZMT
if (linha_compra == 2)
cor := color.black

if (linha_venda == 2)
cor := color.black

//ZR
if (linha_compra == 3)
// original cor := color.yellow
cor := color.yellow

if (linha_venda == 3)
// originalcor := color.yellow
cor := color.yellow

// EMAS
plot(ema(close,216),"",color.green )
plot(ema(close,108),"",color.red )
plot(ema(close,270),"",color=cor, linewidth = 4)

plot(linhar, "", color.orange)

// lc e lv
plot(lc, "", color.blue) //, linewidth = 2)
plot(lv, "", color.purple) //, linewidth = 2)

// PLOTA RANGE
//plot(close, "", color.black)
plot(rb_high_long, "", color.green, linewidth = 2)
plot(rb_low_long, "", color.red, linewidth = 2)
plot(rb_high_short, "", color.green)
plot(rb_low_short, "", color.red)

plot(super_med, "", color.black)


plot(super_med2, "", color.black)

You might also like