Ive got the code from this video, that works fine for him that´s why i dont understand where is the fail code.
https://www.youtube.com/watch?v=f_LfSAamO44
https://www.youtube.com/watch?v=f_LfSAamO44
Felipe Montes:
for(int b=OrdersTotal()-1;b>=0;b--){
if (OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol()){
Comment( Ask + "-" + (TSCompra*_Point) + "=" + (Ask-(TSCompra/100)));
double slcompra= Ask - (TSCompra*_Point) ;
if (OrderType()==OP_BUY){
if(OrderStopLoss() < slcompra){
OrderModify(OrderTicket(),OrderOpenPrice(),slcompra,OrderTakeProfit(),0,CLR_NONE);
}
}
}
}
Hi ! I´ve got a problem with this code, its a trailing stop just for BUY operations for now, when i have an open trade
,see what happens, i dont understand why it modifies StopLoss so many times with random values. I wrote
Print
function to check which value was sending, and it is the right value! , but when you put "slcompra" in OrderModify , 1: It
modifies so many times, 2: it modifies random values , no sense. Im attaching 2 screenshots to help you. Thanks
Hello,
try this code......
//--- bool OrdrModify=false; double TSCompra=10;//It's only for testing this parameter. Not need to copy in your code. double slcompra=0; //--- for(int b=OrdersTotal()-1; b>=0; b--) { if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol()) { Comment(DoubleToStr(Ask,_Digits) + "-" + DoubleToStr((TSCompra*_Point),_Digits) + "=" + DoubleToStr((Ask-(TSCompra/100)),_Digits)); slcompra= Ask - (TSCompra*_Point) ; if(OrderType()==OP_BUY) { if(OrderStopLoss() < slcompra) OrdrModify=OrderModify(OrderTicket(),OrderOpenPrice(),slcompra,OrderTakeProfit(),0,CLR_NONE); } } } } //---
Nikolaos Pantzos:
Hello,
try this code......
Happens exactly same thing
There aren´t any errors on Register, it modifies it all correctly but not with right values and not just 1 time
It is working fine now , i fixed it thanks
Felipe Montes: It is working fine now , i fixed it thanks
- Don't say that. Anyone searching and finding this thread will learn nothing. Post what you did.
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum
- Please edit your (original) post and use the CODE
button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
}
}
}
Hi ! I´ve got a problem with this code, its a trailing stop just for BUY operations for now, when i have an open trade ,see what happens, i dont understand why it modifies StopLoss so many times with random values. I wrote Print function to check which value was sending, and it is the right value! , but when you put "slcompra" in OrderModify , 1: It modifies so many times, 2: it modifies random values , no sense. Im attaching 2 screenshots to help you. Thanks