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

 
Can you please tell me how to withdraw the money?
 
Request sent yesterday, more than 24 hours have passed and no word
 
ivlyeva.tatyana6:
I sent a request yesterday, more than a day has passed and silence.

1. Go to the nearest ATM, insert the card, enter the pin code...

2. Go to the nearest bank, make eye contact, then follow the situation...

3. Go to the market. 3) Go to the market. Go to the bank. Withdraw funds (you can withdraw them all, not just your own...) ...

4. If you have to withdraw money from MMM, then even the tank will not help you!

And seriously, you can't!

 
//+------------------------------------------------------------------+
//|                                                  MACD Sample.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
input double TakeProfit    =3160;
input double Lots          =0.5;
input double TrailingStop  =1040;
input int OpenLevel =22;
input int CloseLevel=77;
input int    Period =85;
input int    Period1 =57;
int LastBars=0;
extern int Magic = 110725;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick(void)
  {
   
 
   int    cnt,ticket,total;
//---
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external 
// variables (Lots, StopLoss, TakeProfit, 
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
//---
//--- Trade only if new bar has arrived
   if(LastBars!=Bars) LastBars=Bars;
   else return(0);
   if(Bars<100)
     {
      Print("bars less than 100");
      return;
     }
   if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return;
     }
//--- to simplify the coding and speed up access data are put into internal variables
   
   total=OrdersTotal();
   if(total<1)
     {
      //--- no opened orders identified
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ",AccountFreeMargin());
         return;
        }
      //--- check for long position (BUY) possibility
     if(iRSI(NULL,0,OpenLevel,PRICE_LOW,Period)>iRSI(NULL,0,CloseLevel,PRICE_HIGH,Period1)) 
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-TakeProfit*Point,Bid+TakeProfit*Point,"USDCADH4",Magic,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
               Print("BUY order opened : ",OrderOpenPrice());
           }
         else
            Print("Error opening BUY order : ",GetLastError());
         return;
        }
      //--- check for short position (SELL) possibility
      if(iRSI(NULL,0,OpenLevel,PRICE_LOW,Period1)<iRSI(NULL,0,CloseLevel,PRICE_HIGH,Period)) 
        {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+TakeProfit*Point,Ask-TakeProfit*Point,"USDCADH4",Magic,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
               Print("SELL order opened : ",OrderOpenPrice());
           }
         else
            Print("Error opening SELL order : ",GetLastError());
        }
      //--- exit from the "no opened orders" block
      return;
     }
//--- it is important to enter the market correctly, but it is more important to exit it correctly...   
   for(cnt=0;cnt<total;cnt++)
     {
      if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         //--- long position is opened
         if(OrderType()==OP_BUY)
           {
            //--- should it be closed?
              if(iRSI(NULL,0,OpenLevel,PRICE_LOW,Period1)<iRSI(NULL,0,CloseLevel,PRICE_HIGH,Period)) 
              {
               //--- close order and exit
               if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet))
                  Print("OrderClose error ",GetLastError());
               return;
              }
            //--- check for trailing stop
            if(TrailingStop>0)
              {
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     //--- modify order and exit
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green))
                        Print("OrderModify error ",GetLastError());
                     return;
                    }
                 }
              }
           }
         else // go to short position
           {
            //--- should it be closed?
           if(iRSI(NULL,0,OpenLevel,PRICE_LOW,Period)>iRSI(NULL,0,CloseLevel,PRICE_HIGH,Period1)) 
              {
               //--- close order and exit
               if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet))
                  Print("OrderClose error ",GetLastError());
               return;
              }
            //--- check for trailing stop
            if(TrailingStop>0)
              {
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     //--- modify order and exit
                     if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red))
                        Print("OrderModify error ",GetLastError());
                     return;
                    }
                 }
              }
           }
        }
     }
//---
  }
//+------------------------------------------------------------------+

Hello. Please help me to understand... The Expert Advisor is closing other people's trades or not opening its own if there are other people's trades.

 
darirunu1:

Hello. Please help me to understand... The Expert Advisor is closing other people's trades or not opening its own if there are other people's trades.

Where is your magician for finding orders?
 

If it is written above, the Expert Advisor closes trades opened manually,

If I put it this way

 if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
         continue;
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol()&& OrderMagicNumber()==Magic)  // check for symbol

If there are any trades opened manually, then the Expert Advisor will not close other trades, but it will not open its own if there are any trades opened manually.

 
darirunu1:

If it is written above, the Expert Advisor closes trades opened manually,

If I put it this way

If there are any trades opened manually, then the Expert Advisor will not close other trades, but it will not open its own if there are any trades opened manually.

also need selection by wizardry when opening
 
MakarFX:
I also need selection on the magic number at opening
 ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+TakeProfit*Point,Ask-TakeProfit*Point,"USDCADH4",Magic,0,Red);

What is this? The opening is indicated. The thing is that when you use several Expert Advisors, there is no problem. The problem occurs only when there is a manual opening of a position in the account.

As soon as there are opened deals on the account manually, the Expert Advisor stops working.

As soon as I remove this in the code, total=OrdersTotal();

if(total<1)

EAs go straight on, but open lots of trades

 
darirunu1:

What is this? The opening is indicated. The thing is that when you use several Expert Advisors, there is no problem. The problem occurs only when there is a manual opening of a position in the account.

As soon as there are opened deals on the account manually, the Expert Advisor stops working.

As soon as I remove this in the code, total=OrdersTotal();

if(total<1)

EAs go straight on, but open lots of trades.

This is what I am talking about - OrdersTotal() is for all orders and you need an EA order

   if(CountOrders("", -1,  Magic)<1)
     {
     открытие ордеров
     }
//+----------------------------------------------------------------------------+
//| Подсчет ордеров                                                            |
//+----------------------------------------------------------------------------+
//| -1 - Все типы ордеров                                                      |
//|  0 - ордера типа BUY                                                       |
//|  1 - ордера типа SELL                                                      |
//|  2 - ордера типа BUYLIMIT                                                  |
//|  3 - ордера типа SELLLIMIT                                                 |
//|  4 - ордера типа BUYSTOP                                                   |
//|  5 - ордера типа SELLSTOP                                                  |
//+----------------------------------------------------------------------------+
int CountOrders(string symb="", int or_ty=-1, int magiс=-1) 
  {
   int cnt=0;
   if(symb=="0") symb=_Symbol;
   for(int pos=OrdersTotal()-1;pos>=0;pos--)
     {
      if(OrderSelect(pos,SELECT_BY_POS)==true)
        {
         if((OrderSymbol()==symb || symb=="")&&(or_ty<0 || or_ty==OrderType()))
           {
            if(magiс<0 || OrderMagicNumber()==magiс) cnt++;
           }
        }
     }
   return(cnt);
  }
 
MakarFX:

That's what I'm talking about, OrdersTotal() is all orders and you want EA orders

if(CountOrders("", -1,  Magic)<1)
     {

This is instead of

total=OrdersTotal();

if(total<1) or do we leave this one as well?

Reason: