[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 334

 
hoz:


Boris, if you comment out one of the conditions in int GetGeneralSignal(), the opening is clear.

I have tracked it down. The flag does not change its value when the profitability of currently open orders is in minus. Here is the rewritten function that should set the short and long flags to false, i.e. prohibit opening a position if there are minus orders:

The calling function is this:

Maybe the conditions for the bey are more suitable? True, I have only sells open today due to a very weak euro drop, but still, something is better than nothing!
 
borilunad:
Maybe the conditions are more suitable for the bai? Indeed, only sells are opened today because of very weak euro decline, but still something is better than nothing!


No. The signal is written in the int function GetGeneralSignal() and it works clearly. The signal is primitive, I took it just for the test. If PCI has crossed the upper border - buy, and if the lower one - sell. I do not use indices myself, but I decided to check this only for an experiment.

So there you go. Without flags, everything works perfectly. But it is not so with flags. When theint FindOrders(bool&long,bool&short) function contains an order of the given type and its profit is below zero, my function, according to the reference to function GetGeneralSignal(), must pass false value to a certain flag but in fact the flags always show true:

//+-------------------------------------------------------------------------------------+
//| Поиск своих ордеров                                                                 |
//+-------------------------------------------------------------------------------------+
int FindOrders(bool& long, bool& short)
{
   int t, total = OrdersTotal() - 1;
   double profitL,               // Профит лонговой позиции
          profitS;               // Профит шортовой позиции
   
   for (int i=total; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
          if (OrderSymbol() != Symbol()) continue;
              if (OrderMagicNumber() != i_magic) continue;
              {
                 if (OrderType() == OP_BUY)        // Найден ордер типа OP_BUY
                 {
                     if (profitL < OrderProfit())
                     {
                         profitL = OrderProfit();
                         pr("profitL =" + profitL);
                         if (profitL < 0)
                         long = false;
                     }
                 }

                 else if (OrderType() == OP_SELL)       // Найден ордер типа OP_SELL
                 {
                     if (profitS < OrderProfit())
                     {
                         pr("profitS =" + profitS);
                         profitS = OrderProfit();
                         if (profitS < 0)
                         long = false;
                     }
                 }
                 t++;
              }
   }
   
   return (t);
}  

I can see it in the printer, but it's not clear why the flag doesn't change.

By the way, I showed the profitability of orders in the print:

//+-------------------------------------------------------------------------------------+
//| Поиск своих ордеров                                                                 |
//+-------------------------------------------------------------------------------------+
int FindOrders(bool& long, bool& short)
{
   int t, total = OrdersTotal() - 1;
   double profitL,               // Профит лонговой позиции
          profitS;               // Профит шортовой позиции
   
   for (int i=total; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
          if (OrderSymbol() != Symbol()) continue;
              if (OrderMagicNumber() != i_magic) continue;
              {
                 if (OrderType() == OP_BUY)        // Найден ордер типа OP_BUY
                 {
                     Print("if (OrderType() == OP_BUY)");
                     profitL = OrderProfit();
                     pr("profitL =" + profitL);
                     if (profitL < OrderProfit())
                         if (profitL < 0)
                         long = false;
                 }

                 else if (OrderType() == OP_SELL)       // Найден ордер типа OP_SELL
                 {
                     Print("if (OrderType() == OP_SELL)");
                     profitS = OrderProfit();
                     pr("profitS =" + profitS);
                     if (profitS < OrderProfit())
                         if (profitS < 0)
                         long = false;
                 }
                 t++;
              }
   }
   
   return (t);
}

And in the print the value of the flags, this is what is shown:

I.e. it is clear that when the profitability is below zero, the corresponding flag should be set to false but this does not happen... Everything seems to be elementary, but something is not going on.

 
hoz:


No. There is a signal in the int GetGeneralSignal() function that works well. The signal is primitive, I took it just for the test. If PCI has crossed the upper border - buy, and if the lower one - sell. I do not use indices myself, but I decided to check this only for an experiment.

So there you go. Without flags, everything works perfectly. But it is not so with flags. When theint FindOrders(bool&long,bool&short) function contains an order of the given type and its profit is below zero, my function, according to the reference to function GetGeneralSignal(), must pass false value to a certain flag but the flags always contain true:

I see it in the print, but I do not understand why the flag does not change.
Look, you have written long=false in both cases, so how will it open?
 
hoz:



I can see it in the print, but why the flag doesn't change is not clear.

//+-------------------------------------------------------------------------------------+
//| Поиск своих ордеров                                                                 |
//+-------------------------------------------------------------------------------------+
int FindOrders(bool& long, bool& short)
{
   int t, total = OrdersTotal() - 1;
   double profitL,               // Профит лонговой позиции
          profitS;               // Профит шортовой позиции
   
   for (int i=total; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
          if (OrderSymbol() != Symbol()) continue;
              if (OrderMagicNumber() != i_magic) continue;
              {
                 if (OrderType() == OP_BUY)        // Найден ордер типа OP_BUY
                 {
                     Print("if (OrderType() == OP_BUY)");
                     profitL = OrderProfit();
                     if (profitL < OrderProfit())
                         if (profitL < 0)
                         long = false;
                 }

                 else if (OrderType() == OP_SELL)       // Найден ордер типа OP_SELL
                 {
                     Print("if (OrderType() == OP_SELL)");
                     profitS = OrderProfit();
                     if (profitS < OrderProfit())
                         if (profitS < 0)
                         long = false; /// ?????????????????????? 
                 }
                 t++;
              }
   }
   
   return (t);
}  
 

Corrected the typo.

//+-------------------------------------------------------------------------------------+
//| Поиск своих ордеров                                                                 |
//+-------------------------------------------------------------------------------------+
int FindOrders(bool& long, bool& short)
{
   int t, total = OrdersTotal() - 1;
   double profitL,               // Профит лонговой позиции
          profitS;               // Профит шортовой позиции
   
   for (int i=total; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
          if (OrderSymbol() != Symbol()) continue;
              if (OrderMagicNumber() != i_magic) continue;
              {
                 if (OrderType() == OP_BUY)        // Найден ордер типа OP_BUY
                 {
                     if (profitL < OrderProfit())
                     {
                         profitL = OrderProfit();
                         pr("profitL =" + profitL);
                         if (profitL < 0)
                         long = false;
                     }
                 }

                 else if (OrderType() == OP_SELL)       // Найден ордер типа OP_SELL
                 {
                     if (profitS < OrderProfit())
                     {
                         pr("profitS =" + profitS);
                         profitS = OrderProfit();
                         if (profitS < 0)
                         short = false;
                     }
                 }
                 t++;
              }
   }
   
   return (t);
}

Here's a screenshot:

You can see, on the chart, that the bai is minus and the flag = TRU anyway.

 
Good evening, could you please tell me how to make the Alert form appear only once when the condition occurs and not every time the condition is fulfilled?
 

I feel sorry for you! I'll write you how it will work without loops, which are slowed down by functions! Here's your code, but what do I change it into!

//+-------------------------------------------------------------------------------------+
//| Поиск своих ордеров                                                                 |
//+-------------------------------------------------------------------------------------+
bool& long, bool& short)
double profitL,               // Профит лонговой позиции
       profitS;               // Профит шортовой позиции
 
// int start()
 
//.........................................


  
   if(ExistPositions() == false)
   {
      if(long == true)
      {
         OrderSend(.......OPEN_BUY........................)  
      }
      if(short == true)
      {
         OrderSend(.......OPEN_SELL.........................)
   }  }
   if(ExistPositions() == true)
   {
      if(profitL > 0 && long == true && short == false)
      {
         OrderSend(.......OPEN_BUY........................)  
      }
      if(profitS > 0 && short == true && long == false)
      {
         OrderSend(.......OPEN_SELL.........................)
   }  }
      


                     
This scheme is free of cramps and works instantly! Do away with unnecessary functions! You can find ExistPositions() function in Useful Functions of Dear Kim!
 
borilunad:

I feel sorry for you! I'll write you how it will work without loops, which are slowed down by functions! Here's your code, but what do I change it into!

This scheme is easy and works instantly! Do away with unnecessary functions! You can find ExistPositions() function in Useful Functions of Kim!


Boris, theExistPositions function hasthe same loop, only it has more unnecessary checks, so it won't be sluggish along the way. Your logic is clear to me, but the reason of inoperability of the previous version wasn't disclosed, which is strange :)

You also use these flags:

 if(profitL > 0 && long == true && short == false)

And I was demonstrating that they don't return correctly.

So again, if the profitL and profitS variables will be present in this function then the flags are not needed.

That's how it turned out:

//+-------------------------------------------------------------------------------------+
//| Поиск своих ордеров                                                                 |
//+-------------------------------------------------------------------------------------+
int FindOrders(double& profitL, double& profitS)
{
   int t, total = OrdersTotal() - 1;
   
   for (int i=total; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
          if (OrderSymbol() != Symbol()) continue;
              if (OrderMagicNumber() != i_magic) continue;
              {
                 if (OrderType() == OP_BUY)              // Найден ордер типа OP_BUY
                 {
                     if (profitL < OrderProfit())
                     {
                         profitL = OrderProfit();
                         pr("profitL =" + profitL);      // Выводим профим через коммент на график
                     }
                 }
                 if (OrderType() == OP_SELL)       // Найден ордер типа OP_SELL
                 {
                     if (profitS < OrderProfit())
                     {
                         pr("profitS =" + profitS);     // Выводим профим через коммент на график
                         profitS = OrderProfit();
                     }
                 }
                 t++;
              }
   }
   
   return (t);
}
//+-------------------------------------------------------------------------------------+
//| Получаем общий торговый сигнал                                                      |
//+-------------------------------------------------------------------------------------+
int GetGeneralSignal()
{
   double profitL,               // Профит лонговой позиции
          profitS;               // Профит шортовой позиции
        
   if (FindOrders(profitL, profitS) > 30)
       return (SIGNAL_NO);

   if(ExistPositions() == false)
   {
      if (GetRSI(1) < i_RSIToUpLimit)
      {
         if (GetRSI(0) > i_RSIToUpLimit)
         {
             return (SIGNAL_BUY);
         }
      }
       if (GetRSI(1) > i_RSIToDnLimit)
       {
         if (GetRSI(0) < i_RSIToDnLimit)
         {
             return (SIGNAL_SELL);
         }
      }
   }
   if(ExistPositions() == true)
   {
      if (GetRSI(1) < i_RSIToUpLimit)
         if (GetRSI(0) > i_RSIToUpLimit)
         {
            if(profitL > 0)
               return (SIGNAL_BUY);
         }
      if (GetRSI(1) > i_RSIToDnLimit)
      {
         if (GetRSI(0) < i_RSIToDnLimit)
            if(profitS > 0)
               return (SIGNAL_SELL);
      }
   }
            
   return (SIGNAL_NO);
}

Again, it's not opening on signal, it's opening on whatever.

 
Hi all!
I am making a virtual trail and encountered a problem with closelevel=profitpips-TrailingStop that is, the trail and GlobalVariableSet("tral",0) are turned on as they should be, but the variable
closelevel variable is assigned the value of profitpips(it is the current profit in pips) instead of profitpips-TrailingStop with all ensuing consequences o_o



void Trailing()
   {
    if(!GlobalVariableCheck("tral")&&profitpips>=TrailingStart)
     {
      closelevel=profitpips-TrailingStop;
      GlobalVariableSet("tral",0);
      }
    if(GlobalVariableCheck("tral")&&profitpips>=closelevel+TrailingStop)closelevel=profitpips;
    if(GlobalVariableCheck("tral")&&profitpips<=closelevel)
     {
      Print ("ВСЁ ОТЛИЧНО ЗАКРЫЛИСЬ ПО ТРАЛЛУ");
      for (int i=0; i<NumberOfTry; i++) 
        {
         CloseAll();
         Lot=LOT;
        }
      }  
     return;}

I figured it out, the line
if(GlobalVariableCheck("tral")&&profitpips>=closelevel+TrailingStop)closelevel=profitpips;  


changed it to...
if(GlobalVariableCheck("tral")&&profitpips-TrailingStop>=closelevel+TrailingStop)closelevel=profitpips; 



Nowcloselevelis not modifiedwhen profit increases...

I've already figured it out.



 
hoz:


Boris, theExistPositions function has the sameloop, but there are more unnecessary checks, so it won't be sluggish along the way. Your logic is clear to me, but the reason of inoperability of the previous version wasn't disclosed, which is strange :)

You are also using these flags:

And I have demonstrated that they are not correctly returned.

So again, if the profitL and profitS variables will be present in this function, then the flags are not needed.

That's how it worked out:

Again it opens not by signal, but by whatever.

Then do some digging in your own place! You have a function for every word of your code, and you need to make do with variables. That's what makes the code heavy. You should use functions when you can't do without them! I commented everything in Kim's code that I don't need, and it all works very fast! Remember, I asked everyone how to make the program run faster under many conditions. Now testing runs for a year on all ticks in 5 minutes! I combed through all the conditions and functions and threw out everything unnecessary.