Questions from Beginners MQL4 MT4 MetaTrader 4 - page 84

 
Arseniy Barudkin:   Hello Sirs, please help me to write this function.

Happy Victory Day!!! It's been 4 days - no reply. Let's try... Dissatisfied people write in person!!!

//+-------------------------------------------------------+
//| функция перебрала открытые ордера на графике          |
//| и выделила: 1) с самым маленьким лотом и --- профитом |
//| 2) с самым большим лотом и +++ профитом.       скрипт |
//| Предполагается, что такие есть. И удалила    PROBA.mq4|
//+-------------------------------------------------------+
// Назначение функций OrdersTotal, OrderSelect, OrderClose
// и прочих узнаем поставив на них курсор и нажав F1

#property strict

void OnStart()
{
   int    Проскальзывание=20;
   int    Тикет1 =0,  Тикет2=0;
   double Лот1=100000, Лот2=0;
   bool   Результат;     //  Чтоб избежать лишних предупреждений

   // Выделение
   for(int Тикет=OrdersTotal()-1; Тикет>=0; Тикет--)
   {
     if(!OrderSelect(Тикет,SELECT_BY_POS)) continue; // Что-то помешало - идем к следующему
     if(OrderSymbol() != _Symbol) continue;          // Чужой график

     // Если с меньшим лотом и   --- профитом   то запомним тикет и лот
     if(OrderLots()<Лот1     &&  OrderProfit()<0)
     {
       Тикет1=OrderTicket();
       Лот1=OrderLots();
     }

     // Если с большим лотом и   +++ профитом   то запомним тикет и лот
     if(OrderLots()>Лот2     &&  OrderProfit()>0)
     {
       Тикет2=OrderTicket();
       Лот2=OrderLots();
     }
   }

   // Удаление
   if(Тикет1)
   {
      while(!RefreshRates());
      if(OrderSelect(Тикет1,SELECT_BY_TICKET))  // Чтоб получить цену закрытия
         Результат=OrderClose(Тикет1, Лот1,OrderClosePrice(),Проскальзывание);
   }

   if(Тикет2)
   {
      while(!RefreshRates());
      if(OrderSelect(Тикет2,SELECT_BY_TICKET))
         Результат=OrderClose(Тикет2, Лот2,OrderClosePrice(),Проскальзывание);
   }
}   

And then the question arose: if there are only two orders. One with a big lot with negative profit, and one with a smaller lot with positive profit

What if there's only one order. What if all orders have the same lot and all with a negative profit - should we close one by one?

 

Hello!

Can I get some help? The Expert Advisor is retrieving tradesevery tick. How do I write code to take away about 5 trades or only as many as I want?

extern int tp=50;

extern int sl=200;

extern double lot=0.01;

void OnTick()

{

OrderSend("USDJPY",OP_SELL,lot,Bid,0,Ask+sl*Point,Ask-tp*Point, "Batsasho",1,0,Red);

}

What should I change, add to the code?

Can you answer ***.

Thank you!

 
alstefanov:

Hello!

Can I get some help? The Expert Advisor is retrieving tradesevery tick. How do I write code to take away about 5 trades or only as many as I want?

extern int tp=50;

extern int sl=200;

extern double lot=0.01;

void OnTick()

{

OrderSend("USDJPY",OP_SELL,lot,Bid,0,Ask+sl*Point,Ask-tp*Point, "Batsasho",1,0,Red);

}

What should I change, add to the code?

Can you answer ***.

Thank you!

extern int tp=50;

extern int sl=200;

extern double lot=0.01;

void OnTick()

{ 

if(OrdersTotal()==0)OrderSend("USDJPY",OP_SELL,lot,Bid,0,Ask+sl*Point,Ask-tp*Point,"Batsasho",1,0,Red);

}
 
Please advise how to speed up the work of the EA in the tester for it to be tested faster, the EA uses only one indicator
 
missha32 How do I make my EA faster in the Strategy Tester, it uses only one indicator

First of all, shorten the testing time interval. Best: 1) the last three months. 2) three months with a brexit in the middle. Make sure not to test on all ticks. In fact, in MT4, there are no ticks in the history, and they are modeled by light jerks of price up and down. If you test on two timeframes - M15 and M1, then see, where it is better. Or, better yet, use the demo - start it on Monday morning and check the result on Friday evening using the well-known script. If we need to test 100 Expert Advisors, we open 10 terminals and in each terminal there are 10 charts with Expert Advisors.

It is necessary to have a lot of computers. On a real account $4 with 500 leverage is enough. Look at any chart - with correct entry you can easily double your deposit in a day. And that's a million times in a month. Are there such free EAs on the Internet? Will anyone sell such? Therefore, the money should be invested in computers. We are looking for the entry points. We write programs, calculate in Excel using the formulas and macros, and write scripts and Expert Advisors for calculations. Then, when we figure out how to find entry points, and then Robots, Stops, Trawl, Deposit, Deposits, Withdrawals...

 
STARIJ:

Happy Victory Day! It's been 4 days - no response. Let's try... The dissatisfied ones write in their personal accounts!!!

And then the question arose: if there are only two orders. With a big lot with a negative profit, with a smaller lot with a positive profit

What if there's only one order. What if all orders have the same lot and all with a negative profit - should we close one by one?

for(int Ticket=OrdersTotal()-1; Ticket>=0; Ticket--) - this is the code of the market orders search by ticket in the reverse order (from the last order opened to the first one) - do I get it right?

But "Ticket" doesn't work in Cyrillic, it has to be "Ticket" in Latin.

 
Yaroslav Nykula:
for(int Ticket=OrdersTotal()-1; Ticket>=0; Ticket--) - this is the code of the market order search by the ticket in the reverse order (from the last opened to the first one) - do I get it right?

But "Ticket" in Cyrillic won't work, you need "Ticket" in Latin.

Didn't check, but it should pass not only in Cyrillic but also in Chinese.
 
Vitaly Muzichenko:   I haven't checked, but it should pass not only in Cyrillic but also in Chinese.
When I take up a new language, first of all I check whether Cyrillic eats Cyrillic, or spits it out. This one does. Here's that script - check it out.
Files:
PROBA.mq4  2 kb
 
Hello. The question is: Can we load the values of ticks (the corresponding prices) for a certain trading period (i.e., for a single candle) into a one-dimensional array? And to do it in such a way that the array is formed during the formation of a candle. Is it realistic in MQL4? I would be grateful for your feedback.
 
STARIJ:

Happy Victory Day!!! It's been four days - no answer. Let's try... Dissatisfied people are writing in private!!!

And then a question arose: if there are only two orders. With a big lot with a negative profit, with a smaller lot with a positive profit

And if there is only one order. And if all orders have the same lot and all with a negative profit, should we close one by one?


Thank you very much! This is a good function! This function should be called if there is not enough margin to open another order. But I did not express my idea correctly; it turns out I needed something else! The largest lot with the largest profit from open positions and the smallest lot with negative profit from open positions.
Reason: