You are asking too many questions in one sitting and expecting someone to explain it all to you in a few posts what took them years to learn and master. They could write an entire book just to explain everything you have asked.
Your questions also shows some lack of the basics of trading concepts. For example, with the following of your lines of text ...
current price = ask/bid or mid price of the symbol.
... There is no "mid" price on MetaTrader. There is a Ask price and a Bid price (and for some symbols, also a Last price).
- A "buy" position opens at the Ask price and closes at the Bid price.
- A "sell" position opens at the Bid price and closes at the Ask price.
Charts only shows the bars/candles based on Bid prices (Forex, CFDs, etc.) or Last prices (Futures, etc.).
As for the rest, if you need help with your code, then you will need to show your code, and ask for help with specific things not a generalised list of multiple questions. Be sensible!
Even at "zero" spread, that is a total waste of your money and destined to ruin your account. Learn the maths of Trading ...
Either go long (buy) or go short (sell) depending on the situation. Doing both on the same symbol, is the same as going nowhere except to pay twice the trading fees (spread, commission, etc.) and getting nothing else out of it.
PS! Your "ideal" strategy is simply not feasible in practice, because there are all manner of broker fees, be they the spread, commission, or others.
You are asking too many questions in one sitting and expecting someone to explain it all to you in a few posts what took them years to learn and master. They could write an entire book just to explain everything you have asked.
Your questions also shows some lack of the basics of trading concepts. For example, with the following of your lines of text ...
... There is no "mid" price on MetaTrader. There is a Ask price and a Bid price (and for some symbols, also a Last price).
- A "buy" position opens at the Ask price and closes at the Bid price.
- A "sell" position opens at the Bid price and closes at the Ask price.
Charts only shows the bars/candles based on Bid prices (Forex, CFDs, etc.) or Last prices (Futures, etc.).
As for the rest, if you need help with your code, then you will need to show your code, and ask for help with specific things not a generalised list of multiple questions. Be sensible!
Hi Fernando,
First of all, thank you for your response to my post.
Since the multiple questions I asked here are related, I wanted to share them in the same post. However, if it is against the written or unwritten rules of this forum, I will do my best not to repeat it again. If you want, I can open a separate post for each question.
I cannot agree with my lack of knowledge about basic trading concepts. Since the post would already be long enough, I avoided giving some details. What I meant by mid price was (ask + bid / 2). Yes, I know that this price has no value. I also know that no transaction takes place in the market at this price. However, I am currently trying to develop a rough version of the strategy that will only work on tester and demo accounts. Of course, this will not provide the desired solution on a real account.
However, it is also obvious that I have a lack of knowledge about MetaTrader and MQL. The last time I developed an indicator or strategy with the MQL language was 15-20 years ago. All of them worked with the closing of a bar in a certain period, they were not based on ticks. I am trying to refresh my knowledge as quickly as possible.
As for code sharing, since I developed the strategy for someone else, I cannot reveal his personal ideas here, but I can of course share code snippets related to the question I asked.
You said, "Be reasonable!" Since English is not my native language, I perceived it as an insult when I first read it, but I want to think that your intentions are not bad and I perceive it that way.
Even at "zero" spread, that is a total waste of your money and destined to ruin your account. Learn the maths of Trading ...
Either go long (buy) or go short (sell) depending on the situation. Doing both on the same symbol, is the same as going nowhere except to pay twice the trading fees (spread, commission, etc.) and getting nothing else out of it.
PS! Your "ideal" strategy is simply not feasible in practice, because there are all manner of broker fees, be they the spread, commission, or others.
There are no rules against it at all. It is just that the forum is more for simpler Q&A that can be handled in a simple fashion. Having a very complex multipoint query will be difficult to address and answer satisfactorily.
It is best to narrow things down to specific points that you are having difficult with, and address them progressively as you resolve them.
The Strategy Tester simulates the real-world environment of ask/bid prices. So, even if you use (ask + bid / 2) for calculations, positions will still respect the normal spread rules. And even if you set the spread to zero, you still have commission to content with. You may initially just want to use it in the Strategy Tester, but the whole point of creating a strategy, is because you want to have it work on a real-world live account at some point.
Countless traders have searched for the "holy-grail" by using same-symbol hedging, martingale and grid solutions. They all fail eventually. They are not feasible in the real world.
If your "customer" still wants to pursue this irrespective of the advice against it, then it is his and your prerogative. So, I will not say any more about it.
By "reasonable", I mean for you to break your query down into smaller parts and address each one step-by-step as you progress with your own research and experimentation as you code it.
For each point, you should try to research and implement it yourself, and then you come here when you have reached a wall or need some clarification, showing your code, your efforts, your testing results with log output of the debugging process. Then once solved, you move on to the next phase.
There are no rules against it at all. It is just that the forum is more for simpler Q&A that can be handled in a simple fashion. Having a very complex multipoint query will be difficult to address and answer satisfactorily.
It is best to narrow things down to specific points that you are having difficult with, and address them progressively as you resolve them.
The Strategy Tester simulates the real-world environment of ask/bid prices. So, even if you use (ask + bid / 2) for calculations, positions will still respect the normal spread rules. And even if you set the spread to zero, you still have commission to content with. You may initially just want to use it in the Strategy Tester, but the whole point of creating a strategy, is because you want to have it work on a real-world live account at some point.
Countless traders have searched for the "holy-grail" by using same-symbol hedging, martingale and grid solutions. They all fail eventually. They are not feasible in the real world.
If your "customer" still wants to pursue this irrespective of the advice against it, then it is his and your prerogative. So, I will not say any more about it.
By "reasonable", I mean for you to break your query down into smaller parts and address each one step-by-step as you progress with your own research and experimentation as you code it.
For each point, you should try to research and implement it yourself, and then you come here when you have reached a wall or need some clarification, showing your code, your efforts, your testing results with log output of the debugging process. Then once solved, you move on to the next phase.
Thank you for your ideas, opinions and advice. I appreciate your efforts to keep the forum organized.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use

- current price = ask,bid or mid price of the symbol.
- limit order price = current price (+) change value (pip/percent).
- Place BuyStop(BuyLotSize, limit order price) and SellLimit(SellLotSize, limit order price) orders.
- limit order price = current price (-) change value (pip/percent).
- Place SellStop(SellLotSize, limit order price) and BuyLimit(BuyLotSize, limit order price) orders.
- current price = ask/bid or mid price of the symbol.
- order price = current price (+) change value (pip/percent).
- If the price is greater than the order price, enter the loop and wait for all orders to be executed; place Buy(BuyLotSize) and Sell(SellLotSize) market orders.
- order price = current price (-) change value (pip/percent).
- If the price is greater than the order price, enter the loop and wait for all orders to be executed; place Buy(BuyLotSize) and Sell(SellLotSize) market orders.
- Define a global variable called lock
- At the beginning of the OnTick method, check the lock variable, if it is true return
- Otherwise set lock to true
- current price = ask/bid or mid price of the symbol.
- order price = current price (+) change value (pip/percent).
- If the price is greater than the order price, enter the loop and wait for all orders to be executed; place Buy(BuyLotSize) and Sell(SellLotSize) market orders.
- order price = current price (-) change value (pip/percent).
- If the price is greater than the order price, enter the loop and wait for all orders to be executed; place Buy(BuyLotSize) and Sell(SellLotSize) market orders.
- Just before exiting the OnTick method, set lock method to false
I tried to explain the strategy and problems as simply as I could. If there is anything unclear, please let me know and I will explain in more detail. I am waiting for your help and ideas.
Best Regards