Because you don't check crossover but just the position of SignalMA. If you want to check crossover you should compare the previous position with the current position.
Any suggestions? How can I make the EA differentiate between position of SIGNALMA and SIGNALMA crossover?
Petr Nosek: OrderClosePrice() returns close price. If you close the order for example at 1.23000 the OrderClosePrice() will return 1.23000. If the order is still open the OrderClosePrice() returns 0.0 . Similar to OrderCloseTime()
I was told that ClosePrice if the order stills running will return the price that would close at if it's closed at that moment
OK, but you never use "Pips" in your code behind the block.
Yep, I just noticed that I posted a draft version, later this day I'll update with the actual "final" code before modifying anything upon the suggestions as I want to learn more about why it's bad before making any changes so I can learn more:D
If the expression is true, operator1 is executed and control is given to the operator that follows operator2 (operator2 is not executed). If the expression is false, operator2 is executed.
You should use Magic Number, because you can recognize by Magic Number what EA has opened the Order. Usually you don't want to close Orders opened by another EA.
FernandoBorea: Yep, I just noticed that I posted a draft version, later this day I'll update with the actual "final" code before modifying anything upon the suggestions as I want to learn more about why it's bad before making any changes so I can learn more:D
Is there any reason for using Pips? I don't think so.
Petr Nosek: OrderClosePrice() returns close price. If you close the order for example at 1.23000 the OrderClosePrice() will return 1.23000. If the order is still open the OrderClosePrice() returns 0.0 . Similar to OrderCloseTime()
That's not exact. OrderClosePrice() returns the bid/ask and it's best practice to use it with OrderClose().
Static/global variables are initialized once, on program load, with a constant. Your variables are bogus and never change. Drop the static.
Petr Nosek: you can't close the order by using OrderClosePrice() (returned value is zero, because the order is still open). You have to use Ask or Bid.
FernandoBorea: Could you please explain me the difference between using (!res) and then else? What does " ! " Do?
You should be able to read your code out loud and have it make sense. You would
never write if( (2+2 == 4) == true) would you?
if(2+2 == 4) is sufficient. So don't write
if(bool == true), just use if(bool) or
if(!bool). Code becomes self documenting when you use meaningful
variable names, like bool isLongEnabled where as Long_Entry sounds
like a trigger price or a ticket number and "if long entry" is an incomplete
sentence.
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.
Because you don't check crossover but just the position of SignalMA. If you want to check crossover you should compare the previous position with the current position.
OrderClosePrice() returns close price. If you close the order for example at 1.23000 the OrderClosePrice() will return 1.23000. If the order is still open the OrderClosePrice() returns 0.0 . Similar to OrderCloseTime()
OK, but you never use "Pips" in your code behind the block.
! is a negation.
https://www.mql5.com/en/docs/basis/operators/if
I was told that ClosePrice if the order stills running will return the price that would close at if it's closed at that moment
You should want your money back :D
https://docs.mql4.com/trading/ordercloseprice
Any suggestions? How can I make the EA differentiate between position of SIGNALMA and SIGNALMA crossover?
For example:
What's the Magic Number for?
You should use Magic Number, because you can recognize by Magic Number what EA has opened the Order. Usually you don't want to close Orders opened by another EA.
Yep, I just noticed that I posted a draft version, later this day I'll update with the actual "final" code before modifying anything upon the suggestions as I want to learn more about why it's bad before making any changes so I can learn more:D
OrderClosePrice() returns close price. If you close the order for example at 1.23000 the OrderClosePrice() will return 1.23000. If the order is still open the OrderClosePrice() returns 0.0 . Similar to OrderCloseTime()
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon.
www.mql5.com/en/forum/158890/page3#comment_3812636
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum
How to manage JPY pairs with parameters? - MQL4 and MetaTrader 4 - MQL4 programming forum
Slippage defined in index points - Currency Pairs - Expert Advisors and Automated Trading - MQL5 programming forum