What is the easiest/best way to keep my EA from opening positions until all of the cash is being used in trading? Currently I have an EA that is composed of 2 EMA's that places a trade based on the direction of the 2 indicators. If the conditions are being met, my EA continues to open up new positions until all buying power has been used and then it generates the insufficient funds message in the logs. I am a novice programmer and want to have the code written in my EA as opposed to using an outside function or class so that I can follow the code as I learn this.
I have tried variations of code after "&&" but the orders are still being placed until there is no buying power. Can I use the method below with modifications or am I going about this wrong?
if(SmoothedBuffer1[1]>SmoothedBuffer2[1] && PositionGetDouble(POSITION_VOLUME) <= LotSize);
{
trReq.price=tick.ask; // SymbolInfoDouble(NULL,SYMBOL_ASK);
trReq.sl=tick.ask-_Point*sl; // Stop Loss level of the order
trReq.tp=tick.ask+_Point*tp; // Take Profit level of the order
trReq.type=ORDER_TYPE_BUY; // Order type
OrderSend(trReq,trRez);
}
//If TEMAF < TEMAS -> SELL
if(SmoothedBuffer1[1]<SmoothedBuffer2[1] && PositionGetDouble(POSITION_VOLUME) <= LotSize);
{
trReq.price=tick.bid;
trReq.sl=tick.bid+_Point*sl; // Stop Loss level of the order
trReq.tp=tick.bid-_Point*tp; // Take Profit level of the order
trReq.type=ORDER_TYPE_SELL; // Order type
OrderSend(trReq,trRez);
}
I have tried variations of code after "&&" but the orders are still being placed until there is no buying power. Can I use the method below with modifications or am I going about this wrong?
if(SmoothedBuffer1[1]>SmoothedBuffer2[1] && PositionGetDouble(POSITION_VOLUME) <= LotSize);
{
trReq.price=tick.ask; // SymbolInfoDouble(NULL,SYMBOL_ASK);
trReq.sl=tick.ask-_Point*sl; // Stop Loss level of the order
trReq.tp=tick.ask+_Point*tp; // Take Profit level of the order
trReq.type=ORDER_TYPE_BUY; // Order type
OrderSend(trReq,trRez);
}
//If TEMAF < TEMAS -> SELL
if(SmoothedBuffer1[1]<SmoothedBuffer2[1] && PositionGetDouble(POSITION_VOLUME) <= LotSize);
{
trReq.price=tick.bid;
trReq.sl=tick.bid+_Point*sl; // Stop Loss level of the order
trReq.tp=tick.bid-_Point*tp; // Take Profit level of the order
trReq.type=ORDER_TYPE_SELL; // Order type
OrderSend(trReq,trRez);
}
First, I'd use brackets for complex conditions. Like this:
if((SmoothedBuffer1[1]>SmoothedBuffer2[1]) && (PositionGetDouble(POSITION_VOLUME) <= LotSize));
Second, did you select the position before calling PositionGetDouble(POSITION_VOLUME)?
Third, is LotSize comparable to position's volume?
It's all hard to understand from the piece of code you've inserted.
![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
What is the easiest/best way to keep my EA from opening positions until all of the cash is being used in trading? Currently I have an EA that is composed of 2 EMA's that places a trade based on the direction of the 2 indicators. If the conditions are being met, my EA continues to open up new positions until all buying power has been used and then it generates the insufficient funds message in the logs. I am a novice programmer and want to have the code written in my EA as opposed to using an outside function or class so that I can follow the code as I learn this.