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

 
lottamer:


this modifier was not written by me.

I got it ready from the libraries.

That's why I can't clean it either. the main thing is that it's 100% working.

But why the parameter inside it is not optimized - that's the question.....

There are no basic errors!

The rest of the code works.

Put any conditions on the algorithm.

- buy

-modify

- close

---------------------------

and try to optimize the parameter inside the order MODIFICATION - i.e. stop and take

Well, as long as it works, and even more so if it's 100%, then there's no problem with it. Why should we look for errors in it? - That means it's not the problem! - And if you are looking for an error, it means that you're not 100% sure. So the problem is not in the code but in your evaluation criteria, because they confuse you too. (You started it : ))) I'm just adding oil to it...)

What is presented here - I do not even know how to call it ... Probably - a single action bloated to the size of a function. In most programs this kind of application is not optimal - modification in one block goes with something else. - Although. there may be different conditions of application. But my point is that there is nothing to optimize here... As it is only an action.

 
lottamer:

Look,

If I return everything back now, i.e. remove external STOP and TAKE parameters and write numbers inside the function instead of them, then the EA has been run week after week for 10 weeks and shows clear results.

And if I manually change the stop and takeoff parameters - everything will work and give slightly different results (of course)

And now why, when I take these parameters outside the modifier - the optimizer considers them insignificant?

That's exactly what I'm trying to tell you - that the problem is most likely elsewhere, not in this function. So you have something else mixed up. Maybe these SL and TP are applied in some other places that somehow overlap or something else. We can only guess. - That is why you have to look at the whole code. And no one can help you blindly. - There are no wizards here.

You see, you ask questions but you don't give all the information you need to find out the reason (hiding your know-how reasonably). - As in the example with the plug. - But how can you help in this case? - The answer is that you cannot. All the help is meaningless. And it also takes a lot of energy.

 
Chiripaha:

Well, if it works, and even more so if it's 100%, then there's no problem with it. So why should you look for an error in it? - So, the problem is not in it! - If you are searching for an error, it means that you are not 100% sure. So the problem is not in the code but in your evaluation criteria, because they confuse you too. (You started it : ))) I'm just adding oil to it...)

What is presented here - I do not even know how to call it ... Probably - a single action bloated to the size of a function. In most programs this kind of application is not optimal - modification in one block goes with something else. - Although. there may be different conditions of application. But my point is that there is nothing to optimize here... As it is only an action.

I'm looking in it, because we changed it ONLY and because it's where the optimisable parameters are.

how is there nothing to optimise? stop and take sizes are optimised!

 
Chiripaha:

That's exactly what I'm trying to tell you - that the problem is probably somewhere else, not in this function. So you have something else confused. Maybe these SLs and TPs are applied in some other places that somehow overlap or something else... We can only guess. - That is why you have to look at the whole code. And no one can help you blindly. - There are no wizards.

You see, you ask questions and you leave out some of the information needed to identify the cause (sensibly hiding your know-how). - As in the example with inludes. - But how can you help in this case? - The answer is that you cannot. All the help is meaningless. And it also takes a lot of energy.

I understand...

we need to take a break... and think...

look at....

and I think I know where...

 
lottamer:

I'm looking in it, because we changed it ONLY and because it's where the optimisable parameters are.

how is there nothing to optimise? stop and take sizes are optimised!

: )))))) What are they optimised for? the modification of the order? - That's not what you just said.

They should be optimised in relation to the program, its conditions - which you are reliably hiding. But it cannot be optimized in relation to a single action.

In this case, the developer just has to decide these points by himself. We all go through it, trust me. : )) So do I and other colleagues. You cannot ask for help and hide. Then you have to reveal - in this case make it public at all, as the forum is public - your cards.
 
Chiripaha:

: )))))) In what way are they optimised? In order modification? - That's not what you just said.

They should be optimized in relation to the program, its conditions - which you are reliably hiding. But you can't optimize it in relation to a single action.

In this case, the developer just has to decide these points by himself. We all go through it, trust me. : )) So do I and other colleagues. You can't ask for help and hide it. Then you have to disclose - in this case, make it public at all, as the forum is public - your cards.

I will now prepare all the code and show........
 

here is the code :

EURUSD pair

//+------------------------------------------------------------------+
//|                                                           33.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#include <WinUser32.mqh>
#include <b-Positions.mqh>

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+

extern  int  STOP = 100; 
extern  int  TAKE = 200;

double  Ma_1, Ma_2,  m2, m3; // m2 и m3 - это маркеры



//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  
Ma_1=iMA(NULL,PERIOD_M15,20, 0,MODE_SMA,PRICE_CLOSE,1) ;

Ma_2=iMA(NULL,PERIOD_M15,100,0,MODE_SMA,PRICE_CLOSE,1) ;





//=============================BUY_CONDITIONS=============================================
    

if (Ma_1>Ma_2 && m2==0)     {My_close();  My_buy ();  My_modify();  m2=1;   }  // закрыть если висят открытые позы   
                                                                                                   // и открыть новую
//=============================SELL_CONDITIONS=============================================
 
if (Ma_1<Ma_2 && m3==0)     {My_close();  My_sell ();  My_modify();  m3=1;  }    
 
//======================================

if  ( OrdersTotal()==0 && (m2==1 || m3==1)) {m2=0; m3=0;}  // обнуляет маркеры при закрытии позиций,
                                                           // что дает возможность открывать снова
//==============переход в безубыток ========================
   
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
   
if  (OrderProfit()>0.5)  {My_modify_close_zero ();}


return(0);
  }

//============================функция  ПРОДАТЬ==============================================

int My_sell()
{
    OrderSend (Symbol( ), OP_SELL,  0.01 ,Bid, 0, 0, 0, NULL, 0, 0, CLR_NONE);

}
return;

///==================================КУПИТЬ==========================================
int My_buy ()
{
     OrderSend (Symbol( ), OP_BUY, 0.01 ,Ask, 0, 0, 0, NULL, 0, 0, CLR_NONE);
}
return;


//+---------------------МОДИФИЦИРОВАТЬ сделку сразу по открытии---------------------------------------------+


int My_modify()
 {
   bool   result;
   double take_profit,stop_loss,point;
   int    cmd,total,error;
//----
   total=OrdersTotal();
   point=MarketInfo(Symbol(),MODE_POINT);
//----
//   for(int i=0; i<total; i++)
//     {
      if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES))
        {
         //---- print selected order
         OrderPrint();
         cmd=OrderType();
         //---- buy or sell orders are considered
         if(cmd==OP_BUY || cmd==OP_SELL)
           {
            //---- modify first market order
            while(true)
              {
               if(cmd==OP_BUY) stop_loss=OrderOpenPrice()-STOP*point;
               else            stop_loss=OrderOpenPrice()+STOP*point;
               
                if(cmd==OP_BUY) take_profit=OrderOpenPrice()+TAKE*point;
                           else take_profit=OrderOpenPrice()-TAKE*point;
               
               
               result=OrderModify(OrderTicket(),0,stop_loss, take_profit,0,CLR_NONE);
               if(result!=TRUE) { error=GetLastError(); Print("LastError = ",error); }
               else error=0;
               if(error==135) RefreshRates();
               else break;
              }
             //---- print modified order (it still selected after modify)
             OrderPrint();
//            break;
           }
        }
      else { Print( "Error when order select ", GetLastError()); }
//     }

   return(0);
  }
  
  
//==============================выставить стопы в безубыток============================================================
int My_modify_close_zero ()
{
   bool   result;
   double stop_loss,point;
   int    cmd,total,error;
//----
   total=OrdersTotal();
   point=MarketInfo(Symbol(),MODE_POINT);
//----
//   for(int i=0; i<total; i++)
//     {
      if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES))
        {
         //---- print selected order
         OrderPrint();
         cmd=OrderType();
         
         //---- buy or sell orders are considered
         if(cmd==OP_BUY || cmd==OP_SELL)
           {
            //---- modify first market order
            while(true)
              {
               if(cmd==OP_BUY) stop_loss=OrderOpenPrice();
               else            stop_loss=OrderOpenPrice();
               
               result=OrderModify(OrderTicket(),OrderOpenPrice(),stop_loss,OrderTakeProfit(),0,CLR_NONE);
               if(result!=TRUE) { error=GetLastError(); Print("LastError = ",error); }
               else error=0;
               if(error==135) RefreshRates();
               else break;
              }
             //---- print modified order (it still selected after modify)
             OrderPrint();
//             break;
           }
        }
      else { Print( "Error when order select ", GetLastError()); }
//     }
//----
   return(0);
  }

  
//=================ЗАКРЫТЬ СДЕЛКУ=======================================================
int My_close()
  {
   bool   result;
   double price;
   int    cmd,error;
//----
   if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES))
     {
      cmd=OrderType();
      //---- first order is buy or sell
      if(cmd==OP_BUY || cmd==OP_SELL)
        {
         while(true)
           {
            if(cmd==OP_BUY) price=Bid;
            else            price=Ask;
            result=OrderClose(OrderTicket(),OrderLots(),price,3,CLR_NONE);
            if(result!=TRUE) { error=GetLastError(); Print("LastError = ",error); }
            else error=0;
            if(error==135) RefreshRates();
            else break;
           }
        }
     }
   else Print( "Error when order select ", GetLastError());
//----
   return(0);
  }
 
lottamer:

here is the code :

EURUSD pair

b-Positions.mqh attach it - otherwise you won't be able to run it - you won't see how it works.
 
Chiripaha:
b-Positions.mqh attach - otherwise you won't be able to run it - you won't be able to see it working.

Files:
b-positions.mqh  90 kb
 
lottamer:
I have a question - why do you need this file as an plug-in, if you have all the necessary functions in the Expert Advisor itself? Are you planning to do something else?
Reason: