Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 463

 
HUNTERGOOD:

The request, correctly I created back on page 457 , in paost #4567 , and all the necessary: "indicator, what is needed, and how exactly" - there, it's not difficult to describe everything, set out all the short and to the point, clearly and distinctly, and what was wrong in my first post, that my such a small request, for a man who understands in the code, ignored six pages, and as a result "banter" me on the "lights" - I write here stubby.DUPLICATE REQUEST:

(((^^^^ Good afternoon everyone. Dear programmers, please help me insert a string with the ability to specify the sound file for each Alert3.Lv1;2;3, to trigger a different sound that you specify. I'm not good at coding and programming myself.^^))

Have you tried it on the chart, does it work?

 

Can you tell me what to do: I want to place a stop and a take immediately after any order is placed. If an EA opened an order, I want to set a stop and a take. Ifan operator opened an order, I want to set astop and a take. How should I describe it more precisely? So, the Expert Advisor and the operator understand where these orders are!

This code seems to work, but is it correct?

Or is it necessary to arrange an action for each order type (Expert Advisor or operator) using FOR?

Files:
STOP_TAKE.txt  4 kb
 

How to get it right:1

2

 
Rewerpool:

How to get it right:

Codes are normally inserted here. Most people here are too lazy to parse pictures.

 
Konstantin Nikitin:

It's OK to paste the codes here. Most people here are too lazy to take pictures apart.

I thought I attached the whole code first! Just the file! Message. Then more briefly described the situation in pictures!

 

order type(Expert Advisor or operator) using FOR?



//+------------------------------------------------------------------+

//| FUNCTION of Setting open orders of Stops and Takeovers
//+------------------------------------------------------------------+
void STOP_TAKE()
{
int tip,Ticket;
double OOP,OSL,OTP;
int SPREAD = (int)MarketInfo(Symbol(),MODE_SPREAD);
if (stoploss<STOPLEVEL) stoploss=0;
if (takeprofit<STOPLEVEL) takeprofit=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS)==true)
{
tip=OrderType();
//----------IfOrderTotal()
if(tip<2 && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
OSL = OrderStopLoss();
OTP = OrderTakeProfit();
if ((OSL==0&stoploss!=0)||(OTP==0&&takeprofit!=0))
{
OOP = OrderOpenPrice();
Ticket = OrderTicket();
if (tip==OP_BUY || tip==OP_BUYSTOP || tip==OP_BUYLIMIT)
{
if (takeprofit!=0) TP = NormalizeDouble(OOP + takeprofit*Point,Digits); else TP=OTP;
if (stoploss!=0) SL = NormalizeDouble(OOP - (stoploss+SPREAD)* Point,Digits); else SL=OSL;
if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("SetStop ",Ticket," SL ",OSL," -> ",SL," TP ",OTP," -> ",TP);
else Print(Symbol()," Error STOP_TAKE",GetLastError()," Ticket ",Ticket);
}
if (tip==OP_SELL || tip==OP_SELLSTOP || tip==OP_SELLLIMIT)
{
if (takeprofit!=0) TP = NormalizeDouble(OOP - takeprofit*Point,Digits); else TP=OTP;
if (stoploss!=0) SL = NormalizeDouble(OOP + (stoploss+SPREAD)* Point,Digits); else SL=OSL;
if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL," TP ",OTP," -> ",TP);
else Print(Symbol()," Error STOP_TAKE",GetLastError()," Ticket ",Ticket);
}
}
}
//----------If(tip<2 &&Order)
else if(tip<2 && OrderSymbol()==Symbol()&& OrderMagicNumber()!=Magic)
{
OSL = OrderStopLoss();
OTP = OrderTakeProfit();
if ((OSL==0&stoploss!=0)||(OTP==0&&takeprofit!=0))
{
OOP = OrderOpenPrice();
Ticket = OrderTicket();
if (tip==OP_BUY || tip==OP_BUYSTOP || tip==OP_BUYLIMIT)
{
if (takeprofit!=0) TP = NormalizeDouble(OOP + takeprofit*Point,Digits); else TP=OTP;
if (stoploss!=0) SL = NormalizeDouble(OOP - (stoploss+SPREAD)* Point,Digits); else SL=OSL;
if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL," TP ",OTP," -> ",TP);
else Print(Symbol()," Error STOP_TAKE",GetLastError()," Ticket ",Ticket);
}
if (tip==OP_SELL || tip==OP_SELLSTOP || tip==OP_SELLLIMIT)
{
if (takeprofit!=0) TP = NormalizeDouble(OOP - takeprofit*Point,Digits); else TP=OTP;
if (stoploss!=0) SL = NormalizeDouble(OOP + (stoploss+SPREAD)* Point,Digits); else SL=OSL;
if (OrderModify(Ticket,OOP,SL,TP,0,White)) Print("STOP_TAKE",Ticket," SL ",OSL," -> ",SL," TP ",OTP," -> ",TP);
else Print(Symbol()," Error STOP_TAKE",GetLastError()," Ticket ",Ticket);
}
}
}
}
}
}
 
Rewerpool:

I thought I attached the whole code first! Just the file! Message. Then more briefly described the situation in pictures!

Well, why put a picture here. I am telling you about it.

 
Rewerpool: Orders placed manually have a magic number of 0, the EA places with its own magic number. This is what you should use as a guide.
 

@Konstantin Nikitin OK! Is the code construction for opening take profit order by Expert Advisor or by operator correct? That's why I attached a picture to make the question clearer!

 
Rewerpool:

@Konstantin Nikitin OK! Is the code construction for opening take profit order by Expert Advisor or by operator correct? That's why I attached a picture to make the question clearer!

I would have done it in the following way

for(int i=0; i<OrdersTotal(); i++)
{
     if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
     if(OrderSymbol()!=Symbol()) continue;
     
     int tip = OrderType();
     if(tip!=OP_BUY && tip!=OP_BUYSTOP && tip!=OP_BUYLIMIT) continue;
     
     // переменные которые будут использоваться в любых ордерах
     int Ticket = OrderTicket();
     double OOP = OrderOpenPrice();
     
     //---
     switch( OrderMagicNumber() )
     {
          case Magic:    // Ордера советника
               {
                    // что-то делаем
               }
               break;

          default:       // Все остальные
               {
                    // что-то делаем
               }
     }
}
Reason: