Show your code:
ubzen:
Show your code:
here is the code,
Actually, i need to Open position 1 time at 00.00 buy and sell and close all at 23.00
but the result is many times open position...
int start() { bool result; double price; int cmd,error; if(Hour() == 0 && Minute() == 1) int ticket1 = OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, Ask - 100*Point, Ask + 100 * Point,"",7152,Green); int ticket2 = OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, Bid + 100*Point, Ask - 100 * Point,"",7152,Red); if(Hour() == 23 && Minute() == 58){ if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)) { cmd=OrderType(); if(cmd==OP_BUY || cmd==OP_SELL) { while(true) { if(cmd==OP_BUY) price=Bid; else price=Ask; result=OrderClose(OrderTicket(),OrderLots(),price,3,CLR_NONE); if(result!=TRUE) { error=GetLastError(); Print("LastError = ",error); } else error=0; if(error==135) RefreshRates(); else break; } } } else Print( "Error when order select ", GetLastError()); } return(0); }
With every tick it will open a trade, so you need to check if you've already opened up a position in the last minute.
if(Hour() == 0 && Minute() == 1) { for(int i=OrdersTotal()-1;i>=0;i--) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){Print("Error selecting trade");return(0);} if(OrderMagicNumber()!=7152)continue; if(OrderSymbol()!=Symbol())continue; if(TimeCurrent()-OrderOpenTime()<65)return(0); // Orders opened within last minute } int ticket1 = OrderSend(Symbol(), OP_BUY, 0.1, Ask, 3, Ask - 100*Point, Ask + 100 * Point,"",7152,Green); int ticket2 = OrderSend(Symbol(), OP_SELL, 0.1, Bid, 3, Bid + 100*Point, Ask - 100 * Point,"",7152,Red); }
thks.. bro
your code is very helpful. .

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
i made script Open Position at 00:00 and close at 23:59, but it did not work
could you help me please . . .