[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 718

 
Roger:
You read the file line by line and assign values to your variables each time. When the file ends, the variables will have the last values.

How to implement this?

I can't figure out what to use

 
zheleznii:

How to implement this?

Can't figure out what to use


A lot has already been written and re-written about this, try https://www.mql5.com/ru/forum/118349
 

Good night again! I have recently started writing a multicurrency EA that opens orders on one currency pair and opens orders on another one.

I ripped out the nearest trailing stop from the EA and started to play with it but it did not work. Here is the code:

// ну так сообственно вызываю функцию - TrailingStop();
//вот что в функции
 void TrailingStop()
{ 
   if (TrailingStop<MinStop) return; 
   int ask, bid, open, stop, level; 
   for (int i=0; i<OrdersTotal(); i++) 
      { 
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break; 
      if (OrderSymbol()!=Symbol()) continue; 
      if (OrderType()==OP_BUY) 
         { 
         bid=MathRound(Bid/Point); 
         open=MathRound(OrderOpenPrice()/Point); 
         stop=MathRound(OrderStopLoss()/Point); 
         level=bid-TrailingStop; 
         if (level<open || level>bid-MinStop) continue; 
         if (stop>0 && stop>=level) continue; 
         OrderModify(OrderTicket(),OrderOpenPrice(),level*Point,OrderTakeProfit(),0,White); 
         Print("трал сдвинут");
         //ShowError(); 
         } 
      if (OrderType()==OP_SELL) 
         { 
         ask=MathRound(Ask/Point); 
         open=MathRound(OrderOpenPrice()/Point); 
         stop=MathRound(OrderStopLoss()/Point); 
         level=ask+TrailingStop; 
         if (level>open || level<ask+MinStop) continue; 
         if (stop>0 && stop<=level) continue; 
         OrderModify(OrderTicket(),OrderOpenPrice(),level*Point,OrderTakeProfit(),0,White); 
         //ShowError(); 
         Print("трал сдвинут");
         } 
      } 
}

here is what I cannot figure out. Since the Expert Advisor is a multicurrency Expert Advisor, it opens orders for currencies in unpredictable manner and sometimes opens them at one and the same moment for several currencies.

In the trailing code I calculate open orders for(int i=0; i<OrdersTotal(); i++) and further goes order selection OrderSelect etc. I understand that each open order for a certain currency pair requires data bid, ask, etc. But here I want to find out what data should be downloaded and how will I select an order for changes? I have only one variant in my mind, the worst one is to write a trailing stop for each currency ) Please advise what may be done.

 
Infinity:

Good night again! I have recently started writing a multicurrency EA that opens orders on one currency pair and opens orders on another one.

I ripped out the nearest trailing stop from the EA and started to play with it but it did not work. Here is the code:

here is what I cannot figure out. Since the Expert Advisor is a multicurrency Expert Advisor, it opens orders for currencies in unpredictable manner and sometimes opens them at one and the same moment for several currencies.

In the trailing code I calculate open orders for(int i=0; i<OrdersTotal(); i++) and further goes order selection OrderSelect etc. I understand that each open order for a certain currency pair requires data bid, ask, etc. But here I want to find out which data to load and how to select an order for changes. I have only one variant in my mind, the worst one is to write a trailing stop for each currency ) Please advise what may be done.

Try to pass a tool symbol into the trawl code. Then for each pair you will call trawl.
void TrailingStop(string sy)

if (sy == "" || sy == "0") sy = Symbol();
Well and based on sy value assign other values to specific symbol data... The same Ask with Bid, for example...
 

Infinity:

I don't quite understand the technology, how it will work


 
Roger:

A lot has already been written and re-written about it - try https://www.mql5.com/ru/forum/118349.

int a1;

int handle=FileOpen("a1.csv",FILE_READ|FILE_WRITE,';');
FileWrite(handle,a1);

FileClose(handle);

In the file a1=5;

I do not understand the basics.

int handle=FileOpen("a1.csv",FILE_READ|FILE_WRITE,';');
here we assign value 5 to a1

FileClose(handle);

very necessary

 
Infinity:
Assign values to variables in the trawl code based on data on the pair passed to the function. You need to finalize the trawl code... For example, the Bid variable should not just be declared,

but declared with a value assigned to it:

int ask = MarketInfo(sy, MODE_ASK), bid=MarketInfo(sy, MODE_BID), open, stop, level;

Accordingly

bid=MathRound(Bid/Point);

should already be written otherwise, for example:

bid=MathRound(MarketInfo(sy, MODE_BID)/Point);

Or create another variable, e.g. PriceBid and write

PriceBid=MathRound(Bid/Point);

and then use PriceBid instead of Bid in the code...

Look through all your code and use variables for a particular symbol where necessary.
And this symbol you will pass to the trawl function when calling it:

 TrailingStop( EURUSD);     // Тралим ЕвроБаксы
 TrailingStop("");         // Тралим символ графика

or

TrailingStop(NULL);         // Тралим символ графика

Is it clearer?

 
artmedia70:
Assign values to variables in the trawl code based on data on the pair passed to the function. You need to finalize the trawl code... For example, the Bid variable should not just be declared,

but declared with a value assigned to it:

Correspondingly

should already be written otherwise, for example:

Or create another variable, e.g. PriceBid and write

and then use PriceBid instead of Bid in the code...

Look through all your code and use the fetching of variable values for a particular symbol.
And this symbol you will pass to the trawl function when calling it:

or

Is it clearer?





The only thing I don't understand is which currency pair should be sent to me at which moment. I don't know where to get information that, for example, 4 orders are open on such pairs and that these pairs should be sent to me.

I don't know if I'm doing it right or not... anyway ....

в блоке start  определяю открытые ордера и определяю по каким парам они открыты
 for (int i=0; i<OrdersTotal(); i++) 
      { 
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break; 
      if (OrderSymbol()=="EURUSD") {sy="EURUSD";MinStop=MarketInfo(sy,MODE_STOPLEVEL); break; }
      if (OrderSymbol()=="GBPUSD") {sy="GBPUSD";MinStop=MarketInfo(sy,MODE_STOPLEVEL); break; }
       
      } 
  TrailingStop(sy);

а в функции делаю следующее

void TrailingStop(string sy)
{ 
   if (TrailingStop<MinStop) return; 
   int ask, bid, open, stop, level,point; 
   for (int i=0; i<OrdersTotal(); i++) 
      { 
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break; 
      if (OrderSymbol()==sy)  
      bid=MarketInfo(sy,MODE_BID);
      ask=MarketInfo(sy,MODE_ASK);
      point=MarketInfo(sy,MODE_POINT);
      if (OrderType()==OP_BUY) 
         { 
         bid=MathRound(bid/point); 
         open=MathRound(OrderOpenPrice()/point); 
         stop=MathRound(OrderStopLoss()/point); 
         level=bid-TrailingStop; 
         if (level<open || level>bid-MinStop) continue; 
         if (stop>0 && stop>=level) continue; 
         OrderModify(OrderTicket(),OrderOpenPrice(),level*point,OrderTakeProfit(),0,White); 
         Print("трал сдвинут");
         //ShowError(); 
         } 
      if (OrderType()==OP_SELL) 
         { 
         ask=MathRound(ask/point); 
         open=MathRound(OrderOpenPrice()/point); 
         stop=MathRound(OrderStopLoss()/point); 
         level=ask+TrailingStop; 
         if (level>open || level<ask+MinStop) continue; 
         if (stop>0 && stop<=level) continue; 
         OrderModify(OrderTicket(),OrderOpenPrice(),level*point,OrderTakeProfit(),0,White); 
         //ShowError(); 
         Print("трал сдвинут");
         } 
      } 
}

But for some reason I got an error EURUSD: zero divide - this error probably means somewhere in the variable 0, probably during a split-type operation. Am I trying to implement it correctly at all?

 
zheleznii:

int a1;

int handle=FileOpen("a1.csv",FILE_READ|FILE_WRITE,';');
FileWrite(handle,a1);

FileClose(handle);
In the file a1=5;

Misunderstanding in the basics. Please explain - by completing the proposed

int handle=FileOpen("a1.csv",FILE_READ|FILE_WRITE,';');
here we assign value 5 to a1

FileClose(handle);

I really need it.

So, in order.

If only the latest data is needed, then why save the previous ones? ("before write" occurs with combination of FILE_READ|FILE_WRITE modes).
Therefore it is more logical to use FILE_CSV|FILE_WRITE mode, where previous records are deleted before writing new data.

Let's start writing 4 variables to the file.

//+------------------------------------------------------------------+
int start(){
   int handle;
   int a1 = 3;
   double punkt = 0.4;
   double nn = 1128;
   double mm = 1000;

   handle=FileOpen("a1.csv",FILE_CSV|FILE_WRITE,';');
   FileWrite(handle,a1,punkt,nn,mm);
   FileClose(handle);           
}
//+------------------------------------------------------------------+

The main thing is to remember the order in which the variables are written, because this is the order in which we will read them.

Let us start reading data into variables from the file.

//+------------------------------------------------------------------+
int start(){
   int handle;
   int a;
   double p;
   double n;
   double m;   
   handle=FileOpen("a1.csv",FILE_CSV|FILE_READ, ';');         
   
   a = FileReadNumber(handle);    //считываем первую цифру, соответствующую переменной a1 и далее по порядку...
   p = FileReadNumber(handle);    //punkt
   n = FileReadNumber(handle);    //nn
   m = FileReadNumber(handle);    //mm
   
   FileClose(handle);           
}
//+------------------------------------------------------------------+

Using the FileReadNumber() function, we read the number after the number in the order in which they were written.
That's all there is to it, nothing complicated :)

 
Infinity:


The only thing I don't understand is which currency pair should be sent to me at which moment. Where do I get the information that, for example, 4 orders are open on such pairs and that these pairs should be sent to me?

I don't know if I'm doing it right or not ... anyway ....

But i got EURUSD: zero divide error. Apparently, this error says i have 0 in a variable somewhere, probably, it's a division operation. Am I even trying to implement it correctly ?

Do proofreading after each variable assignment operation, or before each division operation, to see where you get a zero, and then start from there.
Reason: