How to have one signal per bar with current price as signal

 

https://www.mql5.com/en/forum/141967

int start()
{
static datetime currTime;if(currTime==Time[0])return;currTime=Time[0];
 //Get Signal
 //Trade
 

}

the above link show the example of time condition is used,but my ea used a signal based on current price, so it may continue to have signal, then no signal, then a signal in the same bar again,

how do i, to take the first signal only, and ignore all other signal of the same bar 

 
shenlongming:

https://www.mql5.com/en/forum/141967

}

the above link show the example of time condition is used,but my ea used a signal based on current price, so it may continue to have signal, then no signal, then a signal in the same bar again,

how do i, to take the first signal only, and ignore all other signal of the same bar 

 

When you have received the signal the first time set a bool to true,  when you check for a new bar also check if this bool is false . . .  so you can run your code if there is a new bar or the bool is false,  if there was a new bar set the bool to false.
 
shenlongming: my ea used a signal based on current price, so it may continue to have signal, then no signal, then a signal in the same bar again, how do i, to take the first signal only, and ignore all other signal of the same bar
bool isWaiting; void init(){ isWaiting = false; }
int start(){
   bool wasWaiting = isWaiting; isWaiting = false; // assume not.
   :
   if(OncePerBar) return;
   :
   isWaiting = !yourSignal;
   if(!isWaiting)  return; // not yet
   if(!wasWaiting) return; // previously triggered.
   // new trigger..
 

WHRoeder, I am learning a thing or two about programming from your example. But I am using something very simple to work once for each new bar. 

datetime CurrentTime;

int start()
{
   if (CurrentTime != Time[0])
   {
      CurrentTime = Time[0];

      ...get signal...
      ...do trade...

   } // end of if
} // end of start

 Does this solve the question?

 
No it doesn't. The OPs problem wasn't one per bar but avoiding re-triggering on a continuing signal.
 
//no trading after Open
int openbar_intervals=1;
int opentimedifference     =  (Time[0]-OrderOpenTime());
int opentimeintervals          =  (Period()*60*openbar_intervals);//1min=60
   {
   OrderSelect(lastorder,SELECT_BY_POS,MODE_HISTORY);
   if(opentimedifference>=opentimeintervals)
   enableopen  =  true;
   else if (opentimedifference<=opentimeintervals)
   enableopen  =  false;
   }

previously i code like this, what's wrong with it?it just totally dont work 

 
  1. You can NOT use OrderOpenTime() before a successful OrderSelect()
  2. No test for successful OrderSelect() What are Function return values ? How do I use them ? - MQL4 forum
  3. Your code only delays one bar, if there is still a open order. If the order has closed, no delay. Your question was about a continuing signal. Your code continues to open new orders on a continuing signal.
  4. Simply the code
    Your code
    Simpler
    if(opentimedifference>=opentimeintervals)
       enableopen  =  true;
    else if (opentimedifference<=opentimeintervals)
       enableopen  =  false;
    enableopen  = opentimedifference>=opentimeintervals;

 

a nice simplify, which i'm weak of, i got tons of the code alike, and my ea is a bit slow, lol

anyway, so, i cant use a orderopentime, then how do i check for the time?

 

tell me if my logic is wrong

first a signal, if position is open then bool nomoreopenonsamebar= true

then if time0>time,then nomoreopenonsamebar=false, then i can open position again?correct?

how to   time0>time??i dont know how to code this man, a little help here? 

Reason: