
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
Close only profitable positions
Code: Close Profitable Position.mq5
Forum on trading, automated trading systems and testing trading strategies
(MQL5) Close when position reaches a specified profit
Vladimir Karputov, 2020.11.08 06:17
***The EA checks the positions for all symbols and for all Magic Numbers.
Custom Moving Average as a resource
Code: Custom Moving Average as a resource.mq5
It is often asked: "If an Expert Advisor uses a custom indicator, how should you write the Expert Advisor code correctly to make the Expert Advisor work on the MQL5 VPS"?
The answer is this: the indicator must be created as a resource. See example below:
Please note: I moved the 'Custom Moving Average' indicator to the root folder 'Indicators'
I have compiled an indicator and an advisor. The EA attached it to the chart and carried out the migration. The result of working at the MQL5 VPS:
As you can see, everything works great!
Adding the 'iSAR' indicator to the chart
Code: iSAR ChartIndicatorAdd.mq5
Result:
We have a chart with two indicators: iMA in the main window and iMACD in the subwindow.
We launch our advisor:
and tab 'Experts':
If you switch the timeframe:
check: looks at all indicators
and tab 'Experts':
Why does a window, when hidden, return different parameters than when it is active?
The answer is simple - it's all about the Windows operating system. A window can have several states: the window is fully maximized, minimized, and minimized. When the window is inactive, it is in the minimized state (if you have not minimized it before). Let's check it out. We use the Bar number indicator - it numbers the bars and the service indicator 'CHART_FIRST_VISIBLE_BAR.mq5' - the indicator displays the value
CHART_FIRST_VISIBLE_BAR
The number of the first visible bar on the chart. Bar indexing matches timeseries .
int r / o
Here's what happens: first, the window is fully maximized, then the window is minimized, and after that we switch to another chart (which we fully maximize)
Hello Vladimir,
Thanks so much for your efforts with numerous codes and EA that have assisted several beginners in MQL5 programming like me understand the rudiments of coding MQL5 language.
Please I have this EA, copied and modified from some of your codes to suit my strategy, which is supposed to ensure that not more than 2 positions share similar lot sizes.
For instance, only One Sell and One Buy position can have same lot size i.e. for any particular lot size, only One Buy and One Sell position can be opened.
Furthermore, when last opened Buy position is in losses, it ought to Open a Sell with similar Lot size and vice versa.
The challenge encountered is that the EA hardly opens a Sell position even when last Buy position is in losses.
Try this code:
Try this code:
Thanks so much for your assistance. I tried the code as advised however I discovered that a maximum of 7 positions were opened within a year when backtested while for some other years only 2 positions opened. Kindly see the complete code below:
***
Thanks so much for your assistance. I tried the code as advised however I discovered that a maximum of 7 positions were opened within a year when backtested while for some other years only 2 positions opened. Kindly see the complete code below:
***
Please never insert the code as a sheet of text.
You need to do this: insert text using the button
and add the code using the button
...
Please never insert the code as a sheet of text.
You need to do this: insert text using the button and add the code using the button ...
Many thanks for the correction and apologies for that error. Kindly see the complete code, based on your advice, which opened a maximum of 7 positions within a year when backtested while for some other years only 2 positions were opened:
However, my initial code opened several positions yearly as expected but its problem was just that when the last opened Buy position is in losses it fails to open a sell position as intended. Kindly have a look at the code:
Kindly assist, thanks.