Candle Indication

 

Hi All

I am in the process of turning my trading system into an EA on mql4. I have written a candle indicator that the EA will use, the problem is my entry is on subsequent candles, either the next one to signal or the one after. I and looking for suggestions of how to look at 1st & 2nd candles AFTER indicator candle...?

This is on the 5min timeframe.

I have tried many searches but cant really think of what to search for!?

 

Bostock58:

my entry is on subsequent candles, either the next one to signal or the one after. I and looking for suggestions of how to look at 1st & 2nd candles AFTER indicator candle...?

One way is to detect your signal two bars ago instead of on the current bar.

So,

time(0) = current bar

time(1) = penultimate bar

time(2) is two bars ago      <-- detect here

Detect your signal on time(2), and now you can "look at" the 1st and second bars AFTER the signal bar as time(1) and time(0).

 

Hi

The problem is that means I have to wait 10min before entry when I could have entered within 3-4 min if I was monitoring the live price. As you will apreciate on a 5min chart, getting into & out of trades as quickly as possible is critical to any success.

Ideally I need an " OnNewCandle" command!
 
I dont know how this post has ended up in the General Section, I am sure I put it in the Expert Advisor & Auto Trader Section, can Moderation move it please.
 
Bostock58:

Hi All

I am in the process of turning my trading system into an EA on mql4. I have written a candle indicator that the EA will use, the problem is my entry is on subsequent candles, either the next one to signal or the one after. I and looking for suggestions of how to look at 1st & 2nd candles AFTER indicator candle...?

This is on the 5min timeframe.

I have tried many searches but cant really think of what to search for!?

Bostock58:

Hi

The problem is that means I have to wait 10min before entry when I could have entered within 3-4 min if I was monitoring the live price. As you will apreciate on a 5min chart, getting into & out of trades as quickly as possible is critical to any success.

Ideally I need an " OnNewCandle" command!

Hi,

Maybe I can simplify the problem, by changing the logic structure of your program.

That is for each new candle, your EA start to check 1-2 candles behind to find out candle signal.
If the last 2 candles meet the entry requirements and
if there was a candle that has indicated a candle signal before, then ..
you may start open position on current candle.

good luck 

 
The problem is that means I have to wait 10min before entry when I could have entered within 3-4 min if I was monitoring the live price.

From your description, it seemed like your strategy needs a signal bar and a confirmation bar.

You said, "my entry is on subsequent candles, either the next one to signal or the one after."

If the idea of looking back two bars (10 minutes) offends you, then look back one bar (5 minutes). Or do both (look back both 1 and 2 bars back) for every new bar that comes in.
Ideally I need an " OnNewCandle" command!

Search for IsNewBar on this forum.
 
Yohana Parmi:

Hi,

Maybe I can simplify the problem, by changing the logic structure of your program.

That is for each new candle, your EA start to check 1-2 candles behind to find out candle signal.
If the last 2 candles meet the entry requirements and
if there was a candle that has indicated a candle signal before, then ..
you may start open position on current candle.

good luck 

Yes you are correct and I tried to do that by adding to the signal indicator and put a star at the entry point. Unfortunately I ended up with either a star on the signal candle or a star on nearly every candle!
 
Anthony Garot:

From your description, it seemed like your strategy needs a signal bar and a confirmation bar.

You said, "my entry is on subsequent candles, either the next one to signal or the one after."

If the idea of looking back two bars (10 minutes) offends you, then look back one bar (5 minutes). Or do both (look back both 1 and 2 bars back) for every new bar that comes in.

Search for IsNewBar on this forum.
I'm on it...
 
Bostock58:
Yes you are correct and I tried to do that by adding to the signal indicator and put a star at the entry point. Unfortunately I ended up with either a star on the signal candle or a star on nearly every candle!
//+------------------------------------------------------------------+
//| 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=!prev_calculated?rates_total-4:rates_total-prev_calculated;
   for(int i=begin;i>=0 && !_StopFlag;i--)
      SupBuffer[i]=(low[i+2]>low[i+1] && low[i+1]<low[i]) || 
                   (low[i+3]>low[i+2] && low[i+2]<low[i+1])?low[i]:0.0;
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


 
Thanks for the script suggestion Ernst, my programing skills arnt great so I am trying to understand its function logic to work out how it could be used. I also dont know how you produced that graph?
 
Bostock58:
Thanks for the script suggestion Ernst, my programing skills arnt great so I am trying to understand its function logic to work out how it could be used. I also dont know how you produced that graph?

I used the MQL wizard to create a custom indicator. Here's one without the ternary operator.

#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Sup
#property indicator_label1  "Sup"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Res
#property indicator_label2  "Res"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- indicator buffers
double         BuyBuffer[];
double         SellBuffer[];
//+------------------------------------------------------------------+
//| 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);
//---
   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-4;
//---
   for(int i=begin;i>=0 && !_StopFlag;i--)
     { 
      if((low[i+2]>low[i+1] && low[i+1]<low[i]) || 
         (low[i+3]>low[i+2] && low[i+2]<low[i+1]))
         BuyBuffer[i]=low[i];
      else
         BuyBuffer[i]=0.0;
//---
      if((high[i+2]<high[i+1] && high[i+1]>high[i]) || 
         (high[i+3]<high[i+2] && high[i+2]>high[i+1]))
         SellBuffer[i]=high[i];
      else
         SellBuffer[i]=0.0;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
Reason: