// Robô de tendência com stop móvel, alvo e auto reverse// Evita operar em mercado lateral usando ADX
// Definição de parâmetros de entradaInputs:PeriodoMME(20),PeriodoADX(14),LimiteADX(20),AlvoTicks(38),StopTicks(20);
// Declaração de variáveisVars:MediaMME(0.0),ValorADX(0.0),TendenciaAlta(false),TendenciaBaixa(false);
begin// Cálculo da MME e do ADXMediaMME = XAverage(Close, PeriodoMME);ValorADX = ADX(PeriodoADX);
// Verifica se mercado está com tendênciaif ValorADX > LimiteADX thenbeginTendenciaAlta = Close > MediaMME;TendenciaBaixa = Close < MediaMME;
// Se não estiver posicionadoif MarketPosition = 0 thenbeginif TendenciaAlta thenBuy ("Compra") next bar at marketelse if TendenciaBaixa thenSellShort ("Venda") next bar at market;end;end;
// Se estiver comprado, aplica alvo, stop móvel e auto reverseif MarketPosition = 1 thenbeginSell ("StopMovel") next bar at EntryPrice - StopTicks * MinMove / PriceScale stop;Sell ("Alvo") next bar at EntryPrice + AlvoTicks * MinMove / PriceScale limit;
// Auto reverseif Close <= EntryPrice - StopTicks * MinMove / PriceScale thenSellShort ("AutoReverseV") next bar at marketelse if Close >= EntryPrice + AlvoTicks * MinMove / PriceScale thenSellShort ("AutoReverseV") next bar at market;end;
// Se estiver vendido, aplica alvo, stop móvel e auto reverseif MarketPosition = -1 thenbeginBuyToCover ("StopMovel") next bar at EntryPrice + StopTicks * MinMove / PriceScale stop;BuyToCover ("Alvo") next bar at EntryPrice - AlvoTicks * MinMove / PriceScale limit;
// Auto reverseif Close >= EntryPrice + StopTicks * MinMove / PriceScale thenBuy ("AutoReverseC") next bar at marketelse if Close <= EntryPrice - AlvoTicks * MinMove / PriceScale thenBuy ("AutoReverseC") next bar at market;end;end;
Alguém pode ajudar? Grato