Download MetaTrader 5

Indicator only considering candles from time i open indicator

To add comments, please log in or register
Nathan0601
12
Nathan0601  

Hi, I can't figure out how to get the indicator to consider all the candles as opposed to only the ones which have come since i have opened the chart. 

 

I've got pretty simple code for example's sake, just working with the close prices:

 Any help really appreciated. Thanks

void OnTick()
  {
//---
     if (iClose(NULL,0, 1) > iClose(NULL, 0, 2))
  DrawArrowUp("Up" + Bars, Close[1]+10*Point, Blue);
  }

  void DrawArrowUp(string ArrowName,double LinePrice,color LineColor)
{
ObjectCreate(ArrowName, OBJ_ARROW, 0, Time[1], LinePrice); //draw an up arrow
ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(ArrowName, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
ObjectSet(ArrowName, OBJPROP_COLOR,LineColor);
}

void DrawArrowDown(string ArrowName,double LinePrice,color LineColor)
{
ObjectCreate(ArrowName, OBJ_ARROW, 0, Time[1], LinePrice); //draw an up arrow
ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(ArrowName, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
ObjectSet(ArrowName, OBJPROP_COLOR,LineColor);
Carl Schreiber
6689
Carl Schreiber  

??

1) OnTick() is for EAs not for indicators?

2) set a global var. (datetime) FromNow = TimeCurrent(); in init(); and then ignore if Time[i]<FromNow?

Nathan0601
12
Nathan0601  

The code is actually in the OnInit section, I was just experimenting and i guess i copied the wrong code here.

 2) I don't quite follow. Could you please elaborate?  

Carl Schreiber
6689
Carl Schreiber  

Set in OnInit() the 'time-line' FromNow.  And then you can use this timeline to determine whether th opening time of a candel is younger or older than the timeline.

But that is not the opening of the chart.

For the moment you open  chart (not applying your indicator at a chart) I can't even see any hint in the journal tab..

Nathan0601
12
Nathan0601  

I'd like to just set an arrow on candles which confirm to my indicator conditions. The code works but if im comparing two candles, the indicator does not work until  those 2 candles have finished after opening the chart. I'd like to see the previous instances where my conditions were met. 

 My entire code is as follows:

 

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
       if (iClose(NULL,0, 1) > iClose(NULL, 0, 2))
  DrawArrowUp("Up" + Bars, Close[1]+10*Point, Blue); 

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+

  void DrawArrowUp(string ArrowName,double LinePrice,color LineColor)
{
ObjectCreate(ArrowName, OBJ_ARROW, 0, Time[1], LinePrice); //draw an up arrow
ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(ArrowName, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
ObjectSet(ArrowName, OBJPROP_COLOR,LineColor);
}

void DrawArrowDown(string ArrowName,double LinePrice,color LineColor)
{
ObjectCreate(ArrowName, OBJ_ARROW, 0, Time[1], LinePrice); //draw an up arrow
ObjectSet(ArrowName, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(ArrowName, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
ObjectSet(ArrowName, OBJPROP_COLOR,LineColor);
}

Please bare with me as i'm new. 

To add comments, please log in or register