התחל במצב לא מקוון עם האפליקציה Player FM !
MQL4 TUTORIAL BASICS – 113 SIMPLE SELL PERCENTAGE RISK
סדרה בארכיון ("עדכון לא פעיל" status)
When? This feed was archived on December 18, 2021 00:33 (). Last successful fetch was on October 24, 2021 04:05 ()
Why? עדכון לא פעיל status. השרתים שלנו לא הצליחו לאחזר פודקאסט חוקי לזמן ממושך.
What now? You might be able to find a more up-to-date version using the search function. This series will no longer be checked for updates. If you believe this to be in error, please check if the publisher's feed link below is valid and contact support to request the feed be restored or if you have any other concerns about this.
Manage episode 297622157 series 1615247
[This post contains video, click to play]
In this video, we are creating an Expert Advisor for Sell positions, that makes it possible to use user defined Stop Loss value. So let’s find out how to do that with MQL4. To get started, please click on a little icon here or press F4 on your keyboard. Now you should see the Metaeditor window. And here you want to click on file, new file Expert Advisor from template, continue. I will call this file simple sell percentage risk. Click on Continue, continue and finish. Now you can delete everything above the Ontick function and the two Comment lines here, we start by creating an input variable.
If you mark that and press F1, you will see that input variables can be changed by the user from the program properties window without the need to recompile the code. The start value for our trading risk percentage is zero point five. That is one half of a percent. We also need another variable called max position loss. That is the maximal value that we are going to accept as a loss. Inside of the ontick function we need to check if we already have open positions.
So we use the function OrdersTotal. And if that returns a return value that is below one, it would mean that we have no open orders and no open positions. And if that is true, we are going to send a test sell order by using Ordersend for the current symbol on the chart. We want to sell 10 Microlot. Actually, we could also use the new syntax here, because when you mark that and press F1, you will see that you can also use _symbol. We don’t use a defined Stop Loss value here. The Take Profit is 20 points below the current Bid price. Please remember, this is just a test sell order. You wouldn’t do that on a real account. But as we need to close positions, we first need to have open positions. And actually that’s where demo accounts are good for. On your account, you could have more than one open position. So we are going to use a for loop here to go through all the open orders.
Now we can use orderselect for the current counter value and try to select a position. If that is successful, we will calculate the position profit by using order profit. We calculate the max position loss by getting the current account balance divided through one hundred, that would be one percent. And that will be multiplied with the percentage risk value that we have defined here. And if you wonder what that part here is about, well, the max position loss is a negative value.
Therefore, we use this expression to calculate the negative value. Let’s add two print statements here. The first one is for the position profit. The second one is for the max position loss. And we will see the output in our journal. And if the position profit is below the max position loss value that we have allowed. Remember, this is a negative value – we will use order close for the current order ticket and the current order lot size to close the current order.
Let’s close the orderselect the For loop and to see what’s going on, I would like to add a comment statement for the current balance, the current max position loss and the percentage risk value directly on our chart. And that’s about it. Well, if this was too fast for you or if you have no idea what all the code here does, maybe you want to watch one of the other videos from the basic video series first, or maybe even the Premium Course on our website might be interesting for you.
That’s also where you can find offers to download source codes like this one. But for now, please click on the Compile button here or press F7 on your keyboard. You shouldn’t get any errors. And if that is the case, you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader, please click on View, Strategy tester or press Control and R. Please pick the new file Simple sell percentage risk dot EX4.
Mark, the option for the Visual mode here and start your test, here we are. This is our first position. Now let’s click onto the journal tab. And here we see the values for the position profit. And as soon as the loss is higher than the allowed value, we should see that the position is closed. That happened right now. So our little Expert Advisor is working as expected. And in this little video, you have learned how to create an Expert Advisor that allows user defined values to close sell positions.
And you have coded it yourself with a few lines of MQL4 code.

Not sure what to do? Click on the automated trading assistant below

- MQL4 TUTORIAL BASICS - 27 HOW TO CODE A SIMPLE SELL… In this video, we want to create a trailing stop…
- MQL4 TUTORIAL BASICS - 118 SIMPLE LAST ORDER TYPE In this video we are going to create an…
- MQL4 TUTORIAL BASICS - 63 SIMPLE CHECK FOR NEW BARS In this video we are going to create an expert…
- MQL4 TUTORIAL BASICS - 109 SIMPLE FRACTALS EXPERT ADVISOR In this video, we are going to create an…
- MQL4 TUTORIAL BASICS - 67 SIMPLE VERTICAL LINE In this video we are going to create an expert…
- MQL4 TUTORIAL BASICS - 16 HOW TO PLACE A SELL LIMIT In this video we are going to set a pending…
- MQL4 TUTORIAL BASICS - 105 SIMPLE SELL GRID SYSTEM In this video, we are going to create a…
- MQL4 TUTORIAL BASICS - 29 HOW TO COUNT THE OPEN SELL… In this video we want to find out how to…
- MQL4 TUTORIAL BASICS - 60 SIMPLE DYNAMIC SELL POSITION SIZE In this video we are going to create an expert…
- MQL4 TUTORIAL BASICS - 112 SIMPLE BUY PERCENTAGE RISK In this video, we are going to create an…

The post MQL4 TUTORIAL BASICS – 113 SIMPLE SELL PERCENTAGE RISK appeared first on MQL4TUTORIAL.COM.
32 פרקים
סדרה בארכיון ("עדכון לא פעיל" status)
When? This feed was archived on December 18, 2021 00:33 (). Last successful fetch was on October 24, 2021 04:05 ()
Why? עדכון לא פעיל status. השרתים שלנו לא הצליחו לאחזר פודקאסט חוקי לזמן ממושך.
What now? You might be able to find a more up-to-date version using the search function. This series will no longer be checked for updates. If you believe this to be in error, please check if the publisher's feed link below is valid and contact support to request the feed be restored or if you have any other concerns about this.
Manage episode 297622157 series 1615247
[This post contains video, click to play]
In this video, we are creating an Expert Advisor for Sell positions, that makes it possible to use user defined Stop Loss value. So let’s find out how to do that with MQL4. To get started, please click on a little icon here or press F4 on your keyboard. Now you should see the Metaeditor window. And here you want to click on file, new file Expert Advisor from template, continue. I will call this file simple sell percentage risk. Click on Continue, continue and finish. Now you can delete everything above the Ontick function and the two Comment lines here, we start by creating an input variable.
If you mark that and press F1, you will see that input variables can be changed by the user from the program properties window without the need to recompile the code. The start value for our trading risk percentage is zero point five. That is one half of a percent. We also need another variable called max position loss. That is the maximal value that we are going to accept as a loss. Inside of the ontick function we need to check if we already have open positions.
So we use the function OrdersTotal. And if that returns a return value that is below one, it would mean that we have no open orders and no open positions. And if that is true, we are going to send a test sell order by using Ordersend for the current symbol on the chart. We want to sell 10 Microlot. Actually, we could also use the new syntax here, because when you mark that and press F1, you will see that you can also use _symbol. We don’t use a defined Stop Loss value here. The Take Profit is 20 points below the current Bid price. Please remember, this is just a test sell order. You wouldn’t do that on a real account. But as we need to close positions, we first need to have open positions. And actually that’s where demo accounts are good for. On your account, you could have more than one open position. So we are going to use a for loop here to go through all the open orders.
Now we can use orderselect for the current counter value and try to select a position. If that is successful, we will calculate the position profit by using order profit. We calculate the max position loss by getting the current account balance divided through one hundred, that would be one percent. And that will be multiplied with the percentage risk value that we have defined here. And if you wonder what that part here is about, well, the max position loss is a negative value.
Therefore, we use this expression to calculate the negative value. Let’s add two print statements here. The first one is for the position profit. The second one is for the max position loss. And we will see the output in our journal. And if the position profit is below the max position loss value that we have allowed. Remember, this is a negative value – we will use order close for the current order ticket and the current order lot size to close the current order.
Let’s close the orderselect the For loop and to see what’s going on, I would like to add a comment statement for the current balance, the current max position loss and the percentage risk value directly on our chart. And that’s about it. Well, if this was too fast for you or if you have no idea what all the code here does, maybe you want to watch one of the other videos from the basic video series first, or maybe even the Premium Course on our website might be interesting for you.
That’s also where you can find offers to download source codes like this one. But for now, please click on the Compile button here or press F7 on your keyboard. You shouldn’t get any errors. And if that is the case, you can click on a little button here or press F4 to go back to Metatrader. And in Metatrader, please click on View, Strategy tester or press Control and R. Please pick the new file Simple sell percentage risk dot EX4.
Mark, the option for the Visual mode here and start your test, here we are. This is our first position. Now let’s click onto the journal tab. And here we see the values for the position profit. And as soon as the loss is higher than the allowed value, we should see that the position is closed. That happened right now. So our little Expert Advisor is working as expected. And in this little video, you have learned how to create an Expert Advisor that allows user defined values to close sell positions.
And you have coded it yourself with a few lines of MQL4 code.

Not sure what to do? Click on the automated trading assistant below

- MQL4 TUTORIAL BASICS - 27 HOW TO CODE A SIMPLE SELL… In this video, we want to create a trailing stop…
- MQL4 TUTORIAL BASICS - 118 SIMPLE LAST ORDER TYPE In this video we are going to create an…
- MQL4 TUTORIAL BASICS - 63 SIMPLE CHECK FOR NEW BARS In this video we are going to create an expert…
- MQL4 TUTORIAL BASICS - 109 SIMPLE FRACTALS EXPERT ADVISOR In this video, we are going to create an…
- MQL4 TUTORIAL BASICS - 67 SIMPLE VERTICAL LINE In this video we are going to create an expert…
- MQL4 TUTORIAL BASICS - 16 HOW TO PLACE A SELL LIMIT In this video we are going to set a pending…
- MQL4 TUTORIAL BASICS - 105 SIMPLE SELL GRID SYSTEM In this video, we are going to create a…
- MQL4 TUTORIAL BASICS - 29 HOW TO COUNT THE OPEN SELL… In this video we want to find out how to…
- MQL4 TUTORIAL BASICS - 60 SIMPLE DYNAMIC SELL POSITION SIZE In this video we are going to create an expert…
- MQL4 TUTORIAL BASICS - 112 SIMPLE BUY PERCENTAGE RISK In this video, we are going to create an…

The post MQL4 TUTORIAL BASICS – 113 SIMPLE SELL PERCENTAGE RISK appeared first on MQL4TUTORIAL.COM.
32 פרקים
All episodes
×ברוכים הבאים אל Player FM!
Player FM סורק את האינטרנט עבור פודקאסטים באיכות גבוהה בשבילכם כדי שתהנו מהם כרגע. זה יישום הפודקאסט הטוב ביותר והוא עובד על אנדרואיד, iPhone ואינטרנט. הירשמו לסנכרון מנויים במכשירים שונים.