input
MaxTradesDia(3); // 3 operações por dia
var
tradesDia : Integer;
diaRef : Integer;
prevHasPos : Boolean;
validCount : Integer;
begin
// -----------------------------
// CONTROLE DIÁRIO (reset + contagem de operações encerradas)
// -----------------------------
if (diaRef <> Date()) then
begin
diaRef := Date();
tradesDia := 0;
end;
// conta 1 operação quando a posição ENCERRA
if (prevHasPos) and (not HasPosition) then
tradesDia := tradesDia + 1;
prevHasPos := HasPosition;
// -----------------------------
// ENTRADA (apenas se não tiver posição)
// -----------------------------
if (not HasPosition) then
begin
// trava: máximo X operações por dia
if (tradesDia >= MaxTradesDia) then
begin
if (HasPendingOrders) then
CancelPendingOrders;
end
else
begin
// evita “empilhar” ordens
if (HasPendingOrders) then
CancelPendingOrders;
// 1) Candle de ouro / não violou (inside) + candle base <= 400 pontos
if (High <= High[1]) and (Low >= Low[1]) and ((High[1] - Low[1]) <= 400) then
begin
// 2) HiLo define tendência
// 3) MM200 define lado (compra acima / venda abaixo)
// =========================
// COMPRA: HiLo alta + acima da MM200
// e regra 2/3 entre: IFR, Volume, Estocástico
// =========================
if (HiLoActivator(5)|1| = 1) and (Close > FastWMA(200)) then
begin
validCount := 0;
if (IFR(14) > 50) then
validCount := validCount + 1;
// Volume = volume financeiro
if (Volume > Media(9,Volume)) then
validCount := validCount + 1;
if (SlowStochastic(14,3,3) < 90) then
validCount := validCount + 1;
if (validCount >= 2) then
BuyLimit((High[1] + Low[1]) / 2, 1);
end
else
// =========================
// VENDA: HiLo baixa + abaixo da MM200
// e regra 2/3 entre: IFR, Volume, Estocástico
// =========================
if (HiLoActivator(5)|1| = 0) and (Close < FastWMA(200)) then
begin
validCount := 0;
if (IFR(14) < 50) then
validCount := validCount + 1;
if (Volume > Media(9,Volume)) then
validCount := validCount + 1;
if (SlowStochastic(14,3,3) > 10) then
validCount := validCount + 1;
if (validCount >= 2) then
SellShortLimit((High[1] + Low[1]) / 2, 1);
end;
end;
end;
end;
// -----------------------------
// SAÍDAS (mantidas iguais)
// -----------------------------
if (IsBought) then
begin
if (HasPendingOrders) then
CancelPendingOrders;
SellToCoverLimit(BuyPrice + 200,1);
SellToCoverStop(BuyPrice - 100,BuyPrice - 100,1);
end
else if (IsSold) then
begin
if (HasPendingOrders) then
CancelPendingOrders;
BuyToCoverLimit(SellPrice - 200,1);
BuyToCoverStop(SellPrice + 100,SellPrice + 100,1);
end;
end;