Трейлинг-стопы и трейлинг-профит - страница 2

 
Arav007:


Извините, на самом деле я немного запутался.

if(iOpenOrders_Buy = 3)

Если общее количество открытых ордеров на покупку равно '3', то код переходит к следующей части.

if(iOpenOrders_Buy > 0 )

Если количество всего открытых ордеров на покупку больше '0', то код переходит к следующей части.

if(iOpenOrders_Buy == 3)

Тогда если количество открытых ордеров на покупку равно 3, то откроется BuyOrder_1, если равно '2', то откроется BuyOrder_2 и затем BuyOrder_3, если количество открытых ордеров на покупку равно 1.

Я прав?

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

Вы правы, посмотрите еще раз на измененный код, это нормально?
 
deVries:

Вы правы, посмотрите еще раз на измененный код, это нормально?


Я так не думаю.

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

Это означает, что "условие покупки выполнено" и нет "открытых ордеров на покупку", верно?

тогда код перейдет к следующей строке, где iOpenOrders_Buy = 3;

Таким образом, эксперту сообщается, что уже есть 3 открытых ордера, верно?

Но если я ввожу код, зная, что там нет открытых ордеров на покупку, то почему мы присваиваем iOpenOrders_Buy = 3;?

Также цель состоит в том, чтобы одна из трех сделок продолжала работать, и только "новый" ордер на покупку будет открыт, когда последняя сделка будет закрыта.

Поэтому должно быть следующее

if(iOpenOrders_Buy== 0) // Открытых ордеров на покупку нет, поэтому мы должны открыть новые ордера на покупку.


Когда советник получит условие Buy, он откроет три сделки с разными Take Profit.

Затем, если две из сделок все равно будут закрыты (по TP или SL), третья будет продолжать работать.

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

} 

Что вы думаете об этом? Будет ли это делать то же самое, что указано выше?

С уважением,

 
Arav007:


Я так не думаю.


Что вы думаете по этому поводу? Будет ли это делать то же самое, что указано выше?

С уважением,

нет, что происходит, если ордера не удаются, как вы проверяете, какую сделку нужно открыть, если одна не удалась

почему мы присваиваем iOpenOrders_Buy = 3; ?

вы должны открыть 3 новые сделки, если ordersend успешен, сделайте iOpenOrders_Buy новым значением.

если iOpenOrders_Buy становится 0, то у нас есть наши 3 сделки

 
deVries:

нет, что происходит в случае неудачного завершения ордеров, как проверить, какую сделку нужно открыть, если одна не удалась

почему мы присваиваем iOpenOrders_Buy = 3; ?

вы должны открыть 3 новые сделки, если ordersend успешен, сделайте iOpenOrders_Buy новым значением.

если iOpenOrders_Buy становится 0, то у нас есть наши 3 сделки.

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;

}  

}

} 

Да, очень возможно, что 'Ordersend()' не удается открыть ордер.

Теперь я понял, почему

if(iOpenOrders_Buy > 0 ) // мы должны открыть новые ордера на покупку

был использован в вашем коде. Так как мы уже установили iopendOrders=3, то он это проверит.

Но потом я запутался, как значение iopendOrders будет меняться.

Вероятно, из-за ограниченности моего мозга я не смог понять механизм. Поэтому я попытался реализовать вашу логику вышеописанным способом.

Это то, что вы указали в приведенном вами коде?

С уважением,

 
Arav007:

Да, очень возможно, что 'Ordersend()' не может открыть ордер.

Теперь я понял, почему

if(iOpenOrders_Buy > 0 ) // мы должны открыть новые ордера на покупку

был использован в вашем коде. Так как мы уже установили iopendOrders=3, то он это проверит.

Но потом я запутался, как значение iopendOrders будет меняться.

Вероятно, из-за ограниченности моего мозга я не смог понять механизм. Поэтому я попытался реализовать вашу логику вышеописанным способом.

Это то, что вы указали в приведенном вами коде?

С уважением,


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

{ 

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

 
deVries:



Пожалуйста, не обращайте внимания, но я опять запутался!

Если я использую

count=count-1; after

Print( "Buy Order 1 Opened successfully");

это означает, что если первый ордер на покупку был открыт, то значение count будет уменьшено на 1.

Поэтому при входе в следующую функцию, здесь следующее условие 'if':

if (count==2) {}

значение count стало равно '2'. [count=3-1=2].

Правильно ли это?

 
Arav007:


Пожалуйста, не обращайте внимания, но я опять запутался!

Если я использую

count=count-1; after

Print( "Buy Order 1 Opened successfully");

это означает, что если первый ордер на покупку был открыт, то значение count будет уменьшено на 1.

Поэтому при входе в следующую функцию, здесь следующее условие 'if':

if (count==2) {}

значение count стало равно '2'. [count=3-1=2].

Правильно ли это?


попробуйте.... провести тестирование
 
deVries:

попробуйте это сделать.... сделайте несколько тестов


Устал и вот результат.

Вероятно, я не смог разместить код 'Закрытие ордера на продажу перед покупкой' в нужном месте. Отсюда и продажи и покупки, хотя это противоречит оригинальному коду.

И всего '4' ордера на покупку!

Я потерпел неудачу :(

                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

}  

}
 

опс, забыл поставить iOpenOrders_Buy ==0

Теперь тестируем снова с этим.

 
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                                                      
Причина обращения: