Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 461

 
Dmitry01110:
Hi! Could you please tell me how to edit a file created by FileOpen function, e.g. delete a byte from the current position and insert another one in its place!


Also trying to do something similar.

There is a *.csv file with just one column, i.e. the digits in it go under each other. I am trying to make it so that each time a digit is used, there is an icon next to it, indicating that this digit has already been used by the EA.

You may prepare a *.csv file with two columns - [NUMBER]; [SIGN].

 
wolfovik:

Also in the tester there is a constant error PB Trade EURUSD,H1: OrderSend error 130

Although stops are at 300 pips!

It doesn't work like this!

Where did I go wrong?


Calculated prices in the trade order must be normalized to Digits:

ticket = OrderSend(Symbol(),OP_BUY,0.1,Ask,5,NormalizeDouble(Bid-300*Point,Digits),NormalizeDouble(Bid+300*Point,Digits));

You also need to check stop order values for validity against StopLevel requirements:

input int  StopLoss    =  300;   // Значение Stop Loss в пунктах
input int  TakeProfit  =  300;   // Значение Take Profit в пунктах
int   level=0, spread=0;
//+------------------------------------------------------------------+
//|   Старт                                                          |
//+------------------------------------------------------------------+
void OnTick() {
   level=MarketInfo(Symbol(),MODE_STOPLEVEL);
   spread=MarketInfo(Symbol(),MODE_SPREAD);
   if(level==0) level=spread*2;
//---
   int    ticket=0;
   double sl=0, tp=0;
   if(StopLoss>0) sl=NormalizeDouble(MathMin(Bid-StopLoss*Point,Bid-(level+1)*Point),Digits);
   if(TakeProfit>0) tp=NormalizeDouble(MathMax(Bid+TakeProfit*Point,Bid+(level+1)*Point),Digits);
   ticket = OrderSend(Symbol(),OP_BUY,0.1,Ask,5,sl,tp);
   return;
}

For Buy, approximately like this

 
Dmitry01110:
Hi, could you please tell me how to edit a file created with the FileOpen function, e.g. delete a byte from the current position and insert another in its place!
You call the whole text of the file to a string variable, edit it as a simple variable, then call the file write only and return the variable back.
 
Roger:
You call the entire text of a file to a string variable, edit it as a simple variable, then call that file write-only and return that variable back.

What if the number of characters in the file exceeds the maximum size of characters in the string variable?
 
I've figured it out a bit! To replace a value in some file position, you just need to put a pointer to the previous byte using FileSeek, and then, using FileWriteInteger, for example, write a new value there, which will overwrite the old one. The main thing is that old and new values should be of the same size, e.g. LONG_VALUE for int.
 
I had my terminal updated today. Now it can't see the indicators... What to do and did I put it correctly. In the same folder(path) as before.
 

for(int l = StringLen(tfs)-1; l >= 0; l--) { int char = StringGetChar(tfs,l); }

There is an error in the code. Why is "char" sworn in? How and what can I replace it with?

 
artmedia70:
What if the number of characters in the file exceeds the maximum size of characters in the string variable?

There is no limit to the string variable. Or rather, there is, but it is very big. For MT4 from the 529 build it is 2147483647 characters and 2 times less if MT4 is in 32-bit OS. And it is not always. There are different keys and PAE.

Dmitry01110:
Figured it out a bit! To replace a value in some file position, you just need to put a pointer to the previous byte using FileSeek and then, using FileWriteInteger, for example, write there the new value, which will overwrite the old one. The main thing is that old and new values must be of the same size, e.g. LONG_VALUE for int.
Yes, and for CSV the number of characters must match.

Zolotai:

for(int l = StringLen(tfs)-1; l >= 0; l--) { int nChar = StringGetChar(tfs,l); }

There is an error in the code. Why is "char" sworn in? How and what can I replace it with?

 
cp
 
artmedia70:

The calculated prices in the trade order must be normalised to Digits:

You also need to check stop order values for validity against StopLevel requirements:

For Buy...


Thanks, but I've decided to use virtual stop and take for now.

There is still a problem with long EA execution. But indicator works separately without any problems.

How can I optimise it?

Reason: