[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 595
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
Installed MetaTrader 4, opened a demo account. Tried to open/close orders. How can I now make the terminal itself trigger a sell order when the price goes up and a buy order when it goes down, using information like "you need a 2 candle difference to close the old order and open a new one"?
Good evening. Question: When I close part of a trade, the EA kind of opens a new trade with a new ticket. Does the magik of the new order remain the same?
Yes
CAN SOMEONE EXPLAIN WHY ALL TRADES ARE ONLY ON BUY? I have no trades on SELL, the flag indicator before if() on SELL is always 1 for some reason, WHY???? is long&short in settings.
I ALSO WANT TO ASK WHY I LET MY EA MISSES SOME POSITIONS THAT I COULD OPEN? I CAN'T GO IN!
Here is the code(declaration of variables is truncated):
double upfr,dnfr=0.0;//levels of the last fractals
int flag=0;
int start() //open on the fractal break and close after s candles
{
if(iFractals(Symbol(),PERIOD_H1,MODE_UPPER,4)!=0)
{
upfr=iFractals(Symbol(),PERIOD_H1,MODE_UPPER,4);
}
if(iFractals(Symbol(),PERIOD_H1,MODE_UPPER,4)==0)
{
upfr=0;
}
if(iFractals(Symbol(),PERIOD_H1,MODE_LOWER,4)!=0)
{
dnfr=iFractals(Symbol(),PERIOD_H1,MODE_LOWER,4);
}
if(iFractals(Symbol(),PERIOD_H1,MODE_LOWER,4)==0)
{
dnfr=0;
}
//OPEN ORDERS BY PROBIT
H=iHigh(Symbol(),PERIOD_H1,1);
L=iLow(Symbol(),PERIOD_H1,1);
tOpen=iTime(Symbol(),PERIOD_H1,1);
if(H>upfr && flag==0) //if the fractal is up and the fractal level is exceeded
{
tClose=tOpen+s*stime*60;
OrderSend(Symbol(),OP_BUY,lots,Ask,slippage,NULL,NULL);
flag=1;
}
if(L<dnfr)
Print(L," -L dnfr- ",dnfr," flag- ",flag);
if(L<dnfr && flag==0)//if the fractal is down and the fractal level is down
{
tClose=tOpen+s*stime*60;
OrderSend(Symbol(),OP_SELL,lots,Bid,slippage,NULL,NULL);
flag=1;
}
// CLOSE ORDERS BY END OF TIME
if(Time[1]>=tClose && flag==1)// if the designated time has passed
{
Print("CLOSE FUNCTION");
OrClose();
flag=0;
upfr=0;
dnfr=0;
}
return(0);
}
Stumbled across this...
When deleting an EA, it has to delete pending orders
There are two variants
1. It just deletes everything...
int deinit()
{
int i;
//----
for(i=OrdersTotal()-1; i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS))
{
if (OrderType() == OP_BUYSTOP)
{
OrderDelete(OrderTicket());
}
if (OrderType() == OP_SELLSTOP)
{
OrderDelete(OrderTicket());
}
}
}
//----
return(0);
}
2. Selectively...
int deinit()
{
OrderSelect(ticket1,SELECT_BY_TICKET,MODE_TRADES);
OrderDelete(ticket1);
OrderSelect(ticket2,SELECT_BY_TICKET,MODE_TRADES);
OrderDelete(ticket2);
return(0);
}
Now, the catch is that on the demo, it works fine in both cases... But in real life... only one pending lot is removed for some reason... Question - who knows why?
Stumbled across this...
When deleting an EA, it has to delete pending orders
There are two variants
1. It just deletes everything...
int deinit()
{
int i;
//----
for(i=OrdersTotal()-1; i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS))
{
if (OrderType() == OP_BUYSTOP)
{
OrderDelete(OrderTicket());
}
if (OrderType() == OP_SELLSTOP)
{
OrderDelete(OrderTicket());
}
}
}
//----
return(0);
}
2. Selectively...
int deinit()
{
OrderSelect(ticket1,SELECT_BY_TICKET,MODE_TRADES);
OrderDelete(ticket1);
OrderSelect(ticket2,SELECT_BY_TICKET,MODE_TRADES);
OrderDelete(ticket2);
return(0);
}
Now, the catch is that on the demo, it works fine in both cases... But in real life... only one pending lot is removed for some reason... The question - who knows why?
IMHO "does not have enough time":
The run time of a special function deinit() is limited to 2.5 seconds. If the code of a special function deinit() is executed for longer than the specified time, the client terminal will forcefully terminate special function deinit() and the program as a whole.
IMHO "not in time":
The special function deinit() has an execution time of 2.5 seconds. If the code in the special deinit() function runs longer than this time, the client terminal will forcibly terminate the special deinit() function and the program as a whole.
:(
I.e. there is no hope? Roughly speaking, we start with using the script to close the pending orders... And then we close the owl... Nice auto-trading...
One more question - the assistant has set the pendants https://forum.mql4.com/ru/42300/page588
When I change timeframe, the orders are deleted for some reason...
:(
So there's no hope? Roughly speaking, we start with a script to close the pendants...and then we close the owl... Nice auto-trading...
One more question - the assistant has set the pendants https://forum.mql4.com/ru/42300/page588
When you change timeframe, the orders are deleted for some reason...
Either the script or some other way to command the EA to terminate its operation (e.g., via a global variable)
timeframe change = restart of Expert Advisor
either a script, or some other way to command the EA to terminate (e.g., through a global variable)
timeframe change = restart of Expert Advisor
Hmm... no way around the timeframe change?