Download MetaTrader 5
To add comments, please log in or register
What are the latest MQL5.community news? The Wall section will tell you!
Trew
10
Trew 2011.09.16 01:10 

I started picking up mql5 on the weekend and have started creating a few EAs, none of them based on a strategy I'd use, but just to get used to the language itself.

The EA puts in instant orders on the currency with a lot size of 0.1.
If the trend continues I want the EA to be able to purchase additional lots with a lot size of 0.1.

HOWEVER. . . . . 

 I have been trying to create the EA so that the maximum number of lots that any position can consist of is 0.5.

To do this I add the following statement inside an IF statement just before the code that executes the order

 PositionGetDouble(POSITION_VOLUME)<0.5) 

 

It works fine . . . . .  but once the position has closed regardless of it closing from stop loss, take profit or manual close, the EA will then no longer open any other positions.

Is there additional code that I need to add to the EA that will reset it?

Thanks

Also, if any terminology in this is wrong, please feel free to correct me. I've only had my demo account for about a month so I'm still at the bottom of the learning curve. 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Position Properties - Documentation on MQL5
Jimmy
490
Jimmy 2011.09.16 05:27  
Trew:

To do this I add the following statement inside an IF statement just before the code that executes the order

 PositionGetDouble(POSITION_VOLUME)<0.5) 

 

It works fine . . . . .  but once the position has closed regardless of it closing from stop loss, take profit or manual close, the EA will then no longer open any other positions.

Is there additional code that I need to add to the EA that will reset it?

Did you call and check
PositionSelect(symbol)
before calling PositionGetDouble() ?
Trew
10
Trew 2011.09.16 16:33  
fireflies:
Did you call and check
PositionSelect(symbol)
before calling PositionGetDouble() ?
No I didn't. Thanks, it works as intended now :)
/
To add comments, please log in or register