How to get Open[1] and Open[2] from offline chart...

 

Hello,

I need to get values for Open[1], Open[2], Close[1] and Close[2] from Offline chart, BUT my Expert Advisor is attached to 1 Minute chart. How to get it?

 
MINTA:

Hello,

I need to get values for Open[1], Open[2], Close[1] and Close[2] from Offline chart, BUT my Expert Advisor is attached to 1 Minute chart. How to get it?

Hi,
From a regular timeframe it seems simple by iOpen and iClose, but check history refreshing state.
From an irregular timeframe (like M3) I want to know it too, as I described earlier here: https://www.mql5.com/en/forum/138697
 
MINTA:

Hello,

I need to get values for Open[1], Open[2], Close[1] and Close[2] from Offline chart, BUT my Expert Advisor is attached to 1 Minute chart. How to get it?

I don't know . . . but I just found out.

I have some old offline charts . . . so I coded a little Indicator to help me find out how to get the Open, Close, High, Low values . . . I ran the Indicator on the offline chart and . . .

Print("Symbol name is: ", Symbol() );

. . gave me the Symbol name.

Once I had confirmed the symbol name I coded this . . .

   Print("Close Value of bar 49 = ", iClose("AUDUSD+10M", PERIOD_H1, BarNumber));
   
   Print("Open Value of bar 49 = ", iOpen("AUDUSD+10M", PERIOD_H1, BarNumber));

. . . and put the Indicator on a live chart, it agve me the correct values for the relevant bar from the offline chart.

Does that hep you ?

 

No. It seems more complicated with this indicator. I think it's easier to make an expert to put the global variable, and then by an expert who trades to take.

Example:

Expert 1 attached to offline chart:

//I do not know where to put this: is init() or start()

GlobalVariableSet(EURUSDFIRST, Close[1]);

then...

Expert 2 attached to 1 Minute chart:

double EURUSDFIRST;

//----

GlobalVariableGet( EURUSDFIRST);

Comment("EURUSD Close[1] is: ",EURUSDFIRST);

I have tried, but it does not get correct value?

 
MINTA:

I have tried, but it does not get correct value?

My code works . . . why don't you at least try it ?
 
MINTA:

//----

GlobalVariableGet( EURUSDFIRST);

Comment("EURUSD Close[1] is: ",EURUSDFIRST);

I have tried, but it does not get correct value?

This is wrong . . . try this . . .

// in Expert 1 on offline chart

GlobalVariableSet("EURUSDFIRST", Close[1]);

//  in Expert 2 on M1 chart

Comment("EURUSD Close[1] is: ", GlobalVariableGet( "EURUSDFIRST") );
 

THANK YOU RAPTORUK!!!

IT WORKS FINE.

REGARDS,

MINTA

 

One more thing ... Suppose that EA is attached to 1 Minute chart. It opens 1 only order per NEW bar, BUT it receives signals from 4 offline charts so my problem is how to open 1 only order when new bar is formed from every of 4 offline charts?

//+----------------------------------------------------------------------+
//|  It returns the sign of a new bar appearance for the given timeframe |
//+----------------------------------------------------------------------+
bool isNewBar(int timeFrame)
   {
   bool res=false;
   
   // the array contains open time of the current (zero) bar
   // for 7 (seven) timeframes
   static datetime _sTime[];  
   int i=0;
 

//----
   if (_sTime[i]==0 || _sTime[i]!=iTime(Symbol(),timeFrame,0))
      {
      _sTime[i] = iTime(Symbol(),timeFrame,0);
      res=true;
      }
      
//----
   return(res);   
   }
How to code it?

	          
 
You could get the code on the offline charts to update the GlobalVariable just on the first tick of the new 0 bar . . . the code on the M1 chart will read each of the GlobalVariables and when it has read them set them to some arbitrary value, for example 9999 . So when the code on the M1 char checks the GlobalVariables it only reacts when all the values are not 9999
 

Do not get it. How about this://I did not try it yet.//

if (_sTime[i]==0 || _sTime[i]!=iTime("EURUSD",timeFrame,0)|| _sTime[i]!=iTime("GBPUSD",timeFrame,0)|| _sTime[i]!=iTime("USDCHF",timeFrame,0))
      {
      _sTime[i] = iTime(NULL,timeFrame,0);
      res=true;
      }
      
//----
   return(res);   
   }
Just guess. :) I am not sure about this: iTime(NULL,timeFrame,0);
Reason: