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

 
STARIJ:
Below is this:

Mouse click event on graphical object

CHARTEVENT_OBJECT_CLICK

X coordinate

Y coordinate

Name of the graphical object where the event occurred


Ugh, I think I've got it all figured out)
Thanks for the help!

 

I don't know how to link the result "r" to a buffer to display it on a graph, please advise.

I can't understand the examples in the textbooks, I've asked people

They write - "Write the value of "r" in the buffer, and it will appear on the graph." and "Usually you write to the buffer through a for loop. "

but that doesn't tell me anything!

One result is just the letter "r" and that's it, I can't find it anywhere.


And one more thing

how to smooth out the result "r" for example.

Thank you for your attention!
 

What is the error? When running in the tester, the function deletes the pending order and sometimes not. Why? The principle of operation is the following: when the Buy order is closed by TP, the BuyLimit is removed. Please advise

////+------------------DELETE BUYLIM-----------------------------------+
   if((SchBuyLimLots(Symbol())-SchBuyLots(Symbol()))!=0)                  //  лот байлимит НЕ лот бая
     {     
      for(int i=0;i<OrdersTotal();i++)
        {
         datetime T_op=0,T_lim=0,buys=0;
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) break;
         if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=SMB_) continue;
         if(OrderType()==OP_BUY)
         if(OrderCloseTime()>buys) buys+=OrderCloseTime();
         buys= OrderCloseTime();
         T_op=buys;                                                       //  время закрытия бая
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
         if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=SMB_) continue;
           {
            if(OrderType()==OP_BUYLIMIT)
              {
               T_lim=OrderOpenTime();                                     //  время закрытия селл
               ticket=OrderTicket();
               if(T_lim<=T_op)                                            //  разность
               res=OrderDelete( ticket,clrMagenta);
               if(res<1)
               {
                  Print(GetLastError());
               }
              }
           }
        }
     }
 
ZZuretc:

What is the error? When running in the tester, the function deletes the pending order and sometimes not. Why? The principle of operation is the following: when the Buy order is closed by TP, the BuyLimit is removed. Please advise .


OrdersTotal() != OrdersHistoryTotal()

 
Alexey Viktorov: I haven't looked at the miracle myself.

Thank you.

 
Can you tell me how to find the maximum and minimum values of the current ATR?
Files:
q6a0hh.PNG  12 kb
 

Hi all.

Made a simple Expert Advisor based on Stochstick (sells on top peak, buys on bottom peak), and the compiler gives an error on the spot.

Can anyone tell me what's the reason and what this error means? At first I thought I forgot to put a parenthesis somewhere.

But no, I checked it several times and it seems everything is ok with brackets. I will be very grateful to you for help.

Here are errors the compiler generates: ')' - not all control paths return a value Stohastic-Signals-33.mq4 177 3

')' - not all control paths return a value Stohastic-Signals-33.mq4 210 3

Here is the Expert Advisor itself and an mq4 file attached too:

Please advise how to attach the Expert Advisor to this file (in the editor with colored letters)

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

//| Stohastic-Signals-33.mq4

//| Copyright 2017, MetaQuotes Software Corp. |

//| https://www.mql5.com |

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

#property copyright "Copyright 2017, MetaQuotes Software Corp."

#property link "https://www.mql5.com"

#property version "1.00"

#property strict

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

bool New_Bar=false; // flag of a new bar.

extern double H_line=80; // Stochastic upper (overbought) line

extern double L_line=20; // Lower (oversold) line of Stochastic

extern inttern Slippage=2; // Slippage

extern int SL; // SL of the order being set

extern int TP; // TP of the order being set

extern double Lts; //Lot size of the order being set

bool B_Flag=false; // signal flag for BUY

S_Flag=false, // Flag for a SELL signal

ORD_Buy=false, // Flag open Buy position

ORD_Sell=false; // Flag open Sell position

bool Work=true; // Flag which allows expert to work. true-no critical error, false-existent.

string Symb; // Name of the financial instrument

int Crit_Error=11111111; // Number of critical error

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

//| expert tick function |

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

void OnTick()

{

int

Total, // Number of orders in the window

Tip=-1, // Order type selected (B=0,S=1)

Ticket; // Order number

double

M_1, M_2, M_3, // MAIN value on 1, 2 and 3 bars

Lot; // Number of lots in the selected order

bool Ans_Close; // Flag of successful order closing(1-closed, 0-not closed)

bool Ans_Open; // Flag whether the order is successfully opened (1-closed, 0-not opened)

//--------------------------------------------------------------- 1 --

// Check for a critical error

if(Work==false) // Critical error

{

Alert("Critical error. Expert Advisor not working;)

return; // Exit from start()

}

//--------------------------------------------------------------- 2 --

// New bar

Fun_New_Bar(); // Call of the function

if (New_Bar==false) // If the bar is not new

return; // ...then exit

//------------------------------------------------------------- 3 --

// Order counting

Symb=Symbol(); // Name of the financial instrument.

Total=0; // Number of orders

for(int i=1; i<=OrdersTotal(); i++) // Order loop

{

if(OrderSelect(i-1,SELECT_BY_POS)==true) // If the following

{ // Order analysis:

if (OrderSymbol()!=Symb)continue; // Not our financial instrument

Ticket=OrderTicket(); // Order number selected.

Tip =OrderType(); // Type of the selected order.

Lot=OrderLots(); // Number of lots

}

else

{

Alert("OrderSelect() returned an error - ",GetLastError()); // If the order could not be selected, then .

return; // Exit

}

}

//------------------------------------------------------------- 4 --

// Trade criteria Situation analysis

M_1=iStochastic(NULL,0,8,3,3,MODE_EMA,0,MODE_MAIN,1);// 1 bar

M_2=iStochastic(NULL,0,8,3,3,MODE_EMA,0,MODE_MAIN,2);// 2 bar

M_3=iStochastic(NULL,0,8,3,3,MODE_EMA,0,MODE_MAIN,3);// 3 bar

//------------------------------------------------------------- 5 --

if(M_2>=H_line) // if Stohastic has crossed overbought line

{

if(M_3 <= M_2 && M_2 > M_1) // Stohastic has crossed the overbought line {...

{

if(S_Flag==true) // If(Sell position opened, then ...

return; // Exit start()

// If Sell position is not opened, then ...

S_Flag=true; // we set a flag indicating that the signal to Sell has appeared

B_Flag=false; // check that the signal to BUY has not appeared

if(ORD_Buy==true) // If a Buy order has been opened,...

{

if(Tip!=0) // Check: order TYPE does not correspond to the open order...

{

Work=false; //The Expert Advisor will not work

Alert("The order TYPE does not correspond to the open order FLAG. Exit start."); // If the match does not exist, the Expert Advisor stops working

return; // Exit from start

}

Ans_Close=Close_Order(Ticket,Lot,Slippage,Tip); // Close the open Buy order

if(Ans_Close==false) // If failed to close, then...

{

Alert("Failed to close the order. The Expert Advisor stops working.\n Critical error number ", Crit_Error);

return; // Exit

}

}

Ans_Open=Open_Order(Symb,Lts,SL,TP,1); // OPEN POINTS

if(Ans_Open==false) // if failed to open Sell

{

Alert("Failed to open order. The Expert Advisor stops working.\n Critical error number ", Crit_Error);

return; // Exit from start

} // If Sell was successfully opened

ORD_Sell=true; // we put a flag that a SHORT position has been opened

ORD_Buy=false; // Flag the LONG position as gone

}

return; // Exit start

}

//------------------------------------------------------------------------ 6 --

if(M_2<=L_line) // If Stohastic has crossed the oversold line

{

if(M_3 >= M_2 && M_2 < M_1) // Bottom peak appears (BUY CALL)

{

if(B_Flag==true) // If Buy position is open

return; // Exit start()

// If no Buy position is opened, then...

B_Flag=true; // Flag positive for Buy position opened

S_Flag=false; // check that there is no SELL signal

if(ORD_Sell==true) // If there is an open Sell order,...

{

if(Tip!=1) // Check: order TYPE does not correspond to the open order...

{

Work=false; //The Expert Advisor will not work

Alert("The order TYPE does not correspond to the open order's FLAG. Exit start."); // If the match does not exist, the Expert Advisor stops working

return; // Exit from start

}

Ans_Close=Close_Order(Ticket,Lot,Slippage,Tip); // Close the open Sell order

if(Ans_Close==false) // If failed to close

{

Alert("Failed to close the order. The Expert Advisor stops working.\n Critical error number ", Crit_Error);

return; // Exit

}

}

Ans_Open=Open_Order(Symb,Lts,SL,TP,0); // OPEN LONG POSITION

if(Ans_Open==false) // if failed to open Buy

{

Alert("Failed to open order. The Expert Advisor stops working.\n Critical error number ", Crit_Error);

return; // Exit from start

} // If Buy order was successfully opened

ORD_Sell=false; // check that there is no short position

ORD_Buy=true; // Flag open LONG position

}

return; // Exit start

}

}

//+------------------------------------------------------------------ 7 --

void Fun_New_Bar() // The detection fie .

{ // ... new bar.

static datetime New_Time=0; // time of the current bar

New_Bar=false; // No new bar

if(New_Time!=Time[0]) // compare the time

{

New_Time=Time[0]; // Now the time is

New_Bar=true; // New bar is caught

}

}

//--------------------------------------------------------------- 8 --

bool Close_Order(int F_Ticket,double F_Lot,int F_Slippage,int F_Tip) // Order closing fie

{

double Close_Price=0; // Close price of the order

while(true)

{

RefreshRates(); // Update data

if(F_Tip==0) // If the order is Buy, ...

Close_Price=Bid; // Close price Bid

Close_Price=Ask; // If the order is Sell, close price Ask

bool Ans_Close=OrderClose(F_Ticket,F_Lot,Close_Price,F_Slippage); // Close Buy or Sell

if (Ans_Close==true) // It worked :)

return(true); // Exit from the close function

Crit_Error=GetLastError(); // Fix error number

if (Fun_Error(Crit_Error)==1) // Error handling

continue; // retry; // try again.

return(false); // Exit from the function

}

}

//--------------------------------------------------------------- 9 --

//Order open

bool Open_Order(string F_Symb,double F_Lts,int F_SL,int F_TP,int F_Tip)

{

double Open_Price; //open price

string Tip_Deal; // Trade direction(Buy or Sell)

double f_sl; // Stop Loss order

double f_tp; // Take Profit

int Ticket; // Ticket of the open order

while(true) // Orders close loop.

{

RefreshRates(); // Update data

if(F_Tip==1) // Open SELL...

{

Open_Price=Bid;

Tip_Deal="OP_SELL";

f_sl=NormalizeDouble(Bid+F_SL*Point,Digits);

f_tp=NormalizeDouble(Bid-F_TP*Point,Digits);

}

//-------------------------------- If you want to open BUY, then...

Open_Price=Ask;

Tip_Deal="OP_BUY";

f_sl=NormalizeDouble(Bid+F_SL*Point,Digits);

f_tp=NormalizeDouble(Bid-F_TP*Point,Digits);

Ticket=OrderSend(F_Symb,Tip_Deal,F_Lts,Open_Price,2,f_sl,f_tp);//open ORDER

if (Ticket > 0) // it worked :)

return(true); //exit from the function

Crit_Error=GetLastError(); // commit error number

if (Fun_Error(Crit_Error)==1) // Error handling

continue; // Retry; // Try again.

return(false); // Exit from the function

}

}

//--------------------------------------------------------------- 10 --

int Fun_Error(int Error) //Function handling errors

{

switch(Error)

{ // Insurmountable errors.

case 4: Alert("Trade server is busy. Try again...");

Sleep(3000); // Simple solution.

return(1); // Exit function.

case 135:Alert("Price changed. Try again...");

RefreshRates(); // Refresh data.

return(1); // Exit from the function.

case 136:Alert("No price. Waiting for a new tick...");

while(RefreshRates()==false) // Till a new tick

Sleep(1); // Delay in the loop

return(1); // Exit from the function

case 137:Alert("Broker is busy. Try again...");

Sleep(3000); // Simple solution.

return(1); // Exit from the function.

case 146:Alert("The trading subsystem is busy. Try again...");

Sleep(500); // Simple decision

return(1); // Exit from the function

// Critical errors

case 2: Alert("General error;)

return(0); // Exit from the function.

case 5: Alert("Older version of the terminal.");

Work=false; // No longer work

return(0); // Exit from the function

case 64: Alert("Account blocked.");

Work=false; // No longer work

return(0); // Exit from the function

case 133:Alert("Trading prohibited.");

return(0); // Exit from the function

case 134:Alert("Not enough money to execute the transaction.");

return(0); // Exit from the function

default: Alert("An error has occurred ",Error); // Other options

return(0); // Exit from the function

}

}

//-------------------------------------------------------------- 11 --



Files:
 
RomanRott: Can you tell me how to find the maximum and minimum values of the current ATP?
   double max=-10000, min=+10000, ATR;
   for(int n=0; n<WindowFirstVisibleBar();n++)
   {
      ATR=iATR(NULL, 0, 14, n);
      if(max<ATR)max=ATR;
      if(min>ATR)min=ATR;
   }
   Alert("min = ", DoubleToStr(min,4), "    max = ", DoubleToString(max,4));
For other indicators similarly
 
Skander: Hi all.Made a simple expert based on Stochstic (on top peak sells, on bottom buy), and the compiler gives an error on a flat spot.
Can anyone tell me what's the reason and what this error means? At first I thought I forgot to put a parenthesis somewhere.
But no, I checked it several times and it seems everything is ok with brackets. I will be very grateful to you for help.
Here are errors the compiler generates: ')' - not all control paths return a value Stohastic-Signals-33.mq4 177 3
')' - not all control paths return a value Stohastic-Signals-33.mq4 210 3
//--------------------------------------------------------------- 8 --
bool Close_Order(int F_Ticket,double F_Lot,int F_Slippage,int F_Tip) // Order closing fie
{
double Close_Price=0; // Close price of the order
while(true)
{
RefreshRates();// Refresh data
if(F_Tip==0)// If(Buy order, ...
Close_Price=Bid; // Close price Bid
Close_Price=Ask;// If Sell order, close price Ask
bool Ans_Close=OrderClose(F_Ticket,F_Lot,Close_Price,F_Slippage); // Close Buy or Sell
if (Ans_Close==true)// It worked :)
return(true);// Exit from the close function
Crit_Error=GetLastError();// commit error number
if (Fun_Error(Crit_Error)==1) // Error handling
continue;// retry
return(false);// Exit the function
}
}

Press the Compile button in MetaEditor and read the error message - there is a line number and position number

//--------------------------------------------------------------- 8 --
  bool Close_Order(int F_Ticket,double F_Lot,int F_Slippage,int F_Tip)    // Ф-ия закрытия ордера
  {
   double Close_Price=0;                       // Цена закрытия ордера 
   while(true)
     {
        ....................................
            continue;                           // Повторная попытка
         return(false);                                // Выход из функции
     }
     return false;   // Компилятор хочет return в конце функции
  }

Insert programcode with SRC button - local readers like it better this way!!! and your long rambling is BRRRRR

The Code button is for inserting source code into the message text. When clicked, an empty window will appear where you need to paste the code and then click on the Insert button.

 
STARIJ:

Press the Compile button in MetaEditor and read the error message - there is a line number and position number

Insert programcode with SRC button - local readers like it better that way!!! and your long rambling is BRRRRR

The button is for inserting source code into the text of a post. When clicked, an empty window appears where you need to paste the code and then click the Insert button.


Thank you.