Trailing Stops y Trailing Profit - página 2

 
Arav007:


Lo siento, en realidad me he confundido un poco.

if(iOpenOrders_Buy = 3)

Aquí, si el total de órdenes de compra abiertas es igual a '3', el código pasará a la siguiente parte.

if(iOpenOrders_Buy> 0)

Si el número de órdenes de compra abiertas es mayor que "0", el código pasará a la siguiente parte.

if(iOpenOrders_Buy== 3)

Entonces si la cuenta de órdenes de compra abiertas es igual a 3 entonces se abrirá la orden de compra_1, si es igual a '2' entonces se abrirá la orden decompra_2 y luego laorden de compra_3 si la cuenta de órdenes de compra abiertas es igual a 1.

¿Estoy en lo cierto?

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);
....
}

tienes razón mira de nuevo el código cambiado ¿esta bien?
 
deVries:

Tienes razón, mira de nuevo el código cambiado, ¿está bien?


No lo creo.

if(Condición de compra cumplida && iOpenOrders_Buy == 0)

Esto significa que la 'Condición de Compra se cumple' y no hay órdenes de 'Compra Abierta', ¿correcto?

entonces el código pasará a la siguiente línea donde iOpenOrders_Buy = 3;

Así que se le dice al EA que ya hay 3 órdenes abiertas allí, ¿verdad?

Pero si entro en el código sabiendo que no hay órdenes de compra abiertas allí entonces ¿por qué estamos asignando iOpenOrders_Buy =3;?

También el objetivo es, uno de los tres oficios se mantendrá en funcionamiento y sólo 'Nueva' orden de compra se abrirá cuando ese último comercio se cerrará.

Así que esto tiene que ser

if(iOpenOrders_Buy== 0) // No hay ninguna orden de compra abierta por lo que tenemos que abrir nuevas órdenes de compra


Cuando el EA obtenga la condición de compra, entonces abrirá tres operaciones con diferentes Take Profit.

Entonces, si dos de las operaciones se cierran de todos modos (ya sea por TP o SL), la tercera seguirá 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")

} 

¿Qué opinas de esto? ¿Haría lo mismo que se indica arriba?

Saludos

 
Arav007:


No lo creo.


¿Qué opinas de esto? ¿Haría lo mismo que se indica arriba?

Saludos

no, que pasa si el ordersend no tiene éxito, como se comprueba que operación hay que abrir si una falla

¿por qué asignamos iOpenOrders_Buy = 3; ?

tienes que abrir 3 nuevas operaciones si ordersend tiene éxito haz iOpenOrders_Buy nuevo valor

si iOpenOrders_Buy se convierte en 0 tenemos nuestras 3 operaciones

 
deVries:

no lo que sucede si ordersend no tiene éxito, ¿cómo se comprueba que el comercio que tiene que abrir si uno falla

¿por qué asignamos iOpenOrders_Buy = 3; ?

tienes que abrir 3 nuevas operaciones si ordersend tiene éxito haz iOpenOrders_Buy nuevo valor

si iOpenOrders_Buy se convierte en 0 tenemos nuestras 3 operaciones

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;

}  

}

} 

Sí, es muy posible que 'Ordersend()' falle al abrir la orden.

Ahora entiendo por qué

if(iOpenOrders_Buy > 0 ) // tenemos que abrir nuevas órdenes de compra

se utilizó en su código. Como ya establecimos iopendOrders=3, así que lo verificará.

Pero más tarde me confundí que el valor de iopendOrders seguirá cambiando.

Probablemente por mi limitado cerebro no pude entender el mecanismo. Así que traté de implementar su lógica en la forma anterior.

¿Es esto lo que usted ha referido en su código dado?

Saludos

 
Arav007:

Sí, es muy posible que 'Ordersend()' falle al abrir la orden.

Ahora entiendo por qué

if(iOpenOrders_Buy > 0 ) // tenemos que abrir nuevas órdenes de compra

se utilizó en su código. Como ya establecimos iopendOrders=3, así que lo verificará.

Pero más tarde me confundí que el valor de iopendOrders seguirá cambiando.

Probablemente por mi limitado cerebro no pude entender el mecanismo. Así que traté de implementar su lógica en la forma anterior.

¿Es esto lo que usted ha referido en su código dado?

Saludos


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

{ 

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

 
deVries:



Por favor, no te preocupes, pero de nuevo me he confundido.

Si utilizo

count=count-1; después

Print( "Orden de compra 1 abierta con éxito");

esto significa que si la primera orden de compra se abrió, entonces el valor de la cuenta se reducirá en 1.

Así que al entrar en la siguiente función, aquí la siguiente condición 'if':

if (count==2) {}

el valor de count se ha convertido en '2' para ello. [count=3-1=2]

¿Es esto correcto?

 
Arav007:


Por favor, no te preocupes, pero de nuevo me he confundido.

Si utilizo

count=count-1; después

Print( "Orden de compra 1 abierta con éxito");

eso significa que si la primera orden de compra se abrió, entonces el valor de la cuenta se reducirá en 1.

Así que al entrar en la siguiente función, aquí la siguiente condición 'if':

if (count==2) {}

el valor de count se ha convertido en '2' para ello. [count=3-1=2]

¿Es esto correcto?


pruébalo.... haz algunas pruebas
 
deVries:

Pruébalo fuera.... hacer algunas pruebas


Cansado y este es el resultado.

Probablemente no pude colocar el código 'Cerrar la orden de venta antes de comprar' en el lugar correcto. Por lo tanto, se obtienen órdenes de venta y de compra a pesar de estar en contra del código original.

¡Y hay '4' órdenes de compra en total!

He fallado :(

                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, olvidé poner iOpenOrders_Buy ==0

Ahora probando de nuevo con esto.

 
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