Candle Indication - page 3

 
That doesnt help, I would need to know the Mql4 program LOGIC process first before any examples would help.
 
if(Close[i+1]-Close[i]>=2) 
      {BearEntry[i]=Close[i+1];}

This will never be true. The pip value has to be converted to a double.

Only have to alter four lines of the second example I provided.

double pipToDouble;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BuyBuffer);
   SetIndexBuffer(1,SellBuffer);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   SetIndexArrow(0,159);
   SetIndexArrow(1,159);
   pipToDouble=Point*10;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   int begin=rates_total-prev_calculated;
   if(prev_calculated==0)
      begin=rates_total-3;
//---
   for(int i=begin;i>=0 && !_StopFlag;i--)
     { 
      if((close[i]  -close[i+1]>=4*pipToDouble) || 
         (close[i+1]-close[i+2]>=2*pipToDouble))
         BuyBuffer[i]=low[i];
      else
         BuyBuffer[i]=0.0;
//---
      if((close[i+1]-close[i]  >=4*pipToDouble) || 
         (close[i+2]-close[i+1]>=2*pipToDouble))
         SellBuffer[i]=high[i];
      else
         SellBuffer[i]=0.0;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

Hi, thanks for your input, I did consider this problem however at this early stage I am only testing the code on the UK100 & NASDAQ both are trading around the 7500 mark.

So if Close[i+1] was 7483.8 and Close[i] was 7481.2

if(Close[i+1]-Close[i]>=2)

Would result in (2.6) or integer 2 which confirms the direction the market is moving and by how much?

Your revision would allow the code to run on any index, which would eventually be needed.

The problem I am trying to resolve is so simple everyone assumes 'it goes without saying...'

If the above IF statement is correct I need to move on to another IF statement and then to another etc. What I dont need is all IF statements completing every tick regardless of any logic path!

 

For multiple if statements either nest them or use && instead of ||. To only check for a condition on a new bar and not on every tick, add a flag before the loop.(I'm not sure if that is what you meant with the last sentence.)

//---
   if(rates_total!=prev_calculated)
     {
//---
      int begin=rates_total-prev_calculated+1;
      if(prev_calculated==0)
         begin=rates_total-3;
      for(int i=begin;i>0 && !_StopFlag;i--)
        { 
         if(close[i+1]-close[i+2]>=2*pipToDouble)
            if(close[i]-close[i+1]>=4*pipToDouble)
               BuyBuffer[i]=low[i];
            else
               BuyBuffer[i]=0.0;
   //---
         if(close[i+2]-close[i+1]>=2*pipToDouble &&
            close[i+1]-close[i]  >=4*pipToDouble)
            SellBuffer[i]=high[i];
         else
            SellBuffer[i]=0.0;
        }
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
I think nesting is what I was looking for, I need to ask a series of questions and only have an action if all are true. Will need to find out more but cannot find anything useful about flag.
 
Bostock58: I think nesting is what I was looking for, I need to ask a series of questions and only have an action if all are true. Will need to find out more but cannot find anything useful about flag.
What do you mean by flag? Are you referring to a boolean "bool"?
 
Fernando Carreiro:
What do you mean by flag? Are you referring to a boolean "bool"?

"add a flag before the loop." was a suggestion from Ernst.

I have been trying to find a full explanation for the function of { } type brackets as there is literally nothing in MQL4 Resource about them. I dont know if the have a specific name but its difficult to Google "{ }"

 
Bostock58:

"add a flag before the loop." was a suggestion from Ernst.

I have been trying to find a full explanation for the function of { } type brackets as there is literally nothing in MQL4 Resource about them. I dont know if the have a specific name but its difficult to Google "{ }"

It's called the compound operator. https://www.mql5.com/en/docs/basis/operators/compound

The flag (bool) is this part:

if(rates_total!=prev_calculated)

It will only look for signals on the second and third bars once a new bar is formed, and not on every tick. 

Documentation on MQL5: Language Basics / Operators / Compound Operator
Documentation on MQL5: Language Basics / Operators / Compound Operator
  • www.mql5.com
Language Basics / Operators / Compound Operator - Reference on algorithmic/automated trading language for MetaTrader 5
 

Unfortunately the 'compound operator' description only tells me that an 'if' statement is followed by a function in brackets, which I already knew.

I can see how the (rates_total!=prev_calculated) would work I will look to incorporate it, if I ever find a way to add a (true, false) logic path beyond one question.

 
I would have thought this was really simple coding problem to solve and yet I can find nothing on how it could be done...?
Reason: