How do I place a new buy or sell order in code if conditions are met?
I've tried this, but no results:
if (mA - X <= Tick.ask && sellPositionIsOpen == false)
{
myRequest.type = ORDER_TYPE_SELL;
myRequest.price = Tick.ask;
trade.OrderSend(myRequest, myResult);
sellPositionIsOpen = true;
}
if (mA + X >= Tick.bid && buyPositionIsOpen == false)
{
myRequest.type = ORDER_TYPE_BUY;
myRequest.price = Tick.bid;
trade.OrderSend(myRequest, myResult);
buyPositionIsOpen = true;
}
I've also tried using OpenPosition, Buy and Sell. Nothing worked so far.
Hi,
Meantime you run the EA, check the contents of the Journal and Experts tab menu, and post here.
We will know the cause of the actual problem :)
just use the examples from the documentation: https://www.mql5.com/en/docs

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
How do I place a new buy or sell order in code if conditions are met?
I've tried this, but no results:
CTrade trade;
MqlTick Tick;
MqlTradeRequest myRequest;
MqlTradeResult myResult;
ZeroMemory(myResult);
myRequest.action = TRADE_ACTION_DEAL;
myRequest.type = ORDER_TYPE_BUY;
myRequest.symbol = _Symbol;
myRequest.volume = VOLUME;
myRequest.type_filling = ORDER_FILLING_FOK;
myRequest.price = 0;
myRequest.tp = TP;
myRequest.sl = SL;
bool buyPositionIsOpen = false;
bool sellPositionIsOpen = false;
int mA = iMA (_Symbol, Ma_timeframe, Ma_period, Ma_shift, Ma_method, AppliedPrice);
if (mA - X <= Tick.ask && sellPositionIsOpen == false)
{
myRequest.type = ORDER_TYPE_SELL;
myRequest.price = Tick.ask;
trade.OrderSend(myRequest, myResult);
sellPositionIsOpen = true;
}
if (mA + X >= Tick.bid && buyPositionIsOpen == false)
{
myRequest.type = ORDER_TYPE_BUY;
myRequest.price = Tick.bid;
trade.OrderSend(myRequest, myResult);
buyPositionIsOpen = true;
}
I've also tried using OpenPosition, Buy and Sell. Nothing worked so far.