Skip to content

Instantly share code, notes, and snippets.

@luishgp
Last active January 14, 2021 13:53
Show Gist options
  • Save luishgp/c1585814763ff01c064641c0997b0478 to your computer and use it in GitHub Desktop.
Save luishgp/c1585814763ff01c064641c0997b0478 to your computer and use it in GitHub Desktop.
Inside Bars
var
BuyOversold, BuyEden : Boolean;
Stoch, Target, Stop, BuyAt : Float;
begin
Stoch := SlowStochastic(8)[1];
BuyOversold := ((HIGH[1] < HIGH[2]) and (LOW[1] > LOW[2]) and (Stoch < 20));
BuyEden := ((HIGH[1] < HIGH[2]) and (LOW[1] > LOW[2]) and ((CLOSE[1] > MediaExp(8, CLOSE)[1]) and (CLOSE[1] > MediaExp(80, CLOSE)[1])));
if ((BuyOversold or BuyEden) and (BuyPosition = 0)) then
begin
PaintBar(clGreen);
BuyAt := High[1] + 0.02;
// Caso esteja acima da média, o stop descola-se para a media para não ser muito curto
// Caso contrário, o stop fica no ultimo fundo
if (LOW[1] > MediaExp(8, CLOSE)[1]) then
begin
Stop := MediaExp(8, CLOSE)[1];
end
else
begin
Stop := Lowest(LOW, 3) - 0.02;
end;
// Caso seja uma operação contra a tendência, o alvo é 1x o risco
if (BuyOversold AND ((CLOSE[1] < MediaExp(8, CLOSE)[1]) or (CLOSE[1] < MediaExp(80, CLOSE)[1]))) then
begin
Target := ((BuyAt - Stop) * 1) + BuyAt;
end
else
Target := ((BuyAt - Stop) * 1.61) + BuyAt;
BuyStop(BuyAt, BuyAt);
end;
if (IsBought) then
begin
// Alvo
SellToCoverStop(Target, Target);
// Stop
SellToCoverStop(Stop, Stop);
// Caso abra em gap de baixa, pulando o stop
if (HIGH < Stop) then
begin
SellToCoverStop(HIGH, HIGH);
end;
end;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment