How to take value from indicator to strategy

Hallo experts,

Question is how to take value from custom indicator to strategy ?

I build indicator with some signals and put it in with iCustom(…); It works fine but :confused:

Is some solution how to export that bool variables to strategy ?

here is part from indicator :

bool SetBuy   = false; <-- this value
bool SetSell  = false; <-- this
bool SetCross = false; <-- and this

int OnCalculate (const int rates_total,
                 const int prev_calculated,
                 const int begin,
                 const double& price[] )
{
   for (int i=(int)MathMax(prev_calculated-1,0); i<rates_total; i++)
   {
      MA_Value[i] = iMajster(price[i],Length,i,0);
      if (i>0)
      {
         colorBuffer[i] = 2;
            if (MA_Value[i] >  MA_Value[i-1])
              {
               SetBuy   =  true;    <-------- here it changes from true to false
               SetSell  =  false;   <--------
               colorBuffer[i]=0;
              }
            if (MA_Value[i] <  MA_Value[i-1])
              {
               SetSell  =  true;    <--------  
               SetBuy   =  false;   <--------
               colorBuffer[i]=1;
              }
            if (MA_Value[i] == MA_Value[i-1])
              {
               SetCross =  true;    <--------
                
               SetBuy   =  false;   <--------
               SetSell  =  false;   <--------
               colorBuffer[i]=2;
              }
      }
   }      
   return(rates_total);
}

In general, you send buffers (arrays) from an indicator to an EA (strategy).

In your case, it would probably be simpler and more logical to calculate these three boolean values within the EA itself from the MA_Value[] buffer — which you can easily send to the EA via iCustom().

Ok I try to create array and put variables in like this :

//////////////////////////////////////////// global

int SetCross       = 0;
int SetBuy         = 0;
int SetSell        = 0;

//

double SetArray [];

//////////////////////////////////////////// OnInit

int OnInit()
{
   SetIndexBuffer(0,MA_Value,INDICATOR_DATA); PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,3);
   SetIndexBuffer(1,colorBuffer,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(2,SetArray,INDICATOR_CALCULATIONS);  <-------------------------------------------------
   IndicatorSetString(INDICATOR_SHORTNAME,"Majster ("+string(Length)+")");
   return(0);
}

//////////////////////////////////////////// Calculate

int OnCalculate (const int rates_total,
                 const int prev_calculated,
                 const int begin,
                 const double& price[] )
{
   for (int i=(int)MathMax(prev_calculated-1,0); i<rates_total; i++)
   {

      SetArray[0] = SetCross; <-------------------------------------------------------
      SetArray[1] = SetBuy;   <-------------------------------------------------------
      SetArray[2] = SetSell;  <-------------------------------------------------------
      
      MA_Value[i] = iMajster(price[i],Length,i,0);
      if (i>0)
      {
................................ bla bla bla

but now how to take that values in strategy

///////////////////////////////// global

double MA_Custom_Array [];
double MA_Custom_Signals []; <-----

double MA_Custom()
{
   int    MA_Custom_Define = iCustom (_Symbol, _Period, "Majster");
   
       ArraySetAsSeries (MA_Custom_Array, true);
       CopyBuffer (MA_Custom_Define,0,0,1,MA_Custom_Array);

       CopyBuffer (MA_Custom_Define,2,0,0,MA_Custom_Signals); <--------

   double MA_Custom_Value = MA_Custom_Array[0];
   return MA_Custom_Value;
}

/////////////////////////////// init

void OnInit ()
{
 MA_Custom();
}

If I use in strategy another CopyBuffer how to define wich one I need and how to put it into global variables … my mind is on fire

I dont understand what I do wrong.

In comment from indicator is OK. Signal changes from 1.0 means (Sell) or 0.0 (Buy)

34

But comment from strategy is NOT OK.

35

Indicator Code:

////////////////////////////////////////// global

double setarray [];    // define array
int    setvar  = 0;    // define signal value

////////////////////////////////////////// oninit

SetIndexBuffer(4,setarray);  // set array to buffer

////////////////////////////////////////// oncalculate

   ArraySetAsSeries (setarray, true);
   setarray[0] = setvar;                 // write signal number to array ( 0 or 1 )

   Comment ("value = ",setarray[0]);

Expert code:

////////////////////////// global

double Majster_Signal_Array [];

////////////////////////// on tick

    Comment ("value = ",Majster_Signal_Array[0]);

////////////////////////// indicator

double Majster()
{
   double Majster_Value_Array  []; 
   
   int    Majster_Definition = iCustom (_Symbol, _Period, "Majster");
       

       ArraySetAsSeries (Majster_Value_Array, true);
       ArraySetAsSeries (Majster_Signal_Array, true);

       CopyBuffer (Majster_Definition, 0, 0, 1,Majster_Value_Array);
       CopyBuffer (Majster_Definition, 4, 0, 1, Majster_Signal_Array);
       
   
   // return
   double Majster_Return = Majster_Value_Array[0];
   return Majster_Return;

Please help.

////////////////////////// on tick

    Comment ("value = ", Majster());

////////////////////////// indicator

double Majster()
{
   double Majster_Value_Array[]; 
   int Majster_Definition = iCustom (_Symbol, _Period, "Majster");
   ArraySetAsSeries (Majster_Value_Array, true);
   CopyBuffer (Majster_Definition, 0, 0, 1,Majster_Value_Array);

       // check for errors here...

   return Majster_Value_Array[0];
}

Your indicator buffer doesn’t seem to be set As Series.