[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 126

 
agat8430:


Then tell me how to edit the code so it doesn't look hacked if you understand what I'm saying. It's my first time on the forum, and I got a beautiful answer.

"Genius people have a genius answer."


Make the names of the variables "readable".
 
hoz:


No, not without a stop. I just posted a piece of it. Here's my Breakeven function:

The line clearly shows that if the calculated stop is equal to the one you already have, there will be no modification! Right? So the check was initially there? But error 1 was constantly popping up, until I had entered another condition in the start before the modification function:

This is why.... that's what I want to understand. I think I've described everything thoroughly.

This function is used for all modifications, such as setting SL and TP, moving positions and orders trawling with attempts and error checks.

And the start only needs to prescribeposition selection, conditions and warnings. Here is the function:

void ModifyOrder(int ticket,double price,double stoploss,double takeprofit,datetime e,color arrow_color)
{
  int ModifyCnt = 0, err;
  while(ModifyCnt < 3)
  {
    if(OrderModify(ticket,NormalizeDouble(price,Digits),NormalizeDouble(stoploss,Digits),
    NormalizeDouble(takeprofit,Digits),0,arrow_color))
    ModifyCnt = 3;
    else err = GetLastError();
    if(err > 0)
    { 
      Print(ModifyCnt," #",ticket," Error modifing order: (", err , ") " , ErrorDescription(err));
      Sleep(5000); RefreshRates(); ModifyCnt++;
} } }
It's a small one, but it's a big one!
 
borilunad:

For newcomers first and foremost:

Forum navigator and answers to frequently asked questions. Highly recommended reading!( 1 2 3 4 5 6 ) 51 18.02.2011 FAQ


Thank you! Will definitely read it .

The world is not without good people.

 
hoz:

Give the variables a "readable" name.


I want to modify not all open orders but only the start and the last T/P order. Help me out. here is the code

 /* Так и до бана не далеко */
 

Hello all. I take indicator values in a separate window from an already formed bar (i.e. bar 1) that I count once on bar 0 on its first tick. Everything works quickly and correctly.But if I turn off the computer and after some time to switch back on, the indicators continue to work properly, but their values at the time when the computer was off, there is just an empty place. i.e. there are indicator values before and after the computer switch on. But just switch back and forth from TF to TF - all the "missing" values appear. Theindicators are standard - CCI, AO, etc. The codes were taken from the forums, I am attaching them, please explain where I am wrong and what I do not understand.



      Код №1
        ------


int start()
  {  
              
//--------------------------------------------------------------------
   Fun_New_Bar();                               // Обращение к ф-ии
   if (New_Bar==false)                          // Если бар не новый..
      return;                                   // ..то уходим
//--------------------------------------------------------------------    
        
    int counted_bars=IndicatorCounted(),
       limit;  
       
    if(counted_bars>0)
      counted_bars--;
   
      limit=Bars-counted_bars;

   for(int i=0;i<limit;i++)
       
//-------------------------------      
   { 
   
              
      КОД ИНДИКАТОРА
      
                               
   }     
//-------------------------------
   return(0);
 
  }
   
//+------------------------------------------------------------------+  
void Fun_New_Bar()                              // Ф-ия обнаружения ..
  {                                             // .. нового бара
   static datetime New_Time=0;                  // Время текущего бара
   New_Bar=false;                               // Нового бара нет
   if(New_Time!=Time[0])                        // Сравниваем время
     {
      New_Time=Time[0];                         // Теперь время такое
      New_Bar=true;                             // Поймался новый бар
     }
  }
//--------------------------------------------------------------------  



        Код №2
        ------


int start()
{  
     if (NewBar() == true)
  {  
         
    int counted_bars=IndicatorCounted(),
       limit;  
       
    if(counted_bars>0)
      counted_bars--;
   
      limit=Bars-counted_bars;

   for(int i=0;i<limit;i++)
//-------------------------------      
   { 
   
              
      КОД ИНДИКАТОРА
      
                               
   }     
//-------------------------------           
  }    

   return(0); 
}
   
//+------------------------------------------------------------------+    
bool NewBar()
{
   static datetime lastbar = 0;
   datetime curbar = Time[0];
   if(lastbar!=curbar)
   {
      lastbar=curbar;
      return (true);
   }
   else
   {
      return(false);
   }
}


      
          Код №3
          ------


//--- buffers
double ExtMapBuffer1[];
//--- for one bar
datetime Last,New;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMapBuffer1);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    New=Time[0]; 
      
     if(Last!=New)     
   {
  
  int counted_bars=IndicatorCounted(),
       limit;  
       
    if(counted_bars>0)
      counted_bars--;
   
      limit=Bars-counted_bars;
//----
   for(int i=0;i<limit;i++)
//-------------------------------      
   { 
   
              
      КОД ИНДИКАТОРА
      
                               
   }     
//-------------------------------             
   
    Last=New;
   }     
//----
   return(0);
  }
//+------------------------------------------------------------------+




       Код №4
       ------


int start()
  {
      if(last>=Time[0]) return;
  
    int counted_bars=IndicatorCounted(),
       limit;  
       
    if(counted_bars>0)
      counted_bars--;
   
      limit=Bars-counted_bars;
//----
   for(int i=0;i<limit;i++)
       
//-------------------------------      
   { 
   
              
      КОД ИНДИКАТОРА
      
                               
        
//-------------------------------              
       
      last=Time[0];      
   } 
//----
   return(0);
  }
//+------------------------------------------------------------------+

 
borilunad:

I have a function for all modifications such as setting SL and TP, transferring to B/S, trawling positions and orders with attempts and error checks.

I only need to prescribe position selection, conditions and warnings in the start. Here is the function:

Small but clever!


Wow :) Thank you. I'll have to have a look!
 
agat8430:


I want to modify not all open orders but only the start and the last order on T/P I want to make an EA for myself.

Actually, we should "screen out" all closed orders, not counting the magician and the symbol, of course. Then you should select the initial and the last order to modify.

The OrderSelect (g_pos_300, SELECT_BY_POS, MODE_TRADES); - this is the last order.

And the OrderSelect(0, SELECT_BY_POS, MODE_TRADES); - this will be the first order.

This is a branch with questions on the language, and I have answered your question. Bots are not engaged in redesign here. But you can find everything to include it in the Expert Advisor if you have a slightest understanding of the language. Hope that helped...

 
agat8430:


I want it to modify not all open orders but only the start and the last T/P order. I want it to modify not all open orders but only the last T/P order.

For catching the right items, use Kim's "Useful Features" for almost every possible occasion!

https://www.mql5.com/ru/forum/131859

 
hoz:

Generally, closed orders should be "screened out", not counting the magician and the symbol, of course. Then select the initial and the last order to modify.

The OrderSelect(g_pos_300, SELECT_BY_POS, MODE_TRADES); - this is the last order.

And the OrderSelect(0, SELECT_BY_POS, MODE_TRADES); - this will be the first order.

This is a branch with questions on the language, and I have answered your question. Bots are not engaged in redesign here. But you can find everything to include it in the Expert Advisor if you have a slightest understanding of the language. Hope that helped...

Sorry, it won't work! Not the first one, not the last one!
 
MK07:

I take indicator values in a separate window from an already formed bar (i.e. from bar #1) that I count once on bar #0 on its first tick. everything works quickly and correctly. but if I turn off the computer and after some time to turn on again, the indicators continue to work properly, but their values at the time when the computer was off do not exist.All I need to switch back and forth between TF and TF, all "missing" values will reappear.

Code #1

        ------


int start()
  {  
              
//--------------------------------------------------------------------
   Fun_New_Bar();                               // Обращение к ф-ии
   if (New_Bar==false)                          // Если бар не новый..
      return;                                   // ..то уходим
//--------------------------------------------------------------------    
        
    int counted_bars=IndicatorCounted(),
       limit;  
       
    if(counted_bars>0)
      counted_bars--;
   
      limit=Bars-counted_bars;

   for(int i=0;i<limit;i++)
       
//-------------------------------      
   { 
   
              
      КОД ИНДИКАТОРА
      
                               
   }     
//-------------------------------
   return(0);

  }
   
//+------------------------------------------------------------------+  
void Fun_New_Bar()                              // Ф-ия обнаружения ..
  {                                             // .. нового бара
   static datetime New_Time=0;                  // Время текущего бара
   New_Bar=false;                               // Нового бара нет
   if(New_Time!=Time[0])                        // Сравниваем время
     {
      New_Time=Time[0];                         // Теперь время такое
      New_Bar=true;                             // Поймался новый бар
     }
  }

//--------------------------------------------------------------------  

        Код №2
        ------


int start()
{  
     if (NewBar() == true)
  {  
         
    int counted_bars=IndicatorCounted(),
       limit;  
       
    if(counted_bars>0)
      counted_bars--;
   
      limit=Bars-counted_bars;

   for(int i=0;i<limit;i++)
//-------------------------------      
   { 
   
              
      КОД ИНДИКАТОРА
      
                               
   }     
//-------------------------------           
  }    

   return(0); 
}
   
//+------------------------------------------------------------------+    
bool NewBar()
{
   static datetime lastbar = 0;
   datetime curbar = Time[0];
   if(lastbar!=curbar)
   {
      lastbar=curbar;
      return (true);
   }
   else
   {
      return(false);
   }

}

         Код №3
          ------


//--- buffers
double ExtMapBuffer1[];
//--- for one bar
datetime Last,New;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMapBuffer1);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
    New=Time[0]; 
      
     if(Last!=New)     
   {
  
  int counted_bars=IndicatorCounted(),
       limit;  
       
    if(counted_bars>0)
      counted_bars--;
   
      limit=Bars-counted_bars;
//----
   for(int i=0;i<limit;i++)
//-------------------------------      

   { 

       Код №4
       ------


int start()
  {
      if(last>=Time[0]) return;
  
    int counted_bars=IndicatorCounted(),
       limit;  
       
    if(counted_bars>0)
      counted_bars--;
   
      limit=Bars-counted_bars;
//----
   for(int i=0;i<limit;i++)
       
//-------------------------------      
   { 
   
              
      КОД ИНДИКАТОРА
      
                               
        
//-------------------------------              
       
      last=Time[0];      
   } 
//----
   return(0);
  }
//+------------------------------------------------------------------+

Use theSRC button at the top to paste the code! No one will poke around like that. I've pasted it for you. You can do the same in your post.
Reason: