Questions from Beginners MQL4 MT4 MetaTrader 4 - page 86

 
smart_man:

How to make data of all global variables to be saved even after closing the terminal in normal and abnormal mode?

The question concerns variables declared at the beginning of the code like this:

#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

extern double  VAR1 = 1;

double VAR2[1000];

I need not to lose values of VAR1 and VAR2 (the array is filled with data during Expert Advisor's operation). So far, the only idea is to write data into a file (global.txt) at every tick and then, when the terminal is launched, read from the file (global.txt) and recreate the variables and then write them again at every tick. What other options are there?

Either to the terminal's global, or to a resource.
 
Arseniy Barudkin:

Thanks for the help! I have left it like this for now, now I decided to change a little bit the conditions under which the function is called. And in general, you have helped me a lot))

You are right not to get an answer. You have to set the problem, otherwise it cannot be solved.

Let's take a look at the original ToR:

"Arseniy Barudkin2017.05.23 19:56 RU

Greetings Gentlemen! I do not want to take it for flooding, but I can not do without this feature. So guys can anyone help me with a function that goes through all orders and removes two orders simultaneously, one with the smallest lot and negative profit from existing on the chart, and the second with the largest lot and positive profit as well from existing. "

What do we see in the code you have shown us?

1. All orders were opened by Expert Advisor and have a unique Magic.

2. The total profit of the orders we are looking for is positive.

3. The orders are opposite.

4. The lot size with a positive profit is strictly larger than the lot size with a negative one.

Where does this appear in the presented TOR?

In addition: the code shows that you do not know how to close opposite orders, losing at least the spread.

 
fxtz:

Question Can I write a program in Metatrader 4 to open from 2 to 250 positions of my choice with a set stoploss and set profit in one click? So I don't have to manually open one at a time

If your broker's restrictions are so steep, the programming language is designed to write scripts automatically.
 
Mislaid:

You are right not to get an answer. You have to set the problem, otherwise it cannot be solved.

Let's take a look at the original ToR:

"Arseniy Barudkin2017.05.23 19:56 RU

Greetings Gentlemen! I do not want to take it for flooding, but I can not do without this feature. So guys can anyone help me with a function that goes through all orders and removes two orders simultaneously, one with the smallest lot and negative profit from existing on the chart, and the second with the largest lot and positive profit as well from existing. "

What do we see in the code you showed us?

1. All orders were opened by Expert Advisor and have a unique Magic.

2. The total profit of the orders we are looking for is positive.

3. The orders are opposite.

4. The lot size with a positive profit is strictly larger than the lot size with a negative one.

Where does this appear in the presented TOR?

In addition: the code shows that you do not know how to close the counter orders, losing at least the spread.


I'm not arguing a lot of flaws! I'm just getting into this type of activity. I am writing to this thread to get some help or to point out the mistakes! I think this is what it is for. Now for the code. 1) Maybe, I do not understand something, but what's wrong with the fact that all orders in the Expert Advisor have a unique Magic? 2) This condition and in general this entire function is designed in order to close at least two opposite orders in case of a heavy margin load and not to go in the red, the 3rd and 4th points refer to the same thing. And I really don't know how to close counter orders correctly.
 
Arseniy Barudkin:

I'm not arguing a lot of flaws! I'm just getting into this line of work. And I am writing in this thread to get help or to point out mistakes! In my opinion this is what it is for. Now for the code. 1) Maybe, I do not understand something, but what's wrong with the fact that all orders in the Expert Advisor have a unique Magic? 2) This condition and in general this entire function is designed in order to close at least two opposite orders in case of a heavy margin load and not to go in the red, the 3rd and 4th points refer to the same thing. I do not know how to close opposite orders correctly.
If you were my student, I would give you a "good" for submitting the code. And, if in the process of communication, you could show that you are able to generate ideas, then "excellent" From your answer, I see that you are thinking correctly
 

Hello ... EA written in MQL4, trades market orders Buy, Sell withTrailing... Decided to add pending BuyStop, SellStop ... and encountered an unexpected problem = as soon as anypending order appears in MT4 window,Trailing stops working(SL is not set,Modify is not there)... I don't understand what the problem is,trailing function is standard with backtracking from library, two selected pp., ... or it's not about the function? Maybe someone has encountered something like this?

int TralFunck(int Ticket)

 {   double TralPrice=0,Punkt=0;

   chk=OrderSelect(Ticket,SELECT_BY_TICKET,MODE_TRADES);

for(Ticket=OrdersTotal()-1; Ticket>=0; Ticket--)  

  { if (OrderProfit()<=0)       continue;

    if (OrderType()==4)		 continue;

    if (OrderType()==5) 	 continue;

   if (OrderType()==0)  {   Punkt=(Bid-OrderOpenPrice())/Point;TralPrice=NormalizeDouble((Bid-Tral*D*Point),Digits);  }

   if (OrderType()==1)  {   Punkt=(OrderOpenPrice()-Ask)/Point;TralPrice=NormalizeDouble((Ask+Tral*D*Point),Digits);   }

   if (Punkt<MarketInfo(Symbol(),MODE_STOPLEVEL))       continue;

   if(Punkt<(Tral+TP)*D)        continue;

   if(OrderType()==0 && TralPrice<=NormalizeDouble(OrderStopLoss(),Digits))     continue;

   if(OrderType()==1 && TralPrice>=NormalizeDouble(OrderStopLoss(),Digits) && OrderStopLoss()!=0)       continue;

   ModifyOrder(OrderTicket(),OrderOpenPrice(),TralPrice,OrderTakeProfit());     continue;

   }   return(0);

 }


 
Yaroslav Nykula:

Hello ... EA written in MQL4, trades market orders Buy, Sell withTrailing... Decided to add pending BuyStop, SellStop ... and encountered an unexpected problem = as soon as anypending order appears in MT4 window,Trailing stops working(SL is not set,Modify is not there)... I don't understand what the problem is,trailing function is standard with backtracking from library, two selected pp., ... or it's not about the function? Maybe someone has encountered something like this?



Replace return(0); by continue; in order not to exit the loop. At the end of the function leave it as is.

Use the SRC button in the editor to insert code

 
Victor Nikolaev:


Replace return(0); with continue; so as not to exit the loop. At the end of the function, leave it as it is.

Use the SRC button in the editor to insert the code


Thanks ... fixed it ... I'll take the SRC button in the editor into account, sorry ... But the problem remains the same,Trailing andModify do not want to work withpending orders.
 
I recently started trading on mt4. I decided to test my strategy, but in the strategy tester I don't have the visualisation function or the pause button.
 
vsmutew7:
I recently started trading on mt4. I decided to test my strategy, but my strategy tester does not have a visualisation function or a pause button.

Probably need a wider window, especially the one with the 'Start' button

Reason: