It's overly simplified on purpose..only 1 trade being made on GBP/USD, just for testing purposes. This part should close 1 lot when price goes up 11 pips on buy or down 11 pips on sell.
RefreshRates();
if (IsConnected() && IsTradeAllowed()) while (IsTradeContextBusy()) Sleep(75);
if (OrdersTotal()>0) {OrderSelect(0, SELECT_BY_POS,MODE_TRADES);
if (Ask >= (OrderOpenPrice()+ (.0011)) && OrderLots() == 2 && (OrderType() == OP_BUY)) {
OrderClose(OrderTicket(),1,Ask,10,Red); }
if (Bid <= (OrderOpenPrice()- (.0011)) && OrderLots() == 2 && (OrderType() == OP_SELL)) {
OrderClose(OrderTicket(),1,Bid,10,Blue); }}
This part should Close BUY, if there is one then immediately open a Sell.
if ( ) {
RefreshRates();
if (IsConnected() && IsTradeAllowed()) while (IsTradeContextBusy()) Sleep(75);
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if (OrdersTotal() > 0 && OrderType()==OP_BUY) {OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");}
Sleep(500);
RefreshRates();
if (IsConnected() && IsTradeAllowed()) while (IsTradeContextBusy()) Sleep(75);
if (OrdersTotal() ==0) Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 10, 0, 0, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
if (IsConnected() && IsTradeAllowed()) while (IsTradeContextBusy()) Sleep(75);
if(Ticket<0)Print("OrderSend failed with error #",GetLastError());
return(0);
}
I run the visual mode backtesting and it opens buys and sells like crazy, should only have 1 open in either direction at a time.
I've read the help files but have been staring at it too long so I'm missing something obvious.
This is really Very simple code and I'm sure one of you will be able to spot what the heck I'm doing wrong.
APPRECIATE IT
RefreshRates();
if (IsConnected() && IsTradeAllowed()) while (IsTradeContextBusy()) Sleep(75);
if (OrdersTotal()>0) {OrderSelect(0, SELECT_BY_POS,MODE_TRADES);
if (Ask >= (OrderOpenPrice()+ (.0011)) && OrderLots() == 2 && (OrderType() == OP_BUY)) {
OrderClose(OrderTicket(),1,Ask,10,Red); }
if (Bid <= (OrderOpenPrice()- (.0011)) && OrderLots() == 2 && (OrderType() == OP_SELL)) {
OrderClose(OrderTicket(),1,Bid,10,Blue); }}
This part should Close BUY, if there is one then immediately open a Sell.
if ( ) {
RefreshRates();
if (IsConnected() && IsTradeAllowed()) while (IsTradeContextBusy()) Sleep(75);
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if (OrdersTotal() > 0 && OrderType()==OP_BUY) {OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");}
Sleep(500);
RefreshRates();
if (IsConnected() && IsTradeAllowed()) while (IsTradeContextBusy()) Sleep(75);
if (OrdersTotal() ==0) Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 10, 0, 0, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
if (IsConnected() && IsTradeAllowed()) while (IsTradeContextBusy()) Sleep(75);
if(Ticket<0)Print("OrderSend failed with error #",GetLastError());
return(0);
}
I run the visual mode backtesting and it opens buys and sells like crazy, should only have 1 open in either direction at a time.
I've read the help files but have been staring at it too long so I'm missing something obvious.
This is really Very simple code and I'm sure one of you will be able to spot what the heck I'm doing wrong.
APPRECIATE IT
taking series 3 and 34