What if there is currently no open trades?
Why you use the loop "for( j = 0; j >= 0; j-- )"?
What should be the value of OpenOrderTime() if no order selected?
What if there is currently no open trades?
Why you use the loop "for( j = 0; j >= 0; j-- )"?
i would like to no open 2 position at the same bar, if the EA opens one position, so don't open new position at the same bar.
Answer the questions to yourself and you'll find the problem.
Your problem is purely programming problem.
You can either ask somebody to code your EA for a fee. There are people in this forum offering such a service.
Or practice reading program logic reaaallllly carefullyyyy :)
Regards.
You see why it wouldn't work and open another trade the next minute is because you asked it to. if (TimeCurrent()-OrderOpenTime()>60), "60 = 60mins" I would set a little example below and try to explain the best i can given the medium; hopefully it should give you guys a better understanding. That's of course if i got what problem it is you're trying to tackle right.
The output of OrderOpenTime() is quite complex, as the program code would only see it as 'int' and you would need convert it to 'str' => TimeToStr() before you get the output in valued time. But then this would return the time in Year-month-day hour-min. So to answer your question on how you compare this in real time, you wouldn't / shouldn't bother about the time value, but the int value and the exact time frame that generated the entry signal or would generate an exit. See this:
// variable declaration
int orderTime = OrderOpenTime();
int timePlus = orderTime + ((60*timeFrame)*increment);
int currentTime = iTime(symbol, timeFrame, shift);
//final comparisons
if(orderTime == currentTime ) {
OrderClose( int ticket, double lots, double price, int slippage, color Color=CLR_NONE)
}
where: 60 = mins, timeFrame = SignalTimeFrame and increment = number of bars on that timeFrame from OrderOpenTime().
Example if your signal timeFrame is 15mins and you would want to close the trade in 120mins, you would have 120/15 = 8, so you would want to use '8' and you 'increment' that is 8 15mins candle from OrderOpenTime();
This should work for the task at hand. Hope you understand it. Happy Trading.
You see why it wouldn't work and open another trade the next minute is because you asked it to. if (TimeCurrent()-OrderOpenTime()>60), "60 = 60mins" I would set a little example below and try to explain the best i can given the medium; hopefully it should give you guys a better understanding. That's of course if i got what problem it is you're trying to tackle right.
Thread start date: 2007.06.21
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
//+------------------------------------------------------------------+
//| RPoint. mq4 |
//| Copyright © 2004, Poul_Trade_Forum |
//| Aborigen |
//| http://forex.kbpauk.ru/ |
//+------------------------------------------------------------------+
#property copyright "Poul Trade Forum"
#property link "http://forex.kbpauk.ru/"
//---- input parameters
extern int ReversPoint=50;
extern double TakeProfit = 25;
extern double Lots = 1;
extern double InitialStop = 20;
//---- buffers
int Trend,InTrend,ttime;
double Last_High, Last_Low;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted(),i,shift;
//---- TODO: add your code here
i=(Bars-counted_bars)-1;
for (shift=i; shift>=0;shift--)
{
if (Time[shift]!=ttime) InTrend=InTrend+1;
ttime=Time[shift];
if (High[shift+1]>Last_High && Trend==1) InTrend=1;
if (Low[shift+1]<Last_Low && Trend==0) InTrend=1;
if (High[shift+1]>Last_High) Last_High=High[shift+1];
if (Low[shift+1]<Last_Low) Last_Low=Low[shift+1];
if (Trend==1 && Low[shift+1]<Last_High-ReversPoint*Point && InTrend>1)
{
Trend=0;
Last_High=Low[shift+1];
Last_Low=Low[shift+1];
InTrend=1;
}
if (Trend==0 && High[shift+1]>Last_Low+ReversPoint*Point && InTrend>1)
{
Trend=1;
Last_Low=High[shift+1];
Last_High=High[shift+1];
InTrend=1;
}
//----
}
int j=OrdersTotal();
for(j=0;j>=0;j--)
OrderSelect(j, SELECT_BY_POS,MODE_TRADES);
if (TimeCurrent()-OrderOpenTime()>60)
{
if (Trend==1 && Low[shift+1]<Last_High-ReversPoint*Point && InTrend>1)
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-InitialStop*Point,Ask+TakeProfit*Point, NULL,0,0,Green);
}
{
if (Trend==0 && High[shift+1]>Last_Low+ReversPoint*Point && InTrend>1)
OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+InitialStop*Point,Bid-TakeProfit*Point, NULL,0,0,Green);
}
return(0);
}
//+------------------------------------------------------------------+
i can't understand why the line
if (TimeCurrent()-OrderOpenTime()>60)
it doesn't work at all and opens new position at the same minute?