Don't double post! You already had another thread open.
General rules and best pratices of the Forum. - General - MQL5 programming forumDon't double post! You already had another thread open.
General rules and best pratices of the Forum. - General - MQL5 programming forumNo one replied on the other thread, what am I meant to do?
No one replied on the other thread, what am I meant to do?
Well on the other thread, William posted for you to edit your post and use the code button (Alt + S).
You didn't.
A lot of people won't bother to read code if you can't be bothered to post it correctly.
Strange that you have managed to post it correctly here!
Please don't just post that something doesn't work. Supply as much information as possible.
I have deleted your other topic.
My code for a trailing stop does not work, can someone please advise me on what is wrong with the code
Hi Micobez,
I'm not an expert for the coding, but with 2 or 3 person helping, I coded this Trailing stop :
extern double TrailingStart=2500 ; // Trailing starting extern double TrailingStop=2000 ; // Break Even extern double TrailingStep=100; // Trailing stop double tStopLoss = NormalizeDouble(OrderStopLoss(),Digits); double sl = OrderStopLoss(); bool ticket = false ; RefreshRates(); if (OrdersTotal()>0) { for (i=OrdersTotal(); i >= 0 ; i--) { if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)== true) if (OrderType()==OP_BUY) { if (Ask>NormalizeDouble(OrderOpenPrice()+TrailingStart*Point,Digits) && tStopLoss < NormalizeDouble (Bid - (TrailingStop+TrailingStep)*Point,Digits)) { tStopLoss = NormalizeDouble (Bid-TrailingStop*Point,Digits); ticket = OrderModify (OrderTicket(),OrderOpenPrice(),tStopLoss, OrderTakeProfit(),0,White); } } if (OrderType()==OP_SELL) { if (Bid < NormalizeDouble (OrderOpenPrice()-TrailingStart*Point,Digits) && (sl > (NormalizeDouble (Ask+(TrailingStop+TrailingStep)*Point,Digits))) ) { tStopLoss = NormalizeDouble(Ask+TrailingStop*Point,Digits); ticket = OrderModify(OrderTicket(),OrderOpenPrice(),tStopLoss,OrderTakeProfit(),0,Red); } } } }
I hope that will help you.
My code for a trailing stop does not work, can someone please advise me on what is wrong with the code
Just saying "does not work" is not very helpful. You'd better specify what does not work, what error messages you see, what you have tried, and so on.
The first line seems odd to me. This will go on forever, without stopping?
for(int i=0;i>=0;i++)
On top of that, index i is not used to select a specific open position inside the if-loop?
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
My code for a trailing stop does not work, can someone please advise me on what is wrong with the code