Neo traderBot

Neo traderBot

Você sabia?

Abordamos o tema de automatização de estratégias em NTSL, MQL5 e NinjaScript!

leaf leftleaf right
Notifications
Clear all

alvos de saida ( HELP )

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

No meu codigo eu fiz uma condição que apos realizar uma compra, obrigatoriamente a proxima tem que ser uma venda, mas de fato isso afeta minhas saidas, quando estou comprado nao consigo colocar meus stop pois sao ordens de venda para cobrir a posição, entao fiz o seguinte no codigo abaixo, mas nao tenho um bom resultado nas saidas, alguem consegue me ajudar administrar a saida ?

input
  FastAverage(21);
  SlowAverage(8);
 
var  
  sAvgFast     : Float;
  sAvgSlow     : Float;
  sPrevAvgFast : Float;
  sPrevAvgSlow : Float;
  valorA       :real;
  ValorB       :real;
  amplitude    :real;
  p0, p1, p2, p3, p4, p5,p6,p7,p10, p11, p12, p13, p14, p15,p16,p17   : real;
  contador, contador2      :integer;
  sinal,venda,compra,stopcompra,stopvenda,gaincompra,gainvenda, Cliga, Vliga : integer;
  passe1,passe2 : boolean; 
  
begin
  // Armazena os valores das médias em variáveis de apoio
  sAvgFast     := MediaExp(FastAverage, Close);
  sAvgSlow     := MediaExp(SlowAverage, Close);
  sPrevAvgFast := sAvgFast[1];
  sPrevAvgSlow := sAvgSlow[1];
  stopcompra := (p5 - 8 * MinPriceIncrement);
  stopvenda :=  (p10 + 8 * MinPriceIncrement);
  gaincompra := (p2);
  gainvenda := (p13);
  passe1 :=  (sinal=0) or (sinal=2); //testado ok
  passe2 := (sinal=1); //testado ok
   
  if  passe1 and (BuyPosition = 0) and (SellPosition = 0) and (sPrevAvgFast < sPrevAvgSlow) and (sAvgFast > sAvgSlow) then
  BEGIN
    

      ValorA   :=  abs (Lowest(Open, 21));
      ValorB   :=  abs(Highest(close, 8));
      amplitude := abs(ValorB-ValorA) ;
      p0 := valorA + (amplitude * 0);
      p1 := valorA + (amplitude * 0.382);
      p2 := valorA + (amplitude * 0.5);
      p3 := valorA + (amplitude * 0.618);
      p4 := valorA + (amplitude * 1);     //abertura do candle
      p5 := valorB - (amplitude * 1.61);  //stop
      p6 := valorB - (amplitude * 1.69);
      
      cliga:=1;
   
      PaintBar(clVerde);           
    
End;
if passe1 then
begin              
Buystop(p1);

end;
if isBought then
 begin
sinal:=1; 

end;
// Verifica se está comprado
if (IsBought) then
begin
 if  (BuyPrice > gaincompra)or (buyprice > p3 ) or ( buyprice > p4) then
  ClosePosition;
 if HasPendingOrders then
  CancelPendingOrders;
end; 
 
//If (BuyPosition = 1) or isBought and ((BuyPrice > gaincompra)or (buyprice > p3 ) or ( buyprice > p4))then
//begin
// ClosePosition;

        //  If hasPendingOrders then
           // CancelPendingOrders;
       // end;
If (BuyPosition = 1) or isBought and  (BuyPrice > stopcompra)then
begin
ClosePosition;
          If hasPendingOrders then
            CancelPendingOrders;
end;



      
      if passe1 then
      begin
    HorizontalLine(p0, clVermelho);
    HorizontalLine(p1, clBLACK); // 1 SEQUENCIA  DE COMPRA
    HorizontalLine(p2, clBLACK); // 2 SEQUENCIA DE COMPRA
    HorizontalLine(p3, clBLACK);//  3 SEQUENCIA DE COMPRA
    HorizontalLine(p4, clVerde);
    HorizontalLine(p5, clVermelho);
    HorizontalLine(p6, clred);
    contador := contador+ 2;
   
end;
      


   if passe2 and (BuyPosition = 0) and (SellPosition = 0)and (sPrevAvgFast > sPrevAvgSlow) and (sAvgFast < sAvgSlow)  then
 begin
   

      ValorA   :=  abs (Lowest(Open, 8));
      ValorB   :=  abs(Highest(close, 21));
      amplitude := abs(ValorB-ValorA) ;
      p15 := valorA + (amplitude * 0);
      p14 := valorA + (amplitude * 0.382);
      p13 := valorA + (amplitude * 0.50);
      p12 := valorA + (amplitude * 0.618);
      p11 := valorA + (amplitude * 1); //abetura do candle
      p10 := valorA + (amplitude * 1.61);                 //stop
      p16 := valorB + (amplitude * 1.69);
      PaintBar(ClRed);    

  
 
End;
if passe2 then
begin              
SellShortStop(p12);

end;
if isSold then
 begin
sinal:=2; 
Venda:=0;
end;

// Verifica se está vendido
if (IsSold) then
begin
 if  (SellPrice < gainVenda) or (sellprice<p14) or (buyprice<p15) then
  ClosePosition;
 if HasPendingOrders then
  CancelPendingOrders;
end;   
//If (SellPosition = 1)or isSold and ((SellPrice < gainVenda) or (sellprice<p14) or (buyprice<p15))  then
//begin
//ClosePosition;

          //If hasPendingOrders then
           // CancelPendingOrders;
       // end;
If (SellPosition = 1)or isSold and (SellPrice < stopvenda) then
begin
 ClosePosition;
          If hasPendingOrders then
            CancelPendingOrders;
end;     
 
  

if passe2 then
 begin
      HorizontalLine(p10, clVermelho);
      HorizontalLine(p11, clVerde);
      HorizontalLine(p12, clBLACK);   // 1 DE VENDA
      HorizontalLine(p13, clBLACK);  // 2 DE VENDA
      HorizontalLine(p14, clBLACK);  // 3 DE VENDA
      HorizontalLine(p15, clVermelho);
      HorizontalLine(p16, clred);
     contador := contador - 2;      
  

end;
end;


     
      


   
Citar