Trailing Stops e Trailing Profit - página 2

 
Arav007:


Desculpe-me, na verdade, fiquei um pouco confuso.

if(iOpenOrders_Buy = 3)

Aqui se o pedido de Compra Total Aberta for igual a '3', então o código irá prosseguir para a próxima parte.

if(iOpenOrders_Buy > 0 )

Então, se a contagem do pedido de Compra Total Aberta for maior do que '0', então ele prosseguirá para o próximo.

if(iOpenOrders_Buy == 3)

Então, se a contagem da ordem de Compra Aberta for igual a 3, então abrirá BuyOrder_1, se for igual a '2', então abrirá BuyOrder_2 e então BuyOrder_3 é Contagem de ordem de Compra Aberta é igual a 1.

Eu estou certo?

double dTakeProfitPrice_1=10;

double dTakeProfitPrice_2=20;

double dTakeProfitPrice_3=0;
double BuyOrder_1,.......,.......;
if (Buy Condition Met && iOpenOrders_Buy == 0)
{

iOpenOrders_Buy = 3;

{

if(iOpenOrders_Buy  > 0) // we have to open new Buy orders

{

if(iOpenOrders_Buy == 3)
         {
         BuyOrder_1=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_1, "Buy Order",MagicNumber, 0,Blue);
         if(BuyOrder_1 > 0).......
         

         }
if(iOpenOrders_Buy == 2)
         {
         BuyOrder_2=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_2, "Buy Order",MagicNumber, 0,Blue);
....



if(iOpenOrders_Buy == 1)
         {
         BuyOrder_3=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_3, "Buy Order",MagicNumber, 0,Blue);
....
}

você está certo, olhe novamente para o código alterado, está tudo bem?
 
deVries:

você está certo, olhe novamente para o código alterado, está tudo bem?


Acho que não.

se (Buy Condition Met && iOpenOrders_Buy == 0)

Isto significa que 'Buy Condition is Met' e que não há pedidos de 'Opened Buy', certo?

então o código irá Prosseguir para a próxima linha onde iOpenOrders_Buy = 3;

Então é dito à EA que já existem 3 pedidos abertos lá, certo?

Mas se eu entrar no código sabendo que não há nenhuma ordem de Compra Aberta lá, então porque estamos atribuindo iOpenOrders_Buy = 3; ?

Também o alvo é: Uma das três ordens de compra continuará funcionando e somente uma 'Nova' ordem de compra será aberta quando essa última ordem for fechada.

Portanto, isto tem que ser

if(iOpenOrders_Buy== 0) // Não há nenhuma ordem de Compra Aberta, então temos que abrir novas ordens de Compra


Quando a EA obtiver a condição de compra, então abrirá três negócios com diferentes Take Profit.

Então, se duas das negociações forem fechadas de qualquer forma (por TP ou SL), a terceira continuará funcionando.

 double dTakeProfitPrice_1=10;

double dTakeProfitPrice_2=20;

double dTakeProfitPrice_3=0;

double BuyOrder_1,BuyOrder_2,BuyOrder_3;  

iMaxOrders=3; 

iOpenOrders_Buy = CntOrd(iOrderType_Buy,MagicNumber,Symbol());  //counting open buy orders. 

if (Buy Condition Met && iOpenOrders_Buy ==0) //Buy condition has met and there is no Open Buy Order

{ 

if(iOpenOrders_Buy < iMaxOrders) //This will Limit the desired number of orders; Though this is not necessary.

{

BuyOrder_1=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_1, "Buy Order",MagicNumber, 0,Blue); 

//First order opened with TP1 

BuyOrder_2=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_2, "Buy Order",MagicNumber, 0,Blue);

//Second order opened with TP2  

BuyOrder_3=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_3, "Buy Order",MagicNumber, 0,Blue);

////Third order opened with TP3  

} 

} 

else{

print ("There is already a Running Order")

} 

O que você pensa sobre isso? Faria o mesmo que foi dito acima?

Cumprimentos

 
Arav007:


Acho que não.


O que você pensa sobre isto? Faria o mesmo que foi dito acima?

Cumprimentos

não o que acontece se as ordens não forem bem sucedidas, como você verifica que comércio você tem que abrir se um falhar

porque estamos atribuindo iOpenOrders_Buy = 3; ?

você tem que abrir 3 novos negócios se as ordens forem bem sucedidas, fazendo iOpenOrders_Buy novo valor

se iOpenOrders_Buy se torna 0 temos nossos 3 negócios

 
deVries:

não o que acontece se as ordens não forem bem sucedidas, como você verifica que comércio você tem que abrir se um falhar

porque estamos atribuindo iOpenOrders_Buy = 3; ?

você tem que abrir 3 novos negócios se as ordens forem bem sucedidas, fazendo iOpenOrders_Buy novo valor

se iOpenOrders_Buy se torna 0 temos nossos 3 negócios

int iLastError;

 for (count=iMaxOrders; count>0; count--)

{

if (count==3) {

 BuyOrder_1=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_1, "Buy Order",MagicNumber, 0,Blue);

if (BuyOrder_1>0) //Checking if the order was opened or not

{ 

Print( "Buy Order 1 Opened successfully");

}

else {

 Print( "Order Sending Error");

iLastError = GetLastError();

iMaxOrders=3; //Setting iMaxOrders to 3 again thus it goes back and try to open that order again

} 

}

 if (count==2) {

 BuyOrder_2=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_2, "Buy Order",MagicNumber, 0,Blue);

if (BuyOrder_2>0) {

Print( "Buy Order 2 Opened successfully");

}

else {

 Print( "Order Sending Error");

iLastError = GetLastError();

iMaxOrders=2;

}  

}

if (count==1) {

 BuyOrder_3=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_3, "Buy Order",MagicNumber, 0,Blue);

if (BuyOrder_3>0) {

Print( "Buy Order 3 Opened successfully");

}

else {

 Print( "Order Sending Error");

iLastError = GetLastError();

iMaxOrders=1;

}  

}

} 

Sim, é muito possível que o 'Orderend()' não consiga abrir a ordem.

Agora eu entendi porque

if(iOpenOrders_Buy > 0 ) // temos de abrir novos pedidos de compra

foi usado em seu código. Como já definimos iopendOrders=3, então ele irá verificá-lo.

Mas mais tarde fiquei confuso que como o valor do iopendOrders vai continuar mudando.

Provavelmente, para meu cérebro limitado, eu não consegui descobrir o mecanismo. Então, tentei implementar sua lógica da maneira acima.

Foi isso que você mencionou em seu código dado?

Atenciosamente

 
Arav007:

Sim, é muito possível que o 'Orderend()' não consiga abrir a ordem.

Agora eu entendi porque

if(iOpenOrders_Buy > 0 ) // temos de abrir novos pedidos de compra

foi usado em seu código. Como já definimos iopendOrders=3, então ele irá verificá-lo.

Mas mais tarde fiquei confuso que como o valor do iopendOrders vai continuar mudando.

Provavelmente, para meu cérebro limitado, eu não consegui descobrir o mecanismo. Então, tentei implementar sua lógica da maneira acima.

Foi isso que você mencionou em seu código dado?

Atenciosamente


if (BuyOrder_1>0) //Checking if the order was opened or not

{ 

Print( "Buy Order 1 Opened successfully");
count = count - 1;
}

 
deVries:



Por favor, não se importe, mas novamente fiquei confuso!

Se eu usar

count=count-1; depois de

Imprimir( "Buy Order 1 Opened successfully");

isto significa que se a primeira ordem de compra for aberta, então o valor da contagem será diminuído em 1.

Portanto, ao entrar na próxima função, aqui a próxima condição de "se":

if (contagem===2) {}

o valor da contagem tornou-se '2' para ela. [contagem=3-1=2]

Isto é correto?

 
Arav007:


Por favor, não se importe, mas novamente fiquei confuso!

Se eu usar

count=count-1; depois de

Imprimir( "Buy Order 1 Opened successfully");

isto significa que se a primeira ordem de compra for aberta, então o valor da contagem será diminuído em 1.

Portanto, ao entrar na próxima função, aqui a próxima condição de "se":

if (contagem===2) {}

o valor da contagem tornou-se '2' para ela. [contagem=3-1=2]

Isto é correto?


experimente.... faça alguns testes
 
deVries:

experimentei.... fazer alguns testes


Cansado e este é o resultado.

Provavelmente eu não poderia colocar o código "Encerramento da Encomenda de Venda antes da compra" no lugar certo. Por isso, conseguir Vender e Comprar completamente, embora seja contra o código original.

E há '4' ordens de compra ao todo!

Eu falhei :(

                double OpenPrice=Ask;

                double  dTakeProfitPrice_1,dTakeProfitPrice_2,dTakeProfitPrice_3;
                dStopLossPrice = NormalizeDouble(OpenPrice - StopLoss * dPip,Digits);
                dTakeProfitPrice_1 = NormalizeDouble(OpenPrice + TakeProfit_1 * dPip,Digits);
                dTakeProfitPrice_2 = NormalizeDouble(OpenPrice + TakeProfit_2 * dPip,Digits);
                dTakeProfitPrice_3 = NormalizeDouble(OpenPrice + TakeProfit_3 * dPip,Digits);
                
 for (int count=iMaxOrders; count>0; count--)

{

if (count==3) {

 BuyOrder_1=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_1, "Buy Order",MagicNumber, 0,Blue);

if (BuyOrder_1>0) //Checking if the order was opened or not

{ 

sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + "    Buy order 1 sent successfully. Ticket=" + BuyOrder_1;
                                iLastError = 0;
                                count = count - 1; 

}

else {

 iLastError = GetLastError();
                                
                                sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + "    Error sending buy order 1. Error code=" + ErrorDescription(iLastError);

iMaxOrders=3; //Setting iMaxOrders to 3 again thus it goes back and try to open that order again

} 

}

 if (count==2) {

 BuyOrder_2=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_2, "Buy Order",MagicNumber, 0,Blue);

if (BuyOrder_2>0) { 

sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + "    Buy order 2 sent successfully. Ticket=" + BuyOrder_2;
                                iLastError = 0;
                                count = count - 1; 

}

else {

 iLastError = GetLastError();
                                
                                sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + "    Error sending buy order 2. Error code=" + ErrorDescription(iLastError);

iMaxOrders=2; //Setting iMaxOrders to 2 again thus it goes back and try to open that order again

} 

}

if (count==1) {

 BuyOrder_3=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_3, "Buy Order",MagicNumber, 0,Blue);

if (BuyOrder_3>0) {

sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + "    Buy order 2 sent successfully. Ticket=" + BuyOrder_3;
                                iLastError = 0;
                                count = count - 1; 
}

else {

  iLastError = GetLastError();
                                
                                sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + "    Error sending buy order 2. Error code=" + ErrorDescription(iLastError);

iMaxOrders=1; //Setting iMaxOrders to 1 again thus it goes back and try to open that order again

}  

}
 

opps, esqueceu de colocar iOpenOrders_Buy ==0

Agora testando-o novamente com isto.

 
double OpenPrice=Ask;

double  dTakeProfitPrice_1,dTakeProfitPrice_2,dTakeProfitPrice_3;
dStopLossPrice = NormalizeDouble(OpenPrice - StopLoss * dPip,Digits);
dTakeProfitPrice_1 = NormalizeDouble(OpenPrice + TakeProfit_1 * dPip,Digits);
dTakeProfitPrice_2 = NormalizeDouble(OpenPrice + TakeProfit_2 * dPip,Digits);
dTakeProfitPrice_3 = NormalizeDouble(OpenPrice + TakeProfit_3 * dPip,Digits);
                
//some condition
if(Ask>High[1] && OrdersTotal()<1)int count=3; //(int count=iMaxOrders; count>0; count--)
{
iLastError = 0;
   if (count==3) 
    {
    BuyOrder_1=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_1, "Buy Order",MagicNumber, 0,Blue);
    if (BuyOrder_1>0) //Checking if the order was opened or not
      { 
      sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + "    Buy order 1 sent successfully. Ticket=" + BuyOrder_1;
      count = count - 1; 
      }
     else {
          iLastError = GetLastError();                               
          sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + "    Error sending buy order 1. Error code=" + ErrorDescription(iLastError);
          iMaxOrders=3; //Setting iMaxOrders to 3 again thus it goes back and try to open that order again
          } 
    }

   if (count==2) 
    {
    BuyOrder_2=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_2, "Buy Order",MagicNumber, 0,Blue);
    if (BuyOrder_2>0) 
      { 
      sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + "    Buy order 2 sent successfully. Ticket=" + BuyOrder_2;
      count = count - 1; 
      }
     else {
          iLastError = GetLastError();
          sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + "    Error sending buy order 2. Error code=" + ErrorDescription(iLastError);
          iMaxOrders=2; //Setting iMaxOrders to 3 again thus it goes back and try to open that order again
          } 
    }

   if (count==1) 
    {
    BuyOrder_3=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice_3, "Buy Order",MagicNumber, 0,Blue);
    if (BuyOrder_3>0) 
      {
      sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + "    Buy order 2 sent successfully. Ticket=" + BuyOrder_3;
      iLastError = 0;
      count = count - 1; 
      }
     else {
          iLastError = GetLastError();                               
          sLog_CheckBuyConditions = sLog_CheckBuyConditions + sNL + "    Error sending buy order 2. Error code=" + ErrorDescription(iLastError);
          iMaxOrders=1; //Setting iMaxOrders to 3 again thus it goes back and try to open that order again
          }
    }  
}    //all code in red not needed                                                      
Razão: