static int lastSignal=-1;
if(BuySignal && lastSignal!=OP_BUY)
{
//Place Buy order
lastSignal=OP_BUY;
}
if(SellSignal && lastSignal!=OP_SELL)
{
//Place Sell order
lastSignal=OP_SELL;
}
If you don't understand the above, you will need to learn the basics of MQL4.
Using an EA generator produces low quality and very basic code.
Please use the SRC button when posting code in future. I have done it for you this time.
static int lastSignal=-1;
if(BuySignal && lastSignal!=OP_BUY)
{
//Place Buy order
lastSignal=OP_BUY;
}
if(SellSignal && lastSignal!=OP_SELL)
{
//Place Sell order
lastSignal=OP_SELL;
}
If you don't understand the above, you will need to learn the basics of MQL4.
Using an EA generator produces low quality and very basic code.
Thank you so much dear Keith Watford.
![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
Dear friends,
I am new in EA programming and i need your help please. I want my EA to wait after close last trade and don't open trade until next signal.
For example if my EA open last Sell trade then after close as TP or ST wait for BUY signal and don't open again Sell before get Buy signal.
if(Buy1_1 > Buy1_2 && Buy4_1 > Buy4_2 && Buy5_1 < Buy5_2) // Here is your open buy rule
{
result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(0);
}
if(Buy1_1 < Buy1_2 && Buy4_1 < Buy4_2 && Buy5_1 > Buy5_2) // Here is your open Sell rule
{
result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Red);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
OrderSelect(result,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
}
return(0);
}
}
for(int cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber
)
{