Here the normalisation has to be used in a different sequence.
1. as values of SymbolInfoDouble(Currency,SYMBOL_BID) type come from the server, they are already considered normalized. And there is no need to normalize them a second time. I.e. they can simply be written:
DR 0 Core 1 10:21:49 2012.10.01 01:12:43 start_sel=5.000000000010552e-005 EN 0 Core 1 10:21:49 2012.10.01 01:12:43 start_sel=7.0000000145e-005
Of course, only interested in the sel - where did such numbers come from?
7.00000000000145e-005 is just one way of writing the value of a real number. I think it's called "scientific". For more details see."MQL5 Reference Guide / Language Basics / Data Types / Real Types (double, float)".
Yedelkin: 7.00000000000145e-005 is just one of the ways of writing the value of a real number. I think it's called "scientific". For more details see."MQL5 Reference Guide / Language Basics / Data Types / Real Types (double, float)".
Yedelkin,
Thank you for tackling the problem.
Here is the code. The functions for opening the position were written by Nikolay Kositsin.
Please advise how and where to specify in the EA the MA belonging to the No.2 window. For example, I added MA to MFI and I want to register this MA in my EA. I do not know where and how to do it.
mario065: Here is the code. Functions to open the position were written by Nikolay Kositsin. Nikolay Kositsin.
1. I would say this: use someone else's code with great care. Because someone else's code means someone else's mistakes too.
2. Here(https://www.mql5.com/ru/forum/6343/page64#comment_357008) I suggested that you try to correctly zero variables before using them. But your code hasn't implemented this suggestion yet. Moreover, your code contains constructs of the following type:
//+------------------------------------------------------------------+//| Modify position. |//+------------------------------------------------------------------+bool ModifyPosition(conststring symbol,double StopLoss,double Takeprofit)
{
//---- обявяване на структурата и резултата на търговското исканеMqlTradeRequest request;
MqlTradeResult result;
//---- структурна инициализация на търговското искане MqlTradeRequest за модифициране на позиция
request.action = ...
request.symbol = ...
request.sl = ...
request.tp = ...
...
//---- модифицираме позицията и проверяваме резултата от търговското исканеif(!OrderSend(request,result) || result.deal==0)
{
...
}
ZeroMemory(request);
ZeroMemory(result);
return(true);
}
You see, in this construct the request and result variables are zeroed not before they are used but after they are used. Moreover, when these local variables are zeroed, the function stops operating, i.e. such zeroing itself is meaningless. In other words, such a construction is a good example of how MqlTradeRequest and MqlTradeResult variables should not be zeroed. So, if you are eager, please, try to clear the variables correctly. If something goes wrong, please, describe in details what is "not working".
Gumko:
It's been standing for two days now.
Hello all.
Modification and problems.
External function:
bool ModifyPosition(const string symbol,double StopLoss,double Takeprofit){
//---- binding structure and trade results
MqlTradeRequest request;
MqlTradeResult result;
//---- structure initialization of trade search MqlTradeRequest for position modification
request.action = TRADE_ACTION_SLTP;
request.symbol = symbol;
request.sl = StopLoss;
request.tp = Takeprofit;
string word = "";
StringConcatenate(word,
"<< ============ Modifyposition(): Modify position ",
symbol," ============ >>>");
Print(word);
//---- modify position and check the results of trade search
if(!OrderSend(request,result)|| result.deal==0)
{
Print("Modify error =", GetLastError();
return(false);
}
return(true);
}
But it doesn't work like this.
How to do?
Thank you :)
Try it this way:
Try it this way:
Yedelkin,
Thank you, it didn't work.
I checked if it counts correctly for the start of the function call.
Here's how I did it:
double Bid = NormalizeDouble(SymbolInfoDouble(Currency,SYMBOL_BID),_Digits);
double Ask = NormalizeDouble(SymbolInfoDouble(Currency,SYMBOL_ASK),_Digits);
double Open = NormalizeDouble(PositionGetDouble(POSITION_PRICE_OPEN),_Digits);
double SL = NormalizeDouble(PositionGetDouble(POSITION_SL),_Digits);
if(Open > 0){
start_buy = Ask - Open; Print("start_buy=",start_buy);
start_sel = Open - Bid;Print("start_sel=",start_sel);
}
Surprise in the log:
MR 0 Core 1 10:21:49 2012.10.01 10:12:42 deal #2 sell 0.10 EURUSD at 1.28146 done (based on order #2)
GH 0 Core 1 10:21:49 2012.10.01 01 01:12:42 deal performed [#2 sell 0.10 EURUSD at 1.28146]
NI 0 Core 1 10:21:49 2012.10.01 01 01:12:42 order performed sell 0.10 at 1.28146 [#2 sell 0.10 EURUSD at 1.28146 (0.00000)
OF 0 Core 1 10:21:49 2012.10.01 01 01:12:43 start_buy=0.0001299999999999635
DR 0 Core 1 10:21:49 2012.10.01 01:12:43 start_sel=5.000000000010552e-005
LE 0 Core 1 10:21:49 2012.10.01 01:12:43 start_buy=0.0001099999999998325
EN 0 Core 1 10:21:49 2012.10.01 01:12:43 start_sel=7.00000000000145e-005
Of course I was wondering just sela, where did the numbers come from?
I think I wrote the function correctly as shown:
SL & TP Modification
Trade order for modification of StopLoss and/or TakeProfit levels. Requires 4 fields:
So what exactly "failed"?
Insert the code correctly (Ctrl+Alt+M):
Here the normalisation has to be used in a different sequence.
1. as values of SymbolInfoDouble(Currency,SYMBOL_BID) type come from the server, they are already considered normalized. And there is no need to normalize them a second time. I.e. they can simply be written:
2. But after any arithmetic operation the normalization is gone, so if you need to get a normalized number, you should write it like this:
I'm still thinking about the rest.
DR 0 Core 1 10:21:49 2012.10.01 01:12:43 start_sel=5.000000000010552e-005
EN 0 Core 1 10:21:49 2012.10.01 01:12:43 start_sel=7.0000000145e-005
Of course, only interested in the sel - where did such numbers come from?
7.00000000000145e-005 is just one of the ways of writing the value of a real number. I think it's called "scientific". For more details see."MQL5 Reference Guide / Language Basics / Data Types / Real Types (double, float)".
Yedelkin,
Thank you for tackling the problem.
Here is the code. The functions for opening the position were written by Nikolay Kositsin.
For example, I added MA to MFI and I want to register this MA in my EA. I do not know where and how to do it.
Thank you for your reply)
1. I would say this: use someone else's code with great care. Because someone else's code means someone else's mistakes too.
2. Here(https://www.mql5.com/ru/forum/6343/page64#comment_357008) I suggested that you try to correctly zero variables before using them. But your code hasn't implemented this suggestion yet. Moreover, your code contains constructs of the following type:
You see, in this construct the request and result variables are zeroed not before they are used but after they are used. Moreover, when these local variables are zeroed, the function stops operating, i.e. such zeroing itself is meaningless. In other words, such a construction is a good example of how MqlTradeRequest and MqlTradeResult variables should not be zeroed. So, if you are eager, please, try to clear the variables correctly. If something goes wrong, please, describe in details what is "not working".
3. The Standard Library has a trade class"MQL5 Reference / Standard Library / Trade Classes / CTrade". Try to figure out how to apply it in practice. At the initial stage of immersion into the language, this class may be quite sufficient. For example, this class has the following method:"MQL5 Reference / Standard Library / Trade Classes / 2CTrade/ PositionModify". It is implemented as follows:
The 'ClearStructures();' line in it clears the m_request variable before using it.