static int iBuyTicket=-1; static bool Tradeopen = false; | EA's must be coded to recover. If the power fails, OS crashes, terminal or chart is accidentally closed, on the next tick, any static/global ticket variables will have been lost. You will have an open order but don't know it, so the EA will never try to close it, trail SL, etc. How are you going to recover? Use a OrderSelect loop to recover, or persistent storage (GV+flush/file) of ticket numbers required. |
double dPipValue=(dPrice1-dPrice2)/Point; | There is Tick, PIP, and Point. They are all different in general. A tick is the smallest change of price. A Point is the least significant digit quoted. In currencies a pip is defined as 0.0001 (or for JPY 0.01) On a 4 digit broker a point (0.0001) = pip (0.0001). [JPY 0.01 == 0.01] On a 5 digit broker a point (0.00001) = 1/10 pip (0.00010/10). Just because you quote an extra digit doesn't change the value of a pip. (0.0001 == 0.00010) EA's must adjust pips to points (for mq4.) In currencies a tick is a point. Price can change by least significant digit (1.23456 -> 1.23457) In metals a Tick is still the smallest change but is larger than a point. If price can change from 123.25 to 123.50, you have a TickSize of 0.25 and a point of 0.01. Pip has no meaning. This is why you don't use TickValue by itself. Only as a ratio with TickSize. See DeltaValuePerLot() |
if (OrderSelect( iBuyTicket, SELECT_BY_TICKET)==True) { if ( OrderClose(iBuyTicket,Lots,Bid,Slippage)==True) | 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. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence. |
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. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence. |
hello,
somehow OT but I have a different opinion here; by using NOT i am almost sure you are basically make compilation slower. The compiler will make such a code that it gets the return value from the called function and compares against true (or false) in order to decide if the "if" will be executed or not. What you are proposing is that the compiler, sometimes, will first fetch the return value, then will NOT it and after all that it will compare; so you are puttin one more task in the compiler
if(aBool == true) | That results in a second compare. compare the variable to the constant and generate a boolean. Then the if compares the boolean. |
Mccallum28: I am trying to simply open a position when the indicator signals long, if there is no position open.
static bool Tradeopen = false; : if (ArrowUp!=EMPTY_VALUE && Tradeopen!=false) { iBuyTicket=OrderSend(Symbol(),OP_BUY,Lots, Ask, Slippage, 0, 0, | Your if is never true. |
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I am trying to learn to code an EA starting with the basics using icustom and opening a position.
I am trying to simply open a position when the indicator signals long, if there is no position open. If there is to ignore.
I know this is very basic but if someone could help me with the basic construct it would be great. Thanks you.