Questions from Beginners MQL5 MT5 MetaTrader 5 - page 410

 
rosomah:

Can you tell me if using Standard Library, when getting Ask and Bid, do you need to do mysymbol.RefreshRates();

i.e. update or for data from the Library do you not need to update?

or

if you need current prices, you don't need to do anything

if((Bid-Xprice)/Point>=Step)

 

I do not understand something) I have been working on this code for 3 hours. it is a function for a grid. it is called on opening a new order in the grid, its purpose is to recalculate TP and change it for all orders in the grid

But it only changes TP of the oldest order in the grid.

What am I mixing up?))

void ModifyOrders()
  {
   double avg= 0;
   int count = 0;

   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY || OP_SELL)
              {
               avg+=OrderOpenPrice();
               count++;
              }
           }
        }
     }
   int Tcount=count-1;        // Print("204");
   avg=(Tcount*Step*0.4);
//     avg=NormalizeDouble(avg/count,Digits);
   for(int i=OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY)
              {
               double Bprice=FindLastBuyPrice();//Print("215");
               TP=NormalizeDouble(Bprice+avg*Point,Digits); //Print("216");
               bool res=OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0,Blue);// Print("217");
               if(!res)
                  Print(" Error modification. Error code = ",DoubleToString(GetLastError(),0));
              }

            if(OrderType()==OP_SELL)
              {
               double Sprice=FindLastSellPrice();
               TP=NormalizeDouble(Sprice-avg*Point,Digits);
               bool res=OrderModify(OrderTicket(),OrderOpenPrice(),0,TP,0,Red);
               if(!res)
                  Print(" Error modification. Error code = ",DoubleToString(GetLastError(),0));
              }
           }
        }
     }

  }
 
Leanid Aladzyeu:

I do not understand something) I have been working on this code for 3 hours. it is a function for a grid. it is called on opening a new order in the grid, its purpose is to recalculate TP and change it for all orders in the grid

But it only changes TP of the oldest order in the grid.

What am I mixing up?))

When are you going to change the browser? Just like a child.
 
Karputov Vladimir:
When will you change your browser? Just like a child.

It's a problem with the site that they haven't adapted the site to my browser. Service Desk as usual, 0 help. I'm fine with my browser.

 
Leanid Aladzyeu:

It's a problem with the site that they haven't adapted the site to my browser. Service Desk as usual, 0 help. I'm fine with my browser.

You can always use Internet Explorer to paste code - it will paste the code exactly. Think of the people around you - it's embarrassing to read the code as text that you paste.
 

Can you tell me the code for MT4. If a new bar has arrived then redraw the chart indicator.

I think I found the code and put it to start

if(IsNewBar())
   {
    Print("Новый бар");
    RefreshRates();
    WindowRedraw();

   }

// функция за кодом

 bool IsNewBar()

{

   static datetime BARflag = 0;

   datetime now = Time[0];

   if(BARflag < now)

   {

      BARflag = now;         

      return(1);

   }

   

   else

   {

      return(0);

   }

}


Print goes out but the chart does not redraw it =(

 
twiling1983:

Can you tell me the code for MT4. If a new bar has arrived then redraw the chart indicator.

I think I found the code and put it to start


Print goes out but the chart does not redraw it =(

Probably because RefreshRates and WindowRedraw have no effect on indicators. You need to dig the indicators.
 

How to determine what we are buying on the current chart and for what (crooked Russian, sorry). For example, on the EURUSD chart, the base currency (what we buy) is EUR and the quoted currency (what we buy for) is USD. They can be identified:

string first = SymbolInfoString(Symbol(), SYMBOL_CURRENCY_BASE);
string second = SymbolInfoString(Symbol(), SYMBOL_CURRENCY_PROFIT);

What about gold, for example? On a GOLD chart both values will be USD. And I need to determine that we are buying gold for USD. Analyzing the symbol name string is not appropriate.

 
Alexey Viktorov:
Probably, because RefreshRates and WindowRedraw have no effect on indicators. You have to dig into the indicators.

Well, if you press the refresh button in the terminal, everything is recalculated.

how do you press the same button in the code? =)

That's how I see it.

ChartSetSymbolPeriod(0,NULL,PERIOD_CURRENT);

 

Started studying arrays .

I have written a pro-order function with arrays , 3 arrays = 0 buy, 1= sell, 2= total buy and sell trades.

Then I wrote a condition to buy if ( the first condition && array [0] == 0 )then we open a buy

and on sale if ( the first condition && array [1]== 0) then we open a Sell position.

But the tester throws an error and the test stops, what is the problem? ( error " array exit " )

Reason: