Trailing Stops e Trailing Profit - pagina 2

 
Arav007:


Scusate, in realtà mi sono un po' confuso.

if(iOpenOrders_Buy = 3)

Qui se il totale degli ordini di acquisto aperti è uguale a '3' allora il codice procederà alla parte successiva.

if(iOpenOrders_Buy > 0 )

Quindi se il conteggio dell'ordine Total Opened Buy è maggiore di '0' allora si procederà alla parte successiva.

se(iOpenOrders_Buy == 3)

Allora se il conteggio degli ordini di acquisto aperti è uguale a 3 allora aprirà BuyOrder_1, se è uguale a '2' allora aprirà BuyOrder_2 e poi BuyOrder_3 se il conteggio degli ordini di acquisto aperti è uguale a 1.

Ho ragione?

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

Hai ragione, guarda di nuovo il codice modificato, va bene così?
 
deVries:

Hai ragione, guarda di nuovo il codice modificato, va bene così?


Non credo.

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

Questo significa che la "Condizione di acquisto è soddisfatta" e non ci sono ordini di acquisto aperti, giusto?

allora il codice procederà alla prossima linea dove iOpenOrders_Buy = 3;

Quindi viene detto all'EA che ci sono già 3 ordini aperti, giusto?

Ma se entro nel codice sapendo che non ci sono ordini di acquisto aperti, allora perché stiamo assegnando iOpenOrders_Buy = 3; ?

Anche l'obiettivo è, uno dei tre trade continuerà a funzionare e solo 'Nuovo' ordine di acquisto sarà aperto quando l'ultimo trade sarà chiuso.

Quindi questo deve essere

if(iOpenOrders_Buy== 0) // Non c'è nessun ordine di acquisto aperto quindi dobbiamo aprire nuovi ordini di acquisto


Quando l'EA riceverà la condizione di acquisto, aprirà tre operazioni con diversi Take Profit.

Poi se due delle operazioni vengono chiuse comunque (sia dal TP che dallo SL), la terza continuerà a funzionare.

 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")

} 

Cosa ne pensate di questo? Farebbe lo stesso come detto sopra?

Saluti

 
Arav007:


Non credo.


Cosa ne pensate di questo? Farebbe lo stesso come detto sopra?

Saluti

no cosa succede se ordersend non riesce, come si fa a controllare quale commercio si deve aprire se uno fallisce

perché stiamo assegnando iOpenOrders_Buy = 3; ?

si devono aprire 3 nuove operazioni se ordersend riesce a fare iOpenOrders_Buy nuovo valore

se iOpenOrders_Buy diventa 0 abbiamo i nostri 3 trade

 
deVries:

no cosa succede se ordersend non ha successo, come si controlla quale trade si deve aprire se uno fallisce

perché stiamo assegnando iOpenOrders_Buy = 3; ?

si devono aprire 3 nuove operazioni se ordersend ha successo fare iOpenOrders_Buy nuovo valore

se iOpenOrders_Buy diventa 0 abbiamo i nostri 3 trade

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ì, è molto probabile che 'Ordersend()' non riesca ad aprire l'ordine.

Ora ho capito perché

if(iOpenOrders_Buy > 0 ) // dobbiamo aprire nuovi ordini di acquisto

è stato usato nel tuo codice. Poiché abbiamo già impostato iopendOrders=3, quindi lo verificherà.

Ma in seguito mi sono confuso su come il valore di iopendOrders continuerà a cambiare.

Probabilmente per il mio cervello limitato non sono riuscito a capire il meccanismo. Quindi ho cercato di implementare la tua logica nel modo sopra descritto.

È questo che hai riferito nel tuo codice dato?

Saluti

 
Arav007:

Sì, è molto probabile che 'Ordersend()' non riesca ad aprire l'ordine.

Ora ho capito perché

if(iOpenOrders_Buy > 0 ) // dobbiamo aprire nuovi ordini di acquisto

è stato usato nel tuo codice. Poiché abbiamo già impostato iopendOrders=3, quindi lo verificherà.

Ma in seguito mi sono confuso su come il valore di iopendOrders continuerà a cambiare.

Probabilmente per il mio cervello limitato non sono riuscito a capire il meccanismo. Così ho cercato di implementare la tua logica nel modo sopra descritto.

È questo che hai riferito nel tuo codice dato?

Saluti


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

{ 

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

 
deVries:



Per favore, non fateci caso, ma ancora una volta mi sono confuso!

Se uso

count=count-1; dopo

Print( "Buy Order 1 Opened successfully");

ciò significa che se il primo ordine di acquisto è stato aperto, allora il valore di count sarà diminuito di 1.

Quindi, quando si entra nella funzione successiva, ecco la prossima condizione 'if':

if (count==2) {}

il valore di count è diventato '2'. [count=3-1=2]

È giusto?

 
Arav007:


Per favore, non fateci caso, ma ancora una volta mi sono confuso!

Se uso

count=count-1; dopo

Print( "Buy Order 1 Opened successfully");

ciò significa che se il primo ordine di acquisto è stato aperto, allora il valore di count sarà diminuito di 1.

Quindi, quando si entra nella funzione successiva, ecco la prossima condizione 'if':

if (count==2) {}

il valore di count è diventato '2'. [count=3-1=2]

È giusto?


provalo.... fare qualche test
 
deVries:

provate.... fare qualche test


Stanco e questo è il risultato.

Probabilmente non sono riuscito a piazzare il codice 'Closing Sell Order before buying' nel posto giusto. Quindi ho ottenuto Vendi e Compra insieme anche se è contro il codice originale.

E ci sono '4' ordini di acquisto in tutto!

Ho fallito :(

                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, ho dimenticato di mettere iOpenOrders_Buy ==0

Ora lo sto testando di nuovo con questo.

 
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