Neo traderBot

Neo traderBot

Você sabia?

Um backtesting adequado deve buscar simular situações práticas do mercado (slippage, custo de operação, etc...)

leaf leftleaf right
Notifications
Clear all

ADICIONAR NO CODIGO SAIDA ( TOCOVER ) - NAO CONSIGO

1 Posts
1 Usuários
0 Reactions
61 Visualizações
(@rodrigoschmoeller)
Membro ativo
Registrou: 7 meses atrás
Posts: 4
Iniciador do tópico  

Tenho um codigo e quer adicionar um stop a mais ao meu codigo, eu fiz mas nao deu certo, codigo original, e mais abaixo o codigo que modifiquei:

Input
mediaCurta(21);
mediaMedia(8);

var
Mmc, Mml : float;

begin
Mmc := mediaexp(mediaCurta,close);
Mml := mediaexp(mediaMedia,close);

If (buyPosition = 0) and (Mmc[1] < Mml[1]) and (Mmc > Mml) then
begin
BuyAtmarket;
PaintBar(Clblue);
end;

If (buyPosition = 1) and (Mmc[1] > Mml[1]) and (Mmc < Mml) then
Begin
SellToCoverAtMarket;
PaintBar(ClRed);
End;

If (mmc > mml) then PaintBar(Clblue) else PaintBar(Clred);

plot(MMC);
plot2(mml);

end;

CODIGO ATUALIZADO, POREM ACHO QUE ESTA ERRADO ( Quero adicionar uma saida se meu preço cair 20ticks abaixo da minha posição comprada, fechar a operação )

Input
mediaCurta(21);
mediaMedia(8);

var
Mmc, Mml : float;
BuyPrice : float;

begin
Mmc := mediaexp(mediaCurta, close);
Mml := mediaexp(mediaMedia, close);

// Condição para abrir posição de compra
if (buyPosition = 0) and (Mmc[1] < Mml[1]) and (Mmc > Mml) then
begin
BuyAtMarket;
BuyPrice := Close; // Armazena o preço de compra
PaintBar(ClBlue);
end;

// Condição para fechar posição de compra
if (buyPosition = 1) and ((Mmc[1] > Mml[1]) and (Mmc < Mml) or (Close <= BuyPrice - 20 * MinPriceIncrement)) then
begin
SellToCoverAtMarket;
PaintBar(ClRed);
ClosePosition;
if hasPendingOrders then
CancelPendingOrders;
end;

// Condição para pintar as barras de acordo com a relação entre Mmc e Mml
if (mmc > mml) then
PaintBar(ClBlue)
else
PaintBar(ClRed);

// Plotagem dos valores de Mmc e Mml
plot(MMC);
plot2(mml);
end;

 

Input
mediaCurta(21);
mediaMedia(8);

var
Mmc, Mml : float;
BuyPrice : float;

begin
Mmc := mediaexp(mediaCurta, close);
Mml := mediaexp(mediaMedia, close);

// Condição para abrir posição de compra
if (buyPosition = 0) and (Mmc[1] < Mml[1]) and (Mmc > Mml) then
begin
BuyAtMarket;
BuyPrice := Close; // Armazena o preço de compra
PaintBar(ClBlue);
end;

// Condição para fechar posição de compra
if (buyPosition = 1) and ((Mmc[1] > Mml[1]) and (Mmc < Mml) or (Close <= BuyPrice - 20 * MinPriceIncrement)) then
begin
SellToCoverAtMarket;
PaintBar(ClRed);
ClosePosition;
if hasPendingOrders then
CancelPendingOrders;
end;

// Condição para pintar as barras de acordo com a relação entre Mmc e Mml
if (mmc > mml) then
PaintBar(ClBlue)
else
PaintBar(ClRed);

// Plotagem dos valores de Mmc e Mml
plot(MMC);
plot2(mml);
end;


   
Citar