Help with coding

 

Hello,

 I currently have an EA that opens a max of 1 buy and 1 sell. It currently opens trades on bar-open only, however, at the moment it closes intrabar by using a set TP and SL.

I am looking at converting the system to a 100% bar open only system yet and confused about how to go about it. I understand the theory in that I need to select each order, and compare their pip profit vs the given TP and SL and if it exceeds or is equal to it close the trade at bar open.

I am new to coding in MQL5 and was wondering if anyone could help me with this and perhaps give me an example of how this would be completed. I tried looking at the documentation but it doesn't seem to be as clearly laid out as the MQL4 documentation.

 

Thanks for all the help,

David 

 
Tempestshade:

Hello,

 I currently have an EA that opens a max of 1 buy and 1 sell. It currently opens trades on bar-open only, however, at the moment it closes intrabar by using a set TP and SL.

I am looking at converting the system to a 100% bar open only system yet and confused about how to go about it. I understand the theory in that I need to select each order, and compare their pip profit vs the given TP and SL and if it exceeds or is equal to it close the trade at bar open.

I am new to coding in MQL5 and was wondering if anyone could help me with this and perhaps give me an example of how this would be completed. I tried looking at the documentation but it doesn't seem to be as clearly laid out as the MQL4 documentation.

 

Thanks for all the help,

David 

Hello David. Instead of Documentation, I think you should take a look at the Code Base?

There you can find several examples of how to implement any functionality inside Expert Advisors.

If you don't find anything interesting, maybe you could share parts of your code with us, so we could try to help you somehow.

 

Hello Malacarne,

 Thanks for the idea! I will definitely be checking it out.

As for sharing parts of my code; I don't have any part of the bar open only close system built because I have never attempted it before and am rather confused as to how to go about it. The little EA I am coding is based upon the guide https://www.mql5.com/en/articles/100 all I have done so far is change the entry settings/indicators a bit. Most of the code is pretty much the same.

Regardless I will check out the code base and hopefully there is something that helps me implement a bar open close system in the EA.

 

Thanks for the help,

David 

Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners
Step-By-Step Guide to writing an Expert Advisor in MQL5 for Beginners
  • 2010.06.09
  • Samuel
  • www.mql5.com
The Expert Advisors programming in MQL5 is simple, and you can learn it easy. In this step by step guide, you will see the basic steps required in writing a simple Expert Advisor based on a developed trading strategy. The structure of an Expert Advisor, the use of built-in technical indicators and trading functions, the details of the Debug mode and use of the Strategy Tester are presented.
 
Tempestshade:

Hello Malacarne,

 Thanks for the idea! I will definitely be checking it out.

As for sharing parts of my code; I don't have any part of the bar open only close system built because I have never attempted it before and am rather confused as to how to go about it. The little EA I am coding is based upon the guide https://www.mql5.com/en/articles/100 all I have done so far is change the entry settings/indicators a bit. Most of the code is pretty much the same.

Regardless I will check out the code base and hopefully there is something that helps me implement a bar open close system in the EA.

 

Thanks for the help,

David 

Great! Please tell us if you need anything else!
 

Hello Malacarne & All,

 

I spent a good 2 hours looking yesterday and have yet to find a piece of sample code, or a complete EA that operates solely on bar open for open and closing of trades. Perhaps I am not using correct terminology? Is anyone perhaps able to explain to me the process of what I need to do so I can go ahead and attempt coding it myself?

 

Cheers,

David 

 
Tempestshade:

Hello Malacarne & All,

 

I spent a good 2 hours looking yesterday and have yet to find a piece of sample code, or a complete EA that operates solely on bar open for open and closing of trades. Perhaps I am not using correct terminology? Is anyone perhaps able to explain to me the process of what I need to do so I can go ahead and attempt coding it myself?

 

Cheers,

David 

Hello David, then please take a look at the Articles Base. Try to search for "new bar event" and you'll find something interesting, IMO.

I believe you will find at least one interesting article and one interesting code.

I hope it helps you. 

 

Thank you Malacarne for the excellent resources!

 I should correct myself as I don't believe I explain myself properly. I already have code to check if it is a new bar which is neatly provided in the guide I used above. What I actually need help with is the trade function to check a trades profit in pips and then close it if it surpasses or is equal to my set SL and TP. 

 

What I am having trouble with is Selecting the trade, checking the trade, and then subsequently closing the trade if the parameters of the TP and SL are reached. And then repeating that again for any other open trades. I have never used a loop before in MT5/MT4 as I always tend to just work with set TP's and SL's.

 

Help is greatly appreciated.

 

Cheers,

David 

 
Tempestshade:

Thank you Malacarne for the excellent resources!

 I should correct myself as I don't believe I explain myself properly. I already have code to check if it is a new bar which is neatly provided in the guide I used above. What I actually need help with is the trade function to check a trades profit in pips and then close it if it surpasses or is equal to my set SL and TP. 

 

What I am having trouble with is Selecting the trade, checking the trade, and then subsequently closing the trade if the parameters of the TP and SL are reached. And then repeating that again for any other open trades. I have never used a loop before in MT5/MT4 as I always tend to just work with set TP's and SL's.

 

Help is greatly appreciated.

 

Cheers,

David 

If you show your coding attempts, we can try to help you.
 
Tempestshade:

Thank you Malacarne for the excellent resources!

 I should correct myself as I don't believe I explain myself properly. I already have code to check if it is a new bar which is neatly provided in the guide I used above. What I actually need help with is the trade function to check a trades profit in pips and then close it if it surpasses or is equal to my set SL and TP. 

 

What I am having trouble with is Selecting the trade, checking the trade, and then subsequently closing the trade if the parameters of the TP and SL are reached. And then repeating that again for any other open trades. I have never used a loop before in MT5/MT4 as I always tend to just work with set TP's and SL's.

 

Help is greatly appreciated.

 

Cheers,

David 

In order to check a trade's profit, I think you need to explore some MQL5 functions first, like PositionGetDouble and SymbolInfoDouble.

As Alain said, you could show us what you've done so far, so we could try to help you.

 

Hello,

I made a simple EA that sells every 10 pips and I set the price manually: if ((Bid == 1.3770) || (Bid == 1.3780) || (Bid == 1.3790) ... )

But I need an formula that selects automatically Bid price with last digit 0 (MT4 with 4 digit)

I know very little about programing and I got lost on Documentation, I don't know where and what to search


Thank you for your time

 
ovibi:

Hello,

I made a simple EA that sells every 10 pips and I set the price manually: if ((Bid == 1.3770) || (Bid == 1.3780) || (Bid == 1.3790) ... )

But I need an formula that selects automatically Bid price with last digit 0 (MT4 with 4 digit)

I know very little about programing and I got lost on Documentation, I don't know where and what to search


Thank you for your time

Forum on trading, automated trading systems and testing trading strategies

Hello,

This forum is about MT5/mql5, please post your question about MT4/mql4 on mql4.com forum.

  • They are more people who can answer there.
  • They are more people who can have similar problem there.
  • A forum is not only to get help but to share with the community, mql4/MT4 community isn't the same as mql5/MT5 community.