Questions from Beginners MQL4 MT4 MetaTrader 4 - page 153

 

i have a code with classes with info panel!!!
BUT i have a problem!
i have a label on it and i can react it through remote settings.... so when you change the settings 2-3 times, the panel itself moves in different directions!!! and when you change the timeframe 2-3 times!!! how can i get rid of this???


a little more info:
Found that if in Dialog.mqh file in function CAppDialog::Destroy(const int reason) to comment out lines
if(m_deinit_reason!=WRONG_VALUE)
return;
then the panel will be normally destroyed and restarted when switching timeframes.

Files:
TradePanel.mq4  15 kb
 

Hello. I am writing an MT4 indicator that only works with graphical objects and also tracks the position of graphical objects created by the same indicator working on a different period. When I move the vertical line of the major period manually the trend lines from the new position of the vertical line of the major period are redrawn, and also the vertical line of the minor period is redrawn. All this is handled in the OnChartEvent event. The problem is that when moving the vertical line of a high period sometimes objects of a low period are not redrawn right away, but only when I double click on the vertical line of an indicator, working on a high period, they are redrawn. And on another more powerful PC this happens less often. I apply the ChartRedraw() function in the code after re-drawing objects.

May it happen due to the lack of PC resources?

I want to try to run the indicators on different charts and use EventChartCustom to generate a custom event from the indicator working on a higher period to the second indicator. Maybe this will speed up the operation of the program?

 

How do I quickly zero (clear) all elements of a structure?


The structure is global. At certain moments it has to be cleared to be filled with new data later.

I understand that you can element by element equate everything to zero. Is there any other way?


struct ABC{

int a1;

int a2;

int a3;

};

ABC a;

We need something like this

a = 0; // all elements in the steel structure are zero

 
Sergey Likho:

How do I quickly zero (clear) all elements of a structure?


The structure is global. At certain moments it has to be cleared to be filled with new data later.

I understand that you can element by element equate everything to zero. Is there any other way?


struct ABC{

int a1;

int a2;

int a3;

};

ABC a;

We need something like this

a = 0; // all elements in the steel structure are zero

ZeroMemory(a);
 
does anyone have a trailing trade that triggers after N pips and then goes after the price?
I have one, but it triggers after N pips and stops at breakeven....
fix it please, i'm out of my head!!!
void TrailingSL()
{
int    er;
if(shagtrala==0) return;
for(int i = 0; i < OrdersTotal(); i++)
  {
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
     {
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
        {
         if(OrderType()==OP_BUY && NormalizeDouble(Ask-OrderOpenPrice(), Digits) >= NormalizeDouble(shagtrala, Digits) &&
         NormalizeDouble(Ask-OrderStopLoss(), Digits) > NormalizeDouble(lTrailingDistance, Digits))
           {
            er = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss() + (lTrailingDistance * _Point), OrderTakeProfit(),OrderExpiration(),0);
           }
         if(OrderType()==OP_SELL && NormalizeDouble(OrderOpenPrice()-Bid,Digits) >= NormalizeDouble(shagtrala, Digits) &&
         NormalizeDouble(OrderStopLoss()-Bid, Digits) > NormalizeDouble(lTrailingDistance, Digits))
           {
            er = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss() - (lTrailingDistance * _Point), OrderTakeProfit(),OrderExpiration(),0);
           }
        }
     }
  }
return;
}
 
ponochka:
does anyone have a trawl that triggers after N pips and then goes after the price?
I have one, but it works after N pips and stops at breakeven....
fix it please, i'm out of my head!!!

here my trawl works, it works:

//____________________________________________________________________________________
bool trailingpos(int magic_,int trail_p){
   string sym=Symbol(); bool res = true; double sl,slnew,tpips = trail_p*Point; int i,k=OrdersTotal();
   for(i=0;i<k;i++){
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
         if(OrderSymbol()==sym && OrderMagicNumber()==magic_){
            switch(OrderType()){
               case OP_BUY:
                           slnew = NormalizeDouble(Ask - tpips,Digits);
                           sl = OrderStopLoss();
                           if(OrderOpenPrice() <slnew)
                              if((sl < slnew) || (sl == 0.0)){
                                    if(!OrderModify(OrderTicket(),OrderOpenPrice(),slnew,OrderTakeProfit(),OrderExpiration(),clrNONE))
                                                   {res = false; Print(__FUNCTION__,"OrderModify завершилась с ошибкой № ",GetLastError());}
                           }
                           break;
               case OP_SELL:
                           slnew = NormalizeDouble(Bid + tpips,Digits);
                           sl = OrderStopLoss();
                           if(OrderOpenPrice()> slnew)
                              if((sl > slnew) || sl ==0.0){
                                    if(!OrderModify(OrderTicket(),OrderOpenPrice(),slnew,OrderTakeProfit(),OrderExpiration(),clrNONE))
                                                   {res = false; Print(__FUNCTION__,"OrderModify завершилась с ошибкой № ",GetLastError());}
                           }
                           break;
              }
           }
        }
     }
return(res);}
//____________________________________________________________________________________

call the function 2 parameters magic number and trawl np

 
Sergey Likho:

How do I quickly zero (clear) all elements of a structure?


The structure is global. At certain moments it has to be cleared to be filled with new data.

I understand that you can element by element equate everything to zero. Is there another way?

// Обнуляет любую простую структуру
template <typename T>
void SetNull( T &Value )
{
  static T NullValue = {0};
  
  Value = NullValue;
}
 

Hello! is there a code for total earnings on all orders in one day?

I have one:

double getProfitFromTime(datetime time)
  {
   double profit = 0;
   
   for(int i = OrdersHistoryTotal() - 1; i >= 0; i--)
      if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
        {
         if(OrderCloseTime() < time)
            break;
         
         profit += OrderProfit() + OrderCommission() + OrderSwap();
        }
   
   return(profit);
  }

It's referred to like this:

getProfitFromTime(iTime(NULL, PERIOD_D1, 0);

Can i modify it in any way, so that i can see the profit for one currency pair in one day and the total profit for all currency pairs?

 
ponochka:

and total for all currency pairs?

RemoveOrderSymbol() == Symbol() from the condition:

if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
then this part of the code will only count all orders in the terminal history by magic number if the magic number for different currencies is the same; if you removeOrderMagicNumber() == magic then all orders will be counted without considering the magic number
 

Hi all. A word of advice to a newcomer. I want to do a little research on spread behaviour. I have some code that calculates the total spread. Everything is written, everything works fine.

void ModifySpread()
{
  int Spread = (Ask - Bid) / Point;
  
    
  Sumsp = SumSp + Spread;
  Vol++;
  
  PrevTime = Time[0];
  
  return;
}

I want to remove moments when spread does not perform any movements, i.e. bid and ask do not change.
I do this:

void ModifySpread()
{
  int Spread = (Ask - Bid) / Point;
  if ((prevsbid == Bid)) && (prevsask == Ask))return;
   
  SumSp = SumSp + Spread;
  Vol++;
  
  

  prevsask = Ask;
  prevsbid = Bid;
  PrevTime = Time[0];
  return;
}

But nothing changes. Where am I going slow?

Reason: