Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1504

 
Fokus24 CSymbolInfo class to price step?
DoubleToString(ask,_Digits)
 
Fokus24 CSymbolInfo class to price step?

It is enough to use NormaliseDouble() to pass to the methods of opening positions and orders. The second parameter can be obtained using

C_info.Digits()
Документация по MQL5: Преобразование данных / NormalizeDouble
Документация по MQL5: Преобразование данных / NormalizeDouble
  • www.mql5.com
NormalizeDouble - Преобразование данных - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
hi guys i just starting using mt5.the problem is that i cant see my costume indicator on the chart .the code has no errors i put the chart on foreground i checked the indicators list in chart and i can see my indicator, i refresh i closed and open the mt5 , i deleted and redownloaded but still any costume indicator that i make doesnt show up in the chart .any thought 
 
Dear All, I need your help please. I am trying to code an expert advisor and I have been having issues with my code which i cant seem to resolve. I want to delete all buy limit orders when there are no buy positions and also do same for sell limit orders when there are no sell positions. Below is the code i've written and I called the deleteAllBuyOrders() and deleteAllSellOrders() functions in my onTick() section but it just wont work. The code compiles fine however, while testing it, when all buy positions are closed, the buy limit pending orders don't get deleted as i want it to. Please help me out
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void deleteAllBuyOrders()
{
   int totalPositions = PositionsTotal();
   bool hasOpenBuyPosition = false;
   
   // Check if there are any open buy positions
   for (int i = 0; i < totalPositions; i++)
   {
        if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
        {
            hasOpenBuyPosition = true;
            break;
        }
   }
   
   // If there are no open buy positions, delete all pending buy limit orders
   if (!hasOpenBuyPosition)
   {
       int totalOrders = OrdersTotal();
       for(int i = OrdersTotal()-1; i >= 0; i--)
            {
               ulong ticket = OrderGetTicket(i);
               
               if(OrderGetInteger(ORDER_MAGIC) == InpMagic && OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_BUY_LIMIT)
               {
                  trade.OrderDelete(ticket);
               }
            }
   }

}
void deleteAllSellOrders()
{
   int totalPositions = PositionsTotal();
   bool hasOpenSellPosition = false;
   
   // Check if there are any open sell positions
   for (int i = 0; i < totalPositions; i++)
   {
        if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
        {
            hasOpenSellPosition = true;
            break;
        }
   }
   
   // If there are no open sell positions, delete all pending buy limit orders
   if (!hasOpenSellPosition)
   {
       int totalOrders = OrdersTotal();
       for(int i = OrdersTotal()-1; i >= 0; i--)
            {
               ulong ticket = OrderGetTicket(i);
               
               if(OrderGetInteger(ORDER_MAGIC) == InpMagic && OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_SELL_LIMIT)
               {
                  trade.OrderDelete(ticket);
               }
            }
   }

}
 
NoobDaytrader checked the list of indicators on the chart and I can see my indicator , I updated I closed and opened mt5 , I uninstalled and reloaded but still any suit indicator I make is not showing on the chart .Any thoughts

See the articles here - it's all explained. Search for custom indicator type and see the articles.

Features of writing custom indicators.
So how to see in the search request here.
There are several detailed articles there.
 
Mo Isiak #:
Dear all, I need your help please. I am trying to create an EA and I have some problems with the code that I can't solve in any way. I want to delete all buy limit orders when there are no buy positions, and do the same for sell limit orders when there are no sell positions. Below is the code I wrote, and I called deleteAllBuyOrders() and deleteAllSellOrders() in my onTick() section, but it just doesn't work. The code compiles fine, but when testing, when all buy positions are closed, the pending orders with a buy limit are not deleted as I want. Please help me ...

Hello. Please insert the code into the message using a special input window (the picture shows the button to call it):

Now about the code. You have done correctly that you have looped through all open positions, but for some reason you have not selected any position on the ticket to work with it further:

PositionGetTicket

Функция возвращает тикет позиции по индексу в списке открытых позиций и автоматически выбирает эту позицию для дальнейшей работы с ней 
при помощи функций PositionGetDouble, PositionGetInteger, PositionGetString.

ulong  PositionGetTicket( 
   int  index      // номер в списке позиций 
   ); 

Regards, Vladimir.

 

I want to make the code from mql5 work on mql4.

Example code of zig zag indicator with Mql5, how to implement it correctly without CopyBuffer, something does not work.

//--- ZigZag knee search
   double high[],low[];
   MqlRates rates[];
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(rates,true);
   int start_pos=0,count=300;
   if(!iGetArray(handle_iCustom,0,start_pos,count,high) ||
      !iGetArray(handle_iCustom,1,start_pos,count,low) ||
      CopyRates(_Symbol,Period(),start_pos,count,rates)!=count)
     {
      return(false);
     }
     
//Last Hi
   for(int i=0; i<1000; i++)
     {
      high[i]=iCustom(NULL,0,"ZigZag",ExDepth,ExDeviation,ExBackstep,0,i);
     }     
//Last Low
   for(int i=0; i<1000; i++)
     {
      low[i]=iCustom(NULL,0,"ZigZag",ExDepth,ExDeviation,ExBackstep,1 ,i);
     }

     
   
     
     
   double left=0.0,middle=0.0,right=0.0;
   datetime left_date=0.0,middle_date=0.0,right_date=0.0;
   for(int i=0; i<count; i++)
     {
     
      if(high[i]!=0.0 || low[i]!=0.0)
        {
         double value=(high[i]!=0.0)?high[i]:low[i];
         if(value==0.0)
            return(false);
         if(right==0.0)
           {
            right=value;
            right_date=rates[i].time;
            continue;
           }
         if(middle==0.0)
           {
            middle=value;
            middle_date=rates[i].time;
            continue;
           }
         if(left==0.0)
           {
            left=value;
            left_date=rates[i].time;
            break;
           }
        }
     }
 
Konstantin Seredkin CopyBuffer, something does not work.

It will not work inMQL5 withoutCopyBuffer. Only with it. The usual MQL4 style of working with indicator data does not work in MQL5.

 
Yuriy Bykov CopyBuffer inMQL5. Only with it. The usual MQL4 style of working with indicator data does not work in MQL5.

It's clear, everything works on mql5, I wrote how to make this code work on mql4, I highlighted in yellow what I wrote, but in the places where it is highlighted in red, the error is outputting an error of exceeding the array limits

 
MrBrooklin #:

Hello. Please insert the code into the message using a special input window (the picture shows the button to call it):

Now about the code. You have done correctly that you have looped through all open positions, but for some reason you have not selected any position on the ticket to work with it further:

Regards, Vladimir.

Hello. Thank you for your response. Below is the inserted code as requeted.

void deleteAllBuyOrders()
{
   int totalPositions = PositionsTotal();
   bool hasOpenBuyPosition = false;
   
   // Check if there are any open buy positions
   for (int i = 0; i < totalPositions; i++)
   {
        if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
        {
            hasOpenBuyPosition = true;
            break;
        }
   }
   
   // If there are no open buy positions, delete all pending buy limit orders
   if (!hasOpenBuyPosition)
   {
       int totalOrders = OrdersTotal();
       for(int i = OrdersTotal()-1; i >= 0; i--)
            {
               ulong ticket = OrderGetTicket(i);
               
               if(OrderGetInteger(ORDER_MAGIC) == InpMagic && OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_BUY_LIMIT)
               {
                  trade.OrderDelete(ticket);
               }
            }
   }

}
void deleteAllSellOrders()
{
   int totalPositions = PositionsTotal();
   bool hasOpenSellPosition = false;
   
   // Check if there are any open sell positions
   for (int i = 0; i < totalPositions; i++)
   {
        if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
        {
            hasOpenSellPosition = true;
            break;
        }
   }
   
   // If there are no open sell positions, delete all pending buy limit orders
   if (!hasOpenSellPosition)
   {
       int totalOrders = OrdersTotal();
       for(int i = OrdersTotal()-1; i >= 0; i--)
            {
               ulong ticket = OrderGetTicket(i);
               
               if(OrderGetInteger(ORDER_MAGIC) == InpMagic && OrderGetInteger(ORDER_TYPE) == ORDER_TYPE_SELL_LIMIT)
               {
                  trade.OrderDelete(ticket);
               }
            }
   }

}
Reason: