Help with data from custom indicator - page 2

 
input long            chart_id=0;        // chart id
input ushort          custom_event_id=0; // event id

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,        // size of price[] array
                 const int prev_calculated,  // bars, calculated at the previous call
                 const int begin,            // starting index of data
                 const double& price[]       // array for the calculation
   )
  {
   double price_current=price[rates_total-1];

   //--- Initialization:
   if(prev_calculated==0) 
     { // Generate and send "Initialization" event
      EventChartCustom(chart_id,0,(long)_Period,price_current,_Symbol);
      return(rates_total);
     }
   
   // When the new tick, let's generate the "New tick" custom event
   // that can be processed by Expert Advisor or indicator
   
   EventChartCustom(chart_id,custom_event_id+2,(long)_Period,price_current,_Symbol);
   
   //--- return value of prev_calculated for next call
   return(rates_total);
  }
Fernando Carreiro #
:

Then, during the processing of events (OnTick, OnChart, etc.), you should read the current state of the "Algo Trading", and when it is off, you release the indicator handle.

And when it is on again, you will need to reinitialise the indicator handle. The best way, is probably to create a class object for the indicator so that you can initialise and release it on demand.

Here is some sample code to get the state of when trading is allowed or not during various situations ...

do i need to add this code to indicator ? there indicator code 

 
Fernando Carreiro #:

Then, during the processing of events (OnTick, OnChart, etc.), you should read the current state of the "Algo Trading", and when it is off, you release the indicator handle.

And when it is on again, you will need to reinitialise the indicator handle. The best way, is probably to create a class object for the indicator so that you can initialise and release it on demand via the object's methods.

Here is some sample code to get the state of when trading is allowed or not during various situations ...

If I don't misunderstand. For example, should the indicator be in such a way that it will not work when auto trading is turned off, so that the indicator will not be able to send an event?

 
rosen007 #: If I don't misunderstand. For example, should the indicator be in such a way that it will not work when auto trading is turned off, so that the indicator will not be able to send an event?
You can do it both ways. You can either have the indicator stop sending the custom events when "Algo Trading" is disabled or you can have the EA release and reinitialise the handles as needed.
 
Fernando Carreiro #:
You can do it both ways. You can either have the indicator stop sending the custom events when "Algo Trading" is disabled or you can have the EA release and reinitialise the handles as needed.
#property description "iSpy agent-indicator. If you want to get ticks, attach it to the chart"
#property indicator_chart_window

#property indicator_plots 0
input long            chart_id=0;        // chart id
input int          custom_event_id=0; // event id

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,        // size of price[] array
                 const int prev_calculated,  // bars, calculated at the previous call
                 const int begin,            // starting index of data
                 const double& price[]       // array for the calculation
   )
  {
   double price_current=price[rates_total-1];

   //--- Initialization:
   if(prev_calculated==0) 
     { // Generate and send "Initialization" event
     if (!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) ) // eğer auto trade acık deil ise eventleri gonderme
     {
      Print("autotrading off !!");
      
     }
      
      return(rates_total);
     }
   
   // When the new tick, let's generate the "New tick" custom event
   // that can be processed by Expert Advisor or indicator
   
   if  (TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) ) {
      EventChartCustom(chart_id,custom_event_id+2,(long)_Period,price_current,_Symbol);
      }
   else Print("autotrading off !!");
   
   //--- return value of prev_calculated for next call
   return(rates_total);

THİS CODE WORKİNG BUT A WARNİNG OCCURS ( possible loss of data due to type conversion ) line --> 

EventChartCustom(chart_id,custom_event_id+2,(long)_Period,price_current,_Symbol);

 
rosen007 #: THİS CODE WORKİNG BUT A WARNİNG OCCURS ( possible loss of data due to type conversion ) line --> 
input long            chart_id=0;        // chart id
input ushort          custom_event_id=0; // event id

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,        // size of price[] array
                 const int prev_calculated,  // bars, calculated at the previous call
                 const int begin,            // starting index of data
                 const double& price[]       // array for the calculation
   )
  {
   double price_current=price[rates_total-1];

   //--- Initialization:
   if(prev_calculated==0) 
     { // Generate and send "Initialization" event
      EventChartCustom(chart_id,0,(long)_Period,price_current,_Symbol);
      return(rates_total);
     }

   //--- Check if trading allowed
   if( (bool) TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) )
     { // When the new tick, let's generate the "New tick" custom event
       // that can be processed by Expert Advisor or indicator
      EventChartCustom(chart_id,custom_event_id+2,(long)_Period,price_current,_Symbol);
     }   
     
   //--- return value of prev_calculated for next call
   return(rates_total);
  }
 
Fernando Carreiro #:

nothing is changed same warning

 
rosen007 #: nothing is changed same warning
EventChartCustom( chart_id, ushort( custom_event_id + 2 ), (long) _Period, price_current, _Symbol );
 
Fernando Carreiro #:

thanks works fine :) 

 
rosen007 #: thanks works fine :) 
You are welcome!
Reason: