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:
InputmediaCurta(21);mediaMedia(8);
varMmc, Mml : float;
beginMmc := 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) thenBeginSellToCoverAtMarket; 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 )
varMmc, Mml : float;BuyPrice : float;
beginMmc := mediaexp(mediaCurta, close);Mml := mediaexp(mediaMedia, close);
// Condição para abrir posição de compraif (buyPosition = 0) and (Mmc[1] < Mml[1]) and (Mmc > Mml) then begin BuyAtMarket;BuyPrice := Close; // Armazena o preço de compraPaintBar(ClBlue); end;
// Condição para fechar posição de compraif (buyPosition = 1) and ((Mmc[1] > Mml[1]) and (Mmc < Mml) or (Close <= BuyPrice - 20 * MinPriceIncrement)) thenbeginSellToCoverAtMarket; PaintBar(ClRed);ClosePosition;if hasPendingOrders thenCancelPendingOrders;end;
// Condição para pintar as barras de acordo com a relação entre Mmc e Mmlif (mmc > mml) then PaintBar(ClBlue) else PaintBar(ClRed);
// Plotagem dos valores de Mmc e Mmlplot(MMC);plot2(mml);end;
inputMediaCurta(8);MediaLonga(21);
beginMmc := MediaExp(MediaCurta, Close);Mml := MediaExp(MediaLonga, Close);
// Condição de entrada (cruzamento de médias)if (BuyPosition = 0) and (Mmc[1] < Mml[1]) and (Mmc > Mml) thenbeginBuyAtMarket;BuyPrice := Close;PaintBar(ClBlue);end;
// Stop de 20 ticks abaixo do preço de compraif (BuyPosition = 1) and (Close <= BuyPrice - 20 * MinPriceIncrement) thenbeginSellToCoverAtMarket;PaintBar(ClRed);CancelPendingOrders;end;
// Fechamento por cruzamento de médias ao contrárioif (BuyPosition = 1) and (Mmc[1] > Mml[1]) and (Mmc < Mml) thenbeginSellToCoverAtMarket;PaintBar(ClRed);CancelPendingOrders;end;
// Coloração das barrasif (Mmc > Mml) thenPaintBar(ClBlue)elsePaintBar(ClRed);
// PlotsPlot(Mmc);Plot2(Mml);end;