Questions from Beginners MQL4 MT4 MetaTrader 4 - page 235

 
Tenimagalon:
Is this before opening?
if(OrdersTotal< 1)
(
)

Checked it works

//+------------------------------------------------------------------+
//|                                                  OrdersTotal.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   double lot =0.01;
   int Ticket;
//--- buy conditions
   if(OrdersTotal()<1)
     {
      Ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,3,0,0,"",0,0,Blue);
      return;
     }

  }
//+------------------------------------------------------------------+
 
SanAlex:

Checked it works

Thanks :)🍺
 

I would like to clarify one more thing. How to close orders on profit. Let's say I open 4 orders. Two Buy on Euric and one Buy on Chif.And also one Sell/I set in the code Profit=10;

I tried to play with this code, but I failed to understand how I could close one buy or sell order when total profit is reached.

 if(Tip==0 && AccountProfit()>=OrderProfit()*Profit + OrderSwap()>0)
              {
              fc=OrderClose(OrderTicket(),lot,Bid, 2);
              } 
              if (Tip==1 && AccountProfit()>=OrderProfit()*Profit + OrderSwap()>0)
              {
               fc=OrderClose(OrderTicket(),lot,Ask,2);
              }       
 
TP SL objects appear on the chart after closing trades. How can I prevent them from appearing?
 
Aliaksandr Yemialyanau:
TP SL objects appear on the chart after closing trades. How can I prevent them from appearing?
 
Please help me how to get started. My broker won't answer and I can't get in touch with him.
 
Good afternoon everyone . What a question. I copy two signals on MT4 accounts. But when the computer is off, only one account works. When I switch the computer on and switch accounts to MT4, then the second account starts working too. With VPS all is normal. I have my own virtual server. Please advise what the problem is. I need to leave the computer on or put two MT4 terminals, but I have no idea how to do this. I understand that the account that was included in MT4 works. I wanted to add a couple of accounts, but now I do not know how to do it ....
 
Равшана Рахмонов:
Please help me how to start. My broker does not respond, I cannot contact him.

Check the username, password and server name. If you copy and paste it in, there may be an extra space.

 
Tenimagalon:

I would like to clarify one more thing. How to close orders on profit. Let's say I open 4 orders. Two Buy on Euric and one Buy on Chif.And also one Sell/I set in the code Profit=10;

I tried to play with this code, but I failed to understand how I could close one buy or sell order when total profit is reached.

if(AccountProfit()>Profit) Close_Buy_Sell();

//+------------------------------------------------------------------+
void Close_Buy_Sell()
  {
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
         break;
        {
         if(OrderType() == OP_BUY)
           {
            int a=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),3,Red);
           }
         if(OrderType() == OP_SELL)
           {
            int a=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),3,Red);
           }
        }
     }
  }
//+------------------------------------------------------------------+
Close all at total profit
Profit
 

Hello all! Just started to learn how to write a simple trading robot from the examples of YouTube videos. I want to write a script to open the firstbuy order, and it must open if I have no other open orders, the script wrote this, but the order does not open, please advise where the error is!

<

void OnTick()

{

if (OP_SELL==0 && OP_BUY==0)

int ticket=OrderSend(Symbol(),OP_BUY,Lot1,Ask,Slippage,StopLoss,TakeProfit, "My order",MagicNumber,0,clrGreen);

>

Reason: