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

 
Yan Barmin:
Confused. How do I get the real profit (loss) on an open order (not a pending order) on MT4, including all commissions, swaps, etc.? (OrderProfit() + OrderSwap() + OrderCommission() or justOrderProfit() or something else? I would like to earn something after the order is closed.
 OrderProfit() + OrderSwap() + OrderCommission()
 

How to place these volume figures on the candles in the basement window, i.e. at the bottom or make all the figures to go all as a line one horizontally in the centre if the basement doesn't work. Would be very grateful for help.

#property indicator_chart_window

#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 4
#property indicator_width5 4

#property indicator_color1 SkyBlue
#property indicator_color2 Maroon
#property indicator_color3 Yellow
#property indicator_color4 Blue
#property indicator_color5 DeepPink

extern int BarsToCount = 990;

extern string pus1 = "";
extern string p_s = "Points settings";
extern bool use_points = true;
extern int distance_point = 5;
extern color color_point_u = Lime;
extern color color_point_d = DeepPink;
extern color color_point_s = Yellow;
extern inttern size_point = 14;

extern string pus2 = "";
extern string s_w = "Way";
extern bool use_show_same_way = true;
extern bool use_show_daily_way = true;

extern string pus3 = "";
extern string al = "Alerts";
extern bool use_alerts = false;
extern string up_alert = "Up";
extern string down_alert = "Down";


double up[];
double down[];
double mid[];
double up2[];
double down2[];
double none[];

static int prevtime = 0;

//
int init()
{

IndicatorShortName("A");
return(0);
}

//
int deinit()
{
string name_de;
for(int c=BarsToCount;c>=0;c--)
{
name_de="Vol_"+DoubleToStr(c,0);
if(ObjectFind(name_de)!=-1) ObjectDelete(name_de);
}
return(0);
}
//////////////////////////////////////////
int start()
{
////////////
up[0]=EMPTY_VALUE;
down[0]=EMPTY_VALUE;
mid[0]=EMPTY_VALUE;
if(Close[0]>Open[0]) up[0]=Volume[0];
if(Close[0]<Open[0]) down[0]=Volume[0];
if(Close[0]==Open[0]) mid[0]=Volume[0];

////////////////
if(use_points)
Ob_cre(0);

if(!use_points)
Ob_del(0);
////////////
if(Time[0] == prevtime) return(0);
prevtime = Time[0];
///////////////////////////
for(int c=BarsToCount;c>=1;c--)
{
////////////
if(use_points)
Ob_cre(c);

if(!use_points)
Ob_del(c);
////////////
up[c]=EMPTY_VALUE;
down[c]=EMPTY_VALUE;
mid[c]=EMPTY_VALUE;
up2[c]=EMPTY_VALUE;
down2[c]=EMPTY_VALUE;

/////////////////
if(Close[c]>Open[c]) up[c]=Volume[c];
if(Close[c]<Open[c]) down[c]=Volume[c];
if(Close[c]==Open[c]) mid[c]=Volume[c];
none[c]=Volume[c]+Volume[c]/6;


//////////////
if(use_show_same_way)
{

if(Close[c]>Open[c] && Close[c+1]>Open[c+1])
{
up2[c]=Volume[c]; up2[c+1]=Volume[c+1];
up[c]=EMPTY_VALUE; up[c+1]=EMPTY_VALUE;
}

if(Close[c]<Open[c] && Close[c+1]<Open[c+1])
{
down2[c]=Volume[c]; down2[c+1]=Volume[c+1];
down[c]=EMPTY_VALUE; down[c+1]=EMPTY_VALUE;
}

}


if(use_alerts)
{
if(up2[1]!=EMPTY_VALUE && up2[4]==EMPTY_VALUE) Alert(up_alert);
if(down2[1]!=EMPTY_VALUE && down2[4]==EMPTY_VALUE) Alert(down_alert);
}
}
return(0);
}
//func
//+------------------------------------------------------------------+///////////////////////////////
void Ob_cre(int num_of_bar)
{
string name="Vol_"+DoubleToStr(num_of_bar,0);

color col_po;
if(Close[num_of_bar]>Open[num_of_bar]) col_po=color_point_u;
if(Close[num_of_bar]<Open[num_of_bar]) col_po=color_point_d;
if(Close[num_of_bar]==Open[num_of_bar]) col_po=color_point_s;

if(ObjectFind(name)==-1)
{
ObjectCreate(name,OBJ_TEXT,0,0)
}
ObjectSet(name,OBJPROP_TIME1,Time[num_of_bar]);
ObjectSet(name,OBJPROP_PRICE1,High[num_of_bar]+distance_point*Point);
ObjectSet(name,OBJPROP_ANGLE,90);
ObjectSetText(name,DoubleToStr(Volume[num_of_bar],0),size_point, "Arrial",col_po);
ObjectSet(name,OBJPROP_ANCHOR,ANCHOR_CENTER);
}

//
void Ob_del(int num_of_bar)
{
string name="Vol_"+DoubleToStr(num_of_bar,0);
}

Files:
 

I create a synthetic symbol based on EURUSD, name ZIGZAG (to avoid name conflict)

I import the minute bars, everything is successfully imported, but on re-request the number of bars is 0. There is a created file "2019.hcc" of 39 mb in the "history/symbol" folder, in the "ticks" folder everything is empty. Changed the terminal (current version of 30 May 2019), computer - everywhere does not work.

What could be the error?

Files:
simvol.zip  809 kb
 
SEM:

I create a synthetic symbol based on EURUSD, name ZIGZAG (to avoid name conflict)

I import the minute bars, everything is successfully imported, but on re-request the number of bars is 0. There is a created file "2019.hcc" of 39 mb in the "history/symbol" folder, in the "ticks" folder everything is empty. Changed the terminal (current version from May 30, 2019), computer - everywhere does not work.

What could be the error?

In the matching names
 
Hi all, how about improving the MT4 article Balance on the demo version and make it changeable? What would be the possibility of changing the demo balance at its discretion. Either top up . Or withdraw the demo funds and make trading on the demo as close to the real?
 
oleqas1:
Hi, how would you like to improve the MT4 article Balance on Demo version and make it editable? What would be the possibility of demo balance on your own to change. Either top up . Or withdraw the demo funds and make trading on the demo as close to real?

MetaTrader4 will no longer be updated - the development of this platform was halted long ago. At most, significant bugs are being fixed.

Go to MetaTrader5 and use TesterWithdrawal()

Документация по MQL5: Общие функции / TesterWithdrawal
Документация по MQL5: Общие функции / TesterWithdrawal
  • www.mql5.com
Общие функции / TesterWithdrawal - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Hello, How do I calculate the volatility of the European sessions over 3 days?
 

Hello, if there is e.g. a buystop and buylimit.

A buystop is opened, modify buylimit and set a new buystop.

Opens buylimit need to modify buystop and set a new buylimit.

I tried to do this, it opens, but error messages OrderModify error 1, OrderModify error 130. How to fix it I can not figure out. Please help me.


void OnTick()
  {
      price_buystop = NormalizeDouble(Ask+StopLoss*Point,Digits);
      price_buyLimit = NormalizeDouble(price_buystop-StopLoss*2*Point,Digits);
      price_buy = PriceOpenLastPos();
      
      //для байстоп
        if (BuyStopCount()==0)//если нет байстопа
       { 
       TP= NormalizeDouble(price_buystop + TakeProfit*Point,Digits);
       SL= NormalizeDouble(price_buystop - StopLoss*Point,Digits);  
       if(CountBuy()==0)// и нет открытых бай 
       {    
       int ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,price_buystop,Slippage,SL,TP,"buystop",Magic,0,Blue);       
       if (ticket <0) Print ("Не удалось открыть buystop ");
       }
         if (CountBuy()>=1) // если нет байстоп но есть открытая
         {  
        price_buystop = NormalizeDouble(price_buy + StopLoss*Point,Digits);
        int ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,price_buystop,Slippage,SL,TP,"buystop",Magic,0,Blue);       
        if (ticket <0) Print ("Не удалось открыть buystop ");            
         } 
      } else {   //если есть байстоп модифицируем
      if (CountBuy()>=1)//и есть открытые и байстоп
         {        
         price_buystop = NormalizeDouble(price_buy+StopLoss*Point,Digits);
         TP= NormalizeDouble(price_buystop + TakeProfit*Point,Digits);
         SL= NormalizeDouble(price_buystop - StopLoss*Point,Digits);        
         bool res = OrderModify(OrderTicket(),price_buystop,SL,TP,0,Blue);     
         }   
      }
      
   //для байлимит
        if (BuyLimitCount()==0) // если нет байлимит
       {   
       TP= NormalizeDouble(price_buyLimit + TakeProfit*Point,Digits);
       SL= NormalizeDouble(price_buyLimit - StopLoss*Point,Digits); 
        if(CountBuy()==0)// и нет открытых открываем
        {
         int ticket=OrderSend(Symbol(),OP_BUYLIMIT,Lots,price_buyLimit,Slippage,SL,TP,"BuyLimit",Magic,0,Blue);       
         if (ticket <0) Print ("Не удалось открыть BuyLimit ");   
        }
        if (CountBuy()>=1)// если открытая есть
         {         
        price_buyLimit = NormalizeDouble(price_buy - StopLoss*Point,Digits);       
        int ticket=OrderSend(Symbol(),OP_BUYLIMIT,Lots,price_buyLimit,Slippage,SL,TP,"BuyLimit",Magic,0,Blue);         
        if (ticket <0) Print ("Не удалось открыть BuyLimit ");            
         }           
      }  else { // если есть байлимит и есть открытая
       if (CountBuy()>=1)
         {
         price_buyLimit = NormalizeDouble(price_buy-StopLoss*Point,Digits);         
         TP= NormalizeDouble(price_buyLimit + TakeProfit*Point,Digits);
         SL= NormalizeDouble(price_buyLimit - StopLoss*Point,Digits);        
         bool res = OrderModify(OrderTicket(),price_buyLimit,SL,TP,0,Blue);    
         }   
      }
   
  }
//+------------------------------------------------------------------+
// проверяем есть ли байстоп ордера с конца
  int BuyStopCount()
  {
  int count = 0;
  for (int i=OrdersTotal()-1;i>=0;i--)
  {
    if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES) == true && 
        OrderMagicNumber()== Magic && OrderType() == OP_BUYSTOP )                        
        {
        count ++;
        }
    }
    return(count); 
  }
  
  // проверяем есть ли ,байлимит ордера с конца
  int BuyLimitCount()
  {
  int count = 0;
  for (int i=OrdersTotal()-1;i>=0;i--)
  {
    if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES) == true && OrderMagicNumber()== Magic &&                        
        OrderType() == OP_BUYLIMIT )                       
        {
        count ++;
        }
    }
    return(count);      
  }
  
   //проверяем открытые ордера покупку
  int CountBuy()
  {
  int count = 0;
  for (int trade = OrdersTotal()-1; trade>=0; trade --)
  {
    if (OrderSelect (trade, SELECT_BY_POS, MODE_TRADES) ==true)
    {
      if (OrderSymbol()==Symbol() && OrderMagicNumber()== Magic && OrderType()== OP_BUY)
        count++;
    }
   }return(count);
  }
  
  
  // возвращает цену открытия последней открытой позиции
  
  double PriceOpenLastPos()
{
int k=OrdersTotal();
double r =0;
int i;

for (i=0; i<k; i++)
  {
  if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
   {
    if (OrderSymbol()== Symbol() && OrderMagicNumber()== Magic && OrderType()== OP_BUY)
     r=OrderOpenPrice();
   }
}return (r);
}


 

What are these errors associated with when testing an EA in the strategy tester in MT4?


 
Alexandr Sokolov:

What are these errors associated with when testing an EA in the strategy tester in MT4?


Load history. F2.
Reason: