[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 240

 
couldn't find which page.
 
1Rakso писал(а) >>
I have not found the page.

Couldn't find it either. It doesn't matter.

If you work at opening prices, it's enough to check at the opening of a new bar.

int start(){
  if (! NevBar()) return(0);
  
  //.......
  
  return(0);
}

bool NevBar(){
  static int prevtime=0;
  if ( prevtime==Time[0]) return(false);
  prevtime=Time[0];
  return(true);
}

That's about right. And if the opening is possible at other prices. We should use other mechanisms.

If only one position can be opened by one symbol and timeframe, we must control the number of open positions.

int CountOrder[6];

// Функция формирует массив с количеством открытых позиций по каждому виду ордеров.
//===============================================================================
int Order_Count_Calculate(string _Symbol, int _Magic, int _OP=-1){
   ArrayInitialize( Order_Count,0);
   for (int i = OrdersTotal() - 1;  i >= 0;  i--) {
      if (!OrderSelect( i, SELECT_BY_POS, MODE_TRADES))   continue;
      if (OrderSymbol() != _Symbol)                     continue;
      if (OrderMagicNumber() != _Magic)                   continue;
      Order_Count[OrderType()]++;
   }
   if (_OP>=0) return( Order_Count[_OP]);
   return(0);
}

Now, by checking the values of the necessary array elements, we know how many positions of this type are opened.

 
rid >> :

For example (example of setting a buy stop) :

(it is not at all necessary for the set price to be in the quote stream in order to set a pending order.

You can go with the current price or with any price, as long as you adhere to the stop level from CURRENT PRICE TO THE STOP PRICE)

( 'EURUSD - Trends, Forecasts & Consequences' )

Instead of

double priceBUY=..... ....

enter your formula

EH...thanks so much especially for the attached code! Just what the doctor ordered! ))))

 
Vinin >> :

Couldn't find it either. It doesn't matter.

If you work at opening prices, it's enough to check at the opening of a new bar.

That's about right. And if the opening is possible at other prices. We should use other mechanisms.

If only one position can be opened by one symbol and timeframe, we must control the number of open positions.

Now, by checking the values of the necessary array elements, we know how many positions of this type are opened.

Vinin! Thank you!
 
total = OrdersTotal();
short = TRUE;
long = TRUE;
                      for (int cnt = 0; cnt < total; cnt++) {
                      OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES);
                      if(OrderSymbol()==Symbol() && OrderMagicNumber()== MagicNumber){
                      if (OrderType() == OP_SELL) short = FALSE;
                      if (OrderType() == OP_BUY) long = FALSE;
                      }
                      }
                    
                     

I have this in the code, but I don't understand this array, how will it detect if there was an order on this bar and it closed, and we will wait for a new bar?

How do I explain? I might have misspoken or misunderstood the function....

1) If we open an order on the zero bar and it is already closed, then we do not open another order on this bar even if there is a signal to open it because we have already had a trade on this bar and it is already closed.

On each bar it is allowed to open only one deal, if there was a deal on this bar, we do not open the order, how to do?

Help people.....))) I'm already having a meltdown \\\\\\\\>>>>

 
1Rakso писал(а) >>

I have this in my code, I don't understand how it will detect that there was an order on this bar and it closed and we will have to wait for a new bar?

How do I explain? I might have misspoken or misunderstood the function....

1) If we open an order on the zero bar and it is already closed, then we do not open another order on this bar even if there is a signal to open it because we have already had a trade on this bar and it is already closed; we just wait for the next bar.

On each bar it is allowed to open only one deal, if there was a deal on this bar, we do not open the order, how to do?

Help people.....))) I'm already having a meltdown \\\\\\\\>>>>

Check out Igor KIM's thread 'Useful functions from KimIV'. One of the functions will answer your question

 

Here I am trying to write an advisor... Just starting to learn... Error 4062 appears in tester...(ERR_STRING_PARAMETER_EXPECTED - 4062 - parameter of type string is expected)

I can't figure out where to fix it. Can someone local look at the code:)

extern double Lots = 0.9;        //лот
extern double StopLoss = 70;
extern double DecreaseFactor = 80;
extern double MaximumRisk    = 0.014;
extern double MaximumLots    = 100;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetSizeLot() //оптимизация лотов
  {
   double Lot = Lots;
   int cycle;
   int prof = 0;
   int orders = HistoryTotal();     // history orders total
   int losses = 0;                  // number of losses orders without a break
   int vinn = 0;
   int i = orders;
//---- select lot size
  Lot = NormalizeDouble(AccountFreeMargin()* MaximumRisk / 100, 1);
//----
   if(AccountFreeMargin() <= 14) 
       DecreaseFactor = 14;
//----
   if(AccountFreeMargin() > 10000) 
       DecreaseFactor = 60;
//----
   if( DecreaseFactor > 0 && orders > DecreaseFactor)
     {
       //----
       for( cycle = 1; cycle < DecreaseFactor; cycle++)
         {
           i--;
           //----
           if(OrderSelect( i, SELECT_BY_TICKET, MODE_HISTORY) == false) 
             { 
               Print("Error in history!"); 
               break; 
             } 
           //----
           if(OrderCloseTime()>0)
             {
               prof = prof + OrderProfit(); 
               if(OrderProfit() <= 0 ) 
                   losses++;
               else 
                   vinn++;
             }
         }  
       if( prof <= 0 && losses > vinn) 
           Lot = 0.1;
       if( prof <=0 && vinn > losses) 
           Lot = Lot - (0.1* losses);
       if( prof > 0 && losses > vinn) 
         {
           Lot = Lot + (0.1*NormalizeDouble( vinn / 4, 0.1));
         }
       if( prof > 0 && losses <= vinn )
         {
           Lot = Lot + (0.1*NormalizeDouble( vinn / 2, 0.1));
         }
     } 
   if(AccountFreeMargin() < 300 || Lot < 0.1) 
       Lot = 0.1;
   if( Lot*1275 >= AccountFreeMargin()) 
       Lot = NormalizeDouble(AccountFreeMargin()* MaximumRisk / 100, 1);
   if( MaximumLots != 0 && Lot > MaximumLots) 
       Lot = MaximumLots;
   if( DecreaseFactor > orders) 
       Lot = Lots;
   return( Lot);
  }  
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+  
int start()
  {
  double glav1, sig1, glav2, sig2;
  int cnt, ticket, total;
glav1 =iCustom(NULL,0,"i_Trend",0,1);
sig1 =iCustom(NULL,0,"i_Trend",1,1); 
glav2 =iCustom(NULL,0,"i_Trend",0,2);
sig2 =iCustom(NULL,0,"i_Trend",1,2); 
   total = OrdersTotal();  // проверяем есть ли открытые позиции
   if( total < 1) 
     {
       if(AccountFreeMargin() < (500* Lots))  // проверяем денежки на счету
         {
           Print("Денег почти нет, осталось всего: ", AccountFreeMargin());
           return(0);  
         }
                  }
       // проверяем открытие позиции на покупку
       if(( glav2< sig2)  &&
          ( glav1> sig1))
         {
         OrderSend(Symbol(), OP_BUY, GetSizeLot(), Ask, 3, Ask - StopLoss*Point, "AlanMod expert", 16384, 0, Green);
          return(0); 
          }
           // проверяем возможность открытия на продажу
           if(( glav2> sig2)  &&
          ( glav1< sig1))
             {
             OrderSend(Symbol(), OP_SELL, GetSizeLot(), Bid, 3, Bid + StopLoss*Point, "AlanMod expert", 16384, 0, Red);
               return(0); 
             }
          for( cnt = 0; cnt < total; cnt++)
     {
           OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES);
       if(OrderType() <= OP_SELL &&   // проверка открытой позиции 
          OrderSymbol() == Symbol())  // проверка с нашего ли она графика
         {
           if(OrderType() == OP_BUY)    // если открыта позиция на покупку
             {
                            if( glav1< sig1)// проверяем закрывать или нет?
                 {
                                    OrderClose(OrderTicket(), OrderLots(), Bid, 3, Violet); // закрыли
                   return(0);  // сваливаем
                 }
                              }
           else // если эта позиция на продажу
             {
             if( glav1> sig1)//проверяем закрывать иль нет?
         {
         OrderClose(OrderTicket(), OrderLots(), Ask, 3, Violet); // закрыли
        return(0); // сваливаем
        }
      }
    }
  }
}
 
Reys >> :

Here I am trying to write an advisor... Just starting to learn... Error 4062 appears in tester...(ERR_STRING_PARAMETER_EXPECTED - 4062 - parameter of type string is expected)

I can't figure out where to fix it. May any of you local guys look through the code:)

1) double NormalizeDouble( double value, int digits), and you have (vinn/2, 0.1)

2) OrderSend(Symbol(), OP_BUY, GetSizeLot(), Ask, 3, Ask - StopLoss*Point,NO TAKE_profit, "AlanMod expert", 16384, 0, Green);

 
Thank you, I was just ahead of you)
 

how do I name the buffers in the custom indicators?