You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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.