Help Please How to Use Value of One Indicator in Another

To add comments, please log in or register
mp21
74
mp21  
I'm no coder but like to play around and learn a bit.  How can I make the Example indicator only display when it is above or below the FastTMALine indicator (see attachment).  The Example indicator doesn't actually do anything, I just want to learn how to display it based on the value of another indicator.  Any help would be greatly appreciated.
Files:
Chart.PNG 23 kb
Example.mq4 5 kb
Naguisa Unada
524
Naguisa Unada  
//+------------------------------------------------------------------+
//|                                                                  |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property strict
#property indicator_chart_window

// The number of buffers for calculation, up to 8
#property indicator_buffers 2

// The color for displaying arrows
#property indicator_color1 clrLimeGreen       // Long signal
#property indicator_color2 clrRed        // Short signal

// Width of the arrows
#property indicator_width1 1  // Long signal arrow
#property indicator_width2 1  // Short signal arrow
/*
extern int ArrowDistance = 0;
extern bool WaitForCandleClose = true;
extern bool ArrowOnTriggerBar = false;
extern int Arrow = 117;
*/
//extern int MarkMinuteGMT = 0;



// Buffers for the calculations
double Up_Arrow_Buffer[];    // Long buffer for display
double Down_Arrow_Buffer[];   // Short buffer for display
/*
int SignalIndex = 0;
int ArrowOffset = 0;
*/
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   /*if (WaitForCandleClose)
   {
      SignalIndex = 1;
   }
   else
   {
      SignalIndex = 0;
   }
   if (ArrowOnTriggerBar)
   {
      ArrowOffset = 0;
   }
   else
   {
      ArrowOffset = 0;
   }*/
// SetIndexStyle  - sets the new type, style, width and color for a given indicator line
// SetIndexBuffer - binds the array variable declared at a global level to the custom indicator pre-defined buffer
// SetIndexArrow  - sets an arrow symbol for indicators line of the DRAW_ARROW type.
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexBuffer(0, Up_Arrow_Buffer);
   SetIndexArrow(0, 117); // Up arrow
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexBuffer(1, Down_Arrow_Buffer);
   SetIndexArrow(1, 117); // Down arrow
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int i;                           // Bar index
   int Counted_bars;                // Number of counted bars
//--------------------------------------------------------------------
   Counted_bars = IndicatorCounted(); // Number of counted bars
   i = Bars - Counted_bars;     // Index of the first uncounted
   if (Counted_bars == 0)
      i = Bars - 100;

   while (i >= 0)
   {
      double upper_line = iCustom(NULL, PERIOD_CURRENT, "FastTMALine__1", 1, i);
      double lower_line = iCustom(NULL, PERIOD_CURRENT, "FastTMALine__1", 2, i);

      if (Close[i] > upper_line)
         Up_Arrow_Buffer[i] = High[i];

      if (Close[i] < lower_line)
         Down_Arrow_Buffer[i] = Low[i];

      i--;
   }
   /*
   if (i == 0)
   {
      i = 2;  // the newest signal bar is suppose to be at index 2
   }
   while(i >= SignalIndex)                    // Loop for uncounted bars
   {
      if (isUpSwingBar(i))
      {
         Up_Arrow_Buffer[i - ArrowOffset] = Close[i - ArrowOffset]; // - (ArrowDistance * Point);
         Down_Arrow_Buffer[i - ArrowOffset] = EMPTY_VALUE;
      }
      else if (isDownSwingBar(i))
      {
         Down_Arrow_Buffer[i - ArrowOffset] = Close[i - ArrowOffset]; // + (ArrowDistance * Point);
         Up_Arrow_Buffer[i - ArrowOffset] = EMPTY_VALUE;
      }
      else
      {
         Up_Arrow_Buffer[i - ArrowOffset] = EMPTY_VALUE;
         Down_Arrow_Buffer[i - ArrowOffset] = EMPTY_VALUE;
      }
      i--;
   }*/

//----
   return(0);
}
/*
bool isUpSwingBar(int i)
{
//&& TimeMinute(Time[i])==MarkMinuteGMT)
   {

      if(true)
      {
         return (true);
      }
      return (false);
   }
}

bool isDownSwingBar(int i)
{

   {

      if(true)
      {
         return (true);
      }
      return (false);
//
   }
}

*/
//+------------------------------------------------------------------+


It may be "FastTMALine" instead of "FastTMALine__1" on your PC. If so, correct it.

mp21
74
mp21  
Naguisa Unada:
It may be "FastTMALine" instead of "FastTMALine__1" on your PC. If so, correct it.

Thanks mate, that's fantastic!! Really appreciate that.

mp21
74
mp21  
Naguisa Unada:


It may be "FastTMALine" instead of "FastTMALine__1" on your PC. If so, correct it.

Hi Naguisa,  

I'm now struggling to add an alert to this.  When I do it just constantly alerts and it's in the loop.  Do you know how I could add an alert that just runs once?

Thanks

Mark

William Roeder
20207
William Roeder  
mp21: Do you know how I could add an alert that just runs once?
You are looking at a signal. Act on a change of signal.
          MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum #1
Naguisa Unada
524
Naguisa Unada  
Look at this sample.
Files:
mp21
74
mp21  

Thanks, William

mp21
74
mp21  
Naguisa Unada:
Look at this sample.

Thanks, Naguisa, that'll come in very handy for other things.  Just one final thing, the code in your first reply doesn't wait for the bar to close, is there a quick fix for that?

William Roeder
20207
William Roeder  
mp21: eply doesn't wait for the bar to close, is there a quick fix for that?
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
          New candle - MQL4 programming forum
mp21
74
mp21  
William Roeder:
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
          New candle - MQL4 programming forum

Thanks again, William.  

Naguisa, ignore my last comment about the signal appearing before the bar closes.

To add comments, please log in or register