Questions from Beginners MQL4 MT4 MetaTrader 4 - page 27

 
Movlat Baghiyev:
The close condition uses a reverse signal, but it does not work yOur trades are only closed at stop or takei. What is your reason?

Wrong.
Your condition should be at the start and the close function behind the start.

int i;
// 
void Start(){

if ((FMA1<GrossMA1 && FMA2>GrossMA2 && Bid<FMA1-Distanse*GetPoint()) // тут так надо бы Bid<NormalizeDouble(FMA1-Distanse*GetPoint(),Digits)
   || (FRMA1>GrossMA1 && FRMA2<GrossMA2  &&  Ask>FRMA1+Distanse*GetPoint())){
for(i=OrdersTotal()-1;i>=0;i--) if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==Symbol() && OrderMagicNumber()==magic) {
if (OrderType()==OP_BUY || OrderType()==OP_SELL)  CloseOpBuySell(); // тут закроются все ордера и бай и селл
    }
  }

}// end start

void CloseOpBuySell()

for(i=0;i<OrdersTotal();i++) 
  { 
  if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) 
   { 
    if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic ) //свой магик
    { 
      if(OrderType()==OP_BUY
        { 
         if(OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),3,LawnGreen);  {continue;}
        } 
      if(OrderType()==OP_SELL
        { 
         if(OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),3,LawnGreen);  {continue;}
        } 
      } 
    } 
  } 
  return;
  }

If you have to close on separate conditions, and not all at once, then the close function should be different.
 
Natashe4ka:

Wrong.
You should have the condition at the start and the closing function at the start.

If you need to close by individual conditions and not all at once, then the closing function should be different.

Right, but I've already done it and sent it to him, so he won't say anything.

int start()
{
    //закрытие по МА-шкам
   if (FMA1<GrossMA1 && FMA2>GrossMA2 && Bid<FMA1-Distanse*GetPoint()) CloseOpBuySell("BUY");
   if (FRMA1>GrossMA1 && FRMA2<GrossMA2  &&  Ask>FRMA1+Distanse*GetPoint()) CloseOpBuySell("SELL");
  return(0);
}
//----
//-----------------------------------+

void CloseOpBuySell(string TypeClose)
   {
      for(int i=0;i<OrdersTotal();i++)
         {
            if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
               {
                   if(OrderSymbol()==Symbol() && OrderMagicNumber()==mn )
                      {
                        if(TypeClose=="BUY")
                          {
                              if(OrderType()==OP_BUY)OrderClose(OrderTicket(),OrderLots(),Bid,3,LawnGreen);
                           }
                        if(TypeClose=="SELL")
                          {
                              if(OrderType()==OP_SELL)OrderClose(OrderTicket(),OrderLots(),Ask,3,LawnGreen);
                          }
                     }
               }
         }
   }
 
Renat Akhtyamov,Natashe4ka thank you very much.

 
lot=NormalizeDouble(AccountBalance()*MaximumRisk/(MarketInfo(Symbol(),MODE_MARGINREQUIRED)*100),1);
This is how lot is calculated .MaximumRisk==100 . I need lot to be calculated automatically to the maximum .I wrote MaximumRisk==100 to calculate the maximum possible lot at trade opening. How many times is it correct?
 
Movlat Baghiyev:
lot=NormalizeDouble(AccountBalance()*MaximumRisk/(MarketInfo(Symbol(),MODE_MARGINREQUIRED)*100),1);
Here is a variant of lot calculation .MaximumRisk==100 . I need it to be calculated automatically for each lot .I have prescribed MaximumRisk==100 to calculate the maximum possible lot at trade opening.

It is better to count based on available funds rather than the balance. Otherwise, you risk getting a lot more than you can afford at the time of opening a trade.

You also need to work out the dependency of the lot step, and then check if the lot is within the maximum and minimum lots allowed in the account.

int MaximumRisk=100;
double lots,lotstep,free,margin, lotmin, lotmax;

lotmax=MarketInfo(Symbol(), MODE_MAXLOT);
lotmin=MarketInfo(Symbol(), MODE_MINLOT);
lotstep = MarketInfo(Symbol(), MODE_LOTSTEP);
reqmargin = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
free=AccountFreeMargin();

lots = NormalizeDouble(lotstep*MathRound((free*MaximumRisk*0.01/reqmargin)/lotstep),2);

if (lots < lotmin) lots = lotmin;
if (lots > lotmax) lots = lotmax;
 
Vitalie Postolache:


Got it. Thanks. Let's see what happens.
 
Vitalie Postolache:

It is better to count based on available funds rather than the balance. Otherwise, you risk getting a lot more than you can afford at the time of opening a trade.

You also need to work out the dependency of the lot step, and then check if the lot is within the maximum and minimum lots allowed in the account.

int MaximumRisk=100;
double lots,lotstep,free,margin, lotmin, lotmax;

lotmax=MarketInfo(Symbol(), MODE_MAXLOT);
lotmin=MarketInfo(Symbol(), MODE_MINLOT);
lotstep = MarketInfo(Symbol(), MODE_LOTSTEP);
reqmargin = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
free=AccountFreeMargin();

lots = NormalizeDouble(lotstep*MathRound((free*MaximumRisk*0.01/reqmargin)/lotstep),2);

if (lots < lotmin) lots = lotmin;
if (lots > lotmax) lots = lotmax;
This option doesn't work as it should... Opening one deal with the maximum possible lot, and after closing the second does not open the second writes not enough money...
 

Postponed:

Gevorg Hakobyan, 2016.12.08 15:26

Hello. How can I get a list of all existing currency pairs in Meta Trader 4? And how can I keep abreast of any changes in the list?
 
Vladimir Karputov:

Postponed:

Gevorg Hakobyan, 2016.12.08 15:26

Hello. How can I get the list of all currency pairs existing in Meta Trader 4? And how to be aware of any changes in the list?

SymbolsTotal

Returns the number of available (selected in MarketWatch or all) symbols.

intSymbolsTotal(
bool selected// true - only symbols in MarketWatch
);

Parameters

selected

[in] Request mode. Can take values true or false.

Returned value

If selected is true, the number of characters selected in MarketWatch is returned. If false, it returns the total number of all symbols.

 
Vladimir Karputov:

Postponed:

Gevorg Hakobyan, 2016.12.08 15:26

Hello. How can I get a list of all existing currency pairs in Meta Trader 4? And how can I keep abreast of any changes in the list?
And from what is transferred, is it impossible to write code that will work cross-platform, there is no difference in the task from getting the symbols in the two platforms.