I of course have code for the EA which checks the signals too, but I doubt there is something wrong with that code since that worked good before I put the TrailingStop in.
Thanks for your help, RaptorUK.
You need to learn to count and check your { } braces . . . and have a consistent formatting style.
You need to learn to count and check your { } braces . . . and have a consistent formatting style.
You are missing these . . .
before this line of code . . .
Thanks for that..
The code works now.. No compiling errors.
The only problem is that I can't get it to only trail when my trade almost has reached it's takeprofit.
The code right now trails right away and often gives me way lower profits because it's doesn't allow the trade to almost hit the take profit before it changes anything again.
The only problem is that I can't get it to only trail when my trade almost has reached it's takeprofit.
The code right now trails right away and often gives me way lower profits because it's doesn't allow the trade to almost hit the take profit before it changes anything again.
Hi YoungMoney,
The TrailStops functions trails the stoploss pip by pip if the stoplevel allows it, which is the "safer" way to trail the stop (Drawdowns are smaller).
The TrailStops functions trails the stoploss pip by pip if the stoplevel allows it, which is the "safer" way to trail the stop (Drawdowns are smaller).
What do you exactly want and why?
So If I understand it correctly if I set the "g_TrailingStop" to 30, Then:
-When the trade is 30 pips in profit the EA will move the stoploss to the bid/ask at the moment??
Say I open a BUY trade on 1.00000 bid
The Trailing Stop is Set to 100
Then when the bid moves to 1.00100, what happens?
Where wiill the EA move the stop level?
And will the take profit be the same as when I first started the trade?
Wouldn't also the TakeProfit on the trade make problems for the EA since it may close the trade before the trend is over?
Thank you for taking time to help me, flaab! Really appreciated ;)
So If I understand it correctly if I set the "g_TrailingStop" to 30, Then:
-When the trade is 30 pips in profit the EA will move the stoploss to the bid/ask at the moment??
Say I open a BUY trade on 1.00000 bid
The Trailing Stop is Set to 100
Then when the bid moves to 1.00100, what happens?
Where wiill the EA move the stop level?
And will the take profit be the same as when I first started the trade?
Wouldn't also the TakeProfit on the trade make problems for the EA since it may close the trade before the trend is over?
Thank you for taking time to help me, flaab! Really appreciated ;)
Mh... Here is what they mean:
The g_StopLoss variable is the amount of pips for the trailing stop.
The GreedyTrailing variable determines if the stoploss can be trailed below the opening price.
So, if GreedyTrailing is enabled, the stoploss is trailed very aggresively. For instance:
Buy EURUSD at 1.2810
Price rallies 5pips to 1.2815
The Stoploss is trailed to 1.2815 - g_StopLoss (Even if it is placed below the opening price)
If GreedyTrailing is disabled, the stoploss can only be trailed once the new value is above the opening price. For instance:
Buy EURUSD at 1.2810
Price rallies 20pips to 1.2830
The stoploss is not trailed, because the new stop would be below the opening price yet
Price rallies a bit more to 1.2850
Now the stoploss is trailed because the new stop is above the opening price
You should adjust the g_StopLoss and the GreedyTrailing parameter to meet your strategy. As a short recipe, you would normally...
Enable GreedyTrailing if you do not have a determined take profit level
Disable GreedyTrailing if you have a determind take profit level (Or enable it with a wide value)
If you want a more complex evaluation of the profits, you could use the OrderProfit() function to do something more custom, like halving your position, moving the stoploss to the opening price and so forth.
This code seems to have some problems with stopping trades correctly. The trade is in profit and it still does not move the stop loss line to the chosen amount of pips away from BID/ASK.
Below I have 2 screenshots of a situation like that. If the code had done the correct thing, that trade would be in big profit.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
That should help..
I of course have code for the EA which checks the signals too, but I doubt there is something wrong with that code since that worked good before I put the TrailingStop in.
Thanks for your help, RaptorUK.
You need to learn to count and check your { } braces . . . and have a consistent formatting style.
You are missing these . . .
before this line of code . . .
double GetDecimalPip()You need to learn to count and check your { } braces . . . and have a consistent formatting style.
You are missing these . . .
before this line of code . . .
Thanks for that..
The code works now.. No compiling errors.
The only problem is that I can't get it to only trail when my trade almost has reached it's takeprofit.
The code right now trails right away and often gives me way lower profits because it's doesn't allow the trade to almost hit the take profit before it changes anything again.
Thanks for that..
The code works now.. No compiling errors.
The only problem is that I can't get it to only trail when my trade almost has reached it's takeprofit.
The code right now trails right away and often gives me way lower profits because it's doesn't allow the trade to almost hit the take profit before it changes anything again.
Hi YoungMoney,
The TrailStops functions trails the stoploss pip by pip if the stoplevel allows it, which is the "safer" way to trail the stop (Drawdowns are smaller).
What do you exactly want and why?
Hi YoungMoney,
The TrailStops functions trails the stoploss pip by pip if the stoplevel allows it, which is the "safer" way to trail the stop (Drawdowns are smaller).
What do you exactly want and why?
So If I understand it correctly if I set the "g_TrailingStop" to 30, Then:
-When the trade is 30 pips in profit the EA will move the stoploss to the bid/ask at the moment??
So If I understand it correctly if I set the "g_TrailingStop" to 30, Then:
-When the trade is 30 pips in profit the EA will move the stoploss to the bid/ask at the moment??
Mh... Here is what they mean:
So, if GreedyTrailing is enabled, the stoploss is trailed very aggresively. For instance:
If GreedyTrailing is disabled, the stoploss can only be trailed once the new value is above the opening price. For instance:
You should adjust the g_StopLoss and the GreedyTrailing parameter to meet your strategy. As a short recipe, you would normally...
If you want a more complex evaluation of the profits, you could use the OrderProfit() function to do something more custom, like halving your position, moving the stoploss to the opening price and so forth.
Flaab, thanks for your help.
This code seems to have some problems with stopping trades correctly. The trade is in profit and it still does not move the stop loss line to the chosen amount of pips away from BID/ASK.
Below I have 2 screenshots of a situation like that. If the code had done the correct thing, that trade would be in big profit.
I hope you understand the situation.
Here are my EA options:
StopLoss = 140
TakeProfit = Do not Use
TrailingStop = true
GreedTrailing = false
g-TrailingStop = 100