Previous GlobalVariable or Indexbuffer from Indicator to EA

 
Hello,

On my indicator, I set a GlobalVariable for the trend.

When the trend is up, GlobalVariable is 1 and when the trend is down the GlobalVariable is -1

On my EA, I get the GlobalVariable, but I only succeeded to get the current GlobalVariable.

I would like to get previous GlobalVariable at Current (for example 13h00), 12h55, 12h50, 12h45; 12h40, 12h35 and 12h30 (for M5 period)

The purpose is to know if the trend continue with the same direction, and so if yes the EA buy or sell fonction of the direction.

I tried to use iCustom, but something went wrong...

Have you got any idea how to implement something to retreive variable or indexbuffer from Indicator to EA for my example above.

Thank you,
Have a nice day.
 

You can write in your EA Script some Global Variables and then read them from a indicator script, for that you just need the name from the Global Variable then you can read it from every indicator i Think.

example:

// build Global Variable in EA Script
 
if(GlobalVariableGet("g") != 0) GlobalVariableDel("g");
  Print( GlobalVariableSet("g",TimeCurrent()) );
 
 
// Read Globale Variable in indicator Script
if(GlobalVariableGet("g") != 0 )  Print( GlobalVariableGet("g") );

Now you can write for every bar like 12h55 12h50 ... a Globale Variable with a value and then read it.

Of corse in other direction it must be again possible, also to write Globale Variable in the indicator script and read it from the EA Script.

At the end from the script it is recomend to delete them, for example in the deinit() function.

 
Thank you Heino,

Very interesting solution, I will try and tell you if it is OK.

Have a nice day...
 
Heino,

I tested it like that.

In the Indicator :
  if ( GlobalVariableGet ( "current5" ) != 0 )
  {
    GlobalVariableDel ( "current5" ) ;
    GlobalVariableSet ( "current5" , GlobalVariableGet ( "current4" ) ) ;
  }
  
  if ( GlobalVariableGet ( "current4" ) != 0 )
  {
    GlobalVariableDel ( "current4" ) ;
    GlobalVariableSet ( "current4" , GlobalVariableGet ( "current3" ) ) ;
  }
  
  if ( GlobalVariableGet ( "current3" ) != 0 )
  {
    GlobalVariableDel ( "current3" ) ;
    GlobalVariableSet ( "current3" , GlobalVariableGet ( "current2" ) ) ;
  }
  
  if ( GlobalVariableGet ( "current2" ) != 0 )
  {
    GlobalVariableDel ( "current2" ) ;
    GlobalVariableSet ( "current2" , GlobalVariableGet ( "current1" ) ) ;
  }
  
  if ( GlobalVariableGet ( "current1" ) != 0 )
  {
    GlobalVariableDel ( "current1" ) ;
    GlobalVariableSet ( "current1" , GlobalVariableGet ( "current0" ) ) ;
  }
  
  if ( GlobalVariableGet ( "current0" ) != 0 )
  {
    GlobalVariableDel ( "current0" ) ;
    GlobalVariableSet ( "current0" , TimeCurrent ( ) ) ;
  }
And in the EA:
    int varGlobal0 = GlobalVariableGet ( "current0" ) ;
    int varGlobal1 = GlobalVariableGet ( "current1" ) ;
    int varGlobal2 = GlobalVariableGet ( "current2" ) ;
    int varGlobal3 = GlobalVariableGet ( "current3" ) ;
    int varGlobal4 = GlobalVariableGet ( "current4" ) ;
    int varGlobal5 = GlobalVariableGet ( "current5" ) ;
    
    Print ( "0: " + varGlobal0 + " /1: " + varGlobal1 + " /2: " + varGlobal2 + " /3: " + varGlobal3 + " /4: " + varGlobal4 + " /5: " + varGlobal5 ) ;

It works but there is a bug, for example when varGlobal0 is intialized, varGlobal1 has the same value.
In the second cycle varGlobal0 become varGlobal2 and varGlobal1 become varGlobal3 and so on.

There is always 2 variables with the same value from same variable.

That's why I would like to use iCustom, but if you have any idea how to optimize this code, it could be interesting.

thank you.