Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 200

 
solnce600:
I wonder ..... what this sign means.... I can't think of anything in the textbook about it.


Transferring by reference, allows you to modify (change) the parameter
 
Vinin:

The transfer by reference, allows modification (change) of the parameter

Thank you. I'll keep that in mind for the future.

But why doesn't the function work?

I would be grateful if you could point me in the right direction.
 
solnce600:

Thank you. I'll keep that in mind for the future.

But why isn't the function working?

I'd appreciate it if you could point me in the right direction.

I'd appreciate it if you'd point me in the right direction.
 
Vinin:

Return minimum lot also

Returned.

Now when compiling it gives error.... that Lot variable is not defined.

' ' - variable not defined C:\Program Files\Alpari NZ MT4\experts\PREDICATED LOT.mq4 (47, 39)
http://clip2net.com/s/61vFZH

Although it was defined before Start.


 double  Magic, Lot;

int start()
  {
        

  
 double Price=iOpen (Symbol (),0,0);
 

          
 int last_order_bar = 0;                                                                                                                        
 int ot = OrdersTotal();                                                                                                                        
                                                                                                                        
 if (ot>0) //если есть ордера в рынке                                                                                                                   
 {                                                                                                                      
   if (OrderSelect (ot-1,SELECT_BY_POS))                                                                                                                        
      if (OrderType ()==OP_BUY || OrderType ()==OP_SELL )                                                                                                                       
         last_order_bar = iBarShift (Symbol (),0,OrderOpenTime ());                                                                                                             
 }                                                                                                                      
                                                                                                                        
 int last_hist_order_bar = 0;                                                                                                                   
 int oht = OrdersHistoryTotal();                                                                                                                        
                                                                                                                
 if (oht>0)                                                                                                                     
 {                                                                                                                      
   if (OrderSelect (oht-1,SELECT_BY_POS, MODE_HISTORY))                                                                                                                         
      if (OrderType ()==OP_BUY || OrderType ()==OP_SELL)                                                                                                                        
         last_hist_order_bar = iBarShift (Symbol (),0,OrderOpenTime ());
                                                                                                        
        }

                                                                                                        
if (ot==0)
        
                                                                                                                        
 //if (ot==0 || last_order_bar>0) //если ордеров нет либо последний открыт не на текущем баре                                                                                                                   
 //   if (oht==0 || last_hist_order_bar>0) 
 if (Bid ==Price)
//=============================================================== 
  
if(((Open[1]-Close[1])>100*Point)&&((Open[1]-Close[1])<120*Point))
if(((High[1]-Open[1])>40*Point)&&((High[1]-Open[1])<60*Point))
if(((Close[1]-Low[1])>40*Point)&&((Close[1]-Low[1])<60*Point))

//============================================================
Lot= MarketInfo(Symbol(), MODE_MINLOT);   
if (isCloseLastPosByStop(Symbol(), OP_BUY, Magic, Lot))
{
Lot=Lot*2;
OrderSend(Symbol(),OP_SELL,Lot,Bid,1,Ask+1500*Point,Ask-300*Point,"jfh",123 );
}
else
{

Lot=0.1;        
OrderSend(Symbol(),OP_SELL,1,Bid,Lot,Ask+1500*Point,Ask-300*Point,"jfh",123 );
}
   return(0);
  }
//============================================================  
bool isCloseLastPosByStop(string sy, int op, int mn, double &ll) 
{
   double   pt;
   datetime t;
   int       dg, i, j=-1, k=OrdersHistoryTotal()-1;

   for (i=k; i>=0; i--) 
   {
     if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) 
     {
         if (OrderMagicNumber()!=mn)   continue;   // если магик не тот, переходим к следующему
         if (OrderSymbol()!=sy)        continue;   // если символ не тот, переходим к следующему
         if (OrderType()!=op)           continue;   // если тип не тот, переходим к следующему
         if (t<OrderCloseTime()) 
         {
            t=OrderCloseTime();
            j=i;
            }
         }
      }
      
   if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) 
   {
      dg=MarketInfo(OrderSymbol(), MODE_DIGITS);      // количество знаков в цене символа ордера
      pt=MarketInfo(OrderSymbol(), MODE_POINT);       // размер пункта инструмента в валюте котировки ордера
      if (MathAbs(OrderClosePrice()-OrderStopLoss())< 0.5*pt) // Если закрыт по стопу
      { 
         ll=OrderLots();                              // записываем количество лотов в ордере, закрытом по стопу
         return(true);                                // возвращаем истину
         }
      }
      
   return(False);                                     // возвращаем ложь (позиции нету, либо не по стопу)
}
 
solnce600:

Returned.

Now when compiling it gives error.... that Lot variable is not defined.

' ' - variable not defined C:\Program Files\Alpari NZ MT4\experts\PREDICATED LOT.mq4 (47, 39)
http://clip2net.com/s/61vFZH

I have defined it before Start though.




I need all the code
 
Vinin:

I need all the code
 
 double  Magic, Lot;

int start()
  {
        

  
 double Price=iOpen (Symbol (),0,0);
 

          
 int last_order_bar = 0;                                                                                                                        
 int ot = OrdersTotal();                                                                                                                        
                                                                                                                        
 if (ot>0) //если есть ордера в рынке                                                                                                                   
 {                                                                                                                      
   if (OrderSelect (ot-1,SELECT_BY_POS))                                                                                                                        
      if (OrderType ()==OP_BUY || OrderType ()==OP_SELL )                                                                                                                       
         last_order_bar = iBarShift (Symbol (),0,OrderOpenTime ());                                                                                                             
 }                                                                                                                      
                                                                                                                        
 int last_hist_order_bar = 0;                                                                                                                   
 int oht = OrdersHistoryTotal();                                                                                                                        
                                                                                                                
 if (oht>0)                                                                                                                     
 {                                                                                                                      
   if (OrderSelect (oht-1,SELECT_BY_POS, MODE_HISTORY))                                                                                                                         
      if (OrderType ()==OP_BUY || OrderType ()==OP_SELL)                                                                                                                        
         last_hist_order_bar = iBarShift (Symbol (),0,OrderOpenTime ());
                                                                                                        
        }

                                                                                                        
if (ot==0)
        
                                                                                                                        
 //if (ot==0 || last_order_bar>0) //если ордеров нет либо последний открыт не на текущем баре                                                                                                                   
 //   if (oht==0 || last_hist_order_bar>0) 
 if (Bid ==Price)
//=============================================================== 
  
if(((Open[1]-Close[1])>100*Point)&&((Open[1]-Close[1])<120*Point))
if(((High[1]-Open[1])>40*Point)&&((High[1]-Open[1])<60*Point))
if(((Close[1]-Low[1])>40*Point)&&((Close[1]-Low[1])<60*Point))

//============================================================
Lot= MarketInfo(Symbol(), MODE_MINLOT);   
if (isCloseLastPosByStop(Symbol(), OP_BUY, Magic, Lot))
{
Lot=Lot*2;
OrderSend(Symbol(),OP_SELL,Lot,Bid,1,Ask+1500*Point,Ask-300*Point,"jfh",123 );
}
else
{

Lot=0.1;        
OrderSend(Symbol(),OP_SELL,1,Bid,Lot,Ask+1500*Point,Ask-300*Point,"jfh",123 );
}
   return(0);
  }
//============================================================  
bool isCloseLastPosByStop(string sy, int op, int mn, double &ll) 
{
   double   pt;
   datetime t;
   int       dg, i, j=-1, k=OrdersHistoryTotal()-1;

   for (i=k; i>=0; i--) 
   {
     if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) 
     {
         if (OrderMagicNumber()!=mn)   continue;   // если магик не тот, переходим к следующему
         if (OrderSymbol()!=sy)        continue;   // если символ не тот, переходим к следующему
         if (OrderType()!=op)           continue;   // если тип не тот, переходим к следующему
         if (t<OrderCloseTime()) 
         {
            t=OrderCloseTime();
            j=i;
            }
         }
      }
      
   if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) 
   {
      dg=MarketInfo(OrderSymbol(), MODE_DIGITS);      // количество знаков в цене символа ордера
      pt=MarketInfo(OrderSymbol(), MODE_POINT);       // размер пункта инструмента в валюте котировки ордера
      if (MathAbs(OrderClosePrice()-OrderStopLoss())< 0.5*pt) // Если закрыт по стопу
      { 
         ll=OrderLots();                              // записываем количество лотов в ордере, закрытом по стопу
         return(true);                                // возвращаем истину
         }
      }
      
   return(False);                                     // возвращаем ложь (позиции нету, либо не по стопу)
}
 
Vinin:

I need all code

I need that after the order is closed on a stop the following order opens with the volume equal to volume which was in the LAST closed on a stop

order multiplied by 2

And if the LAST order was closed for any other reason (not a stop) - the position volume should be 0.1
 
solnce600:

Returned.

Now when compiling it gives error.... that Lot variable is not defined.

' ' - variable not defined C:\Program Files\Alpari NZ MT4\experts\PREDITIONS.mq4 (47, 39)
http://clip2net.com/s/61vFZH

But it is defined before Start.

It compiles. It seems to me - your logic is totally lame there... Of course, I didn't look through it. I only checked it for errors.

double  Magic, Lot;

int start() {

   double Price=iOpen(Symbol(),0,0);
          
   int last_order_bar=0; 
   int ot=OrdersTotal();
   if (ot>0)  {
      if (OrderSelect(ot-1,SELECT_BY_POS))
         if (OrderType()==OP_BUY || OrderType()==OP_SELL) last_order_bar=iBarShift(Symbol(),0,OrderOpenTime());
      }

   int last_hist_order_bar=0;
   int oht=OrdersHistoryTotal(); 

   if (oht>0) {
      if (OrderSelect(oht-1,SELECT_BY_POS, MODE_HISTORY))
         if (OrderType ()==OP_BUY || OrderType ()==OP_SELL) last_hist_order_bar=iBarShift(Symbol(),0,OrderOpenTime())
      }

   if (ot==0)
      if (Bid==Price)
  //=============================================================== 
         if(((Open[1]-Close[1])>100*Point)&&((Open[1]-Close[1])<120*Point))
            if(((High[1]-Open[1])>40*Point)&&((High[1]-Open[1])<60*Point))
               if(((Close[1]-Low[1])>40*Point)&&((Close[1]-Low[1])<60*Point))
  //============================================================
                  Lot=MarketInfo(Symbol(), MODE_MINLOT);   
                  if (isCloseLastPosByStop(Symbol(), OP_BUY, Magic, Lot)) {
                     Lot=Lot*2;
                     OrderSend(Symbol(),OP_SELL,Lot,Bid,1,Ask+1500*Point,Ask-300*Point,"jfh",123 );
                     }
                  else {
                     Lot=0.1;        
                     OrderSend(Symbol(),OP_SELL,1,Bid,Lot,Ask+1500*Point,Ask-300*Point,"jfh",123 );
                     }
   return(0);
}
//+----------------------------------------------------------------------------+
bool isCloseLastPosByStop(string sy, int op, int mn, double &ll) {
   double   pt;
   int      t, dg, i, j=-1, k=OrdersHistoryTotal()-1;

   for (i=k; i>=0; i--) {
     if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
         if (OrderMagicNumber()!=mn)   continue;   // если магик не тот, переходим к следующему
         if (OrderSymbol()!=sy)        continue;   // если символ не тот, переходим к следующему
         if (OrderType()!=op)          continue;   // если тип не тот, переходим к следующему
         if (t<OrderCloseTime()) {
            t=OrderCloseTime();
            j=i;
            }
         }
      }
   if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {
      dg=MarketInfo(OrderSymbol(), MODE_DIGITS);      // количество знаков в цене символа ордера
      pt=MarketInfo(OrderSymbol(), MODE_POINT);       // размер пункта инструмента в валюте котировки ордера
      if (MathAbs(OrderClosePrice()-OrderStopLoss())<0.5*pt) { // Если закрыт по стопу
         ll=OrderLots();                              // записываем количество лотов в ордере, закрытом по стопу
         return(true);                                // возвращаем истину
         }
      }
   return(False);                                     // возвращаем ложь (позиции нету, либо не по стопу)
}
//+----------------------------------------------------------------------------+

datetime is the same as int

 
artmedia70:

It compiles. I think your logic is totally flawed there... I didn't look at it, of course. I only checked it for errors.

Datetime is the same int.



Thank you very much.

Everything compiles.

But........

- opens a position on EVERY five-minute period (every candle)

- the order volume does not change after the last stop