inputlong chart_id=0; // chart idinputushort custom_event_id=0; // event id//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate (constint rates_total, // size of price[] arrayconstint prev_calculated, // bars, calculated at the previous callconstint begin, // starting index of dataconstdouble& price[] // array for the calculation
)
{
double price_current=price[rates_total-1];
//--- Initialization:if(prev_calculated==0)
{ // Generate and send "Initialization" eventEventChartCustom(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 indicatorEventChartCustom(chart_id,custom_event_id+2,(long)_Period,price_current,_Symbol);
//--- return value of prev_calculated for next callreturn(rates_total);
}
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
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_plots0inputlong chart_id=0; // chart idinputint custom_event_id=0; // event id//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate (constint rates_total, // size of price[] arrayconstint prev_calculated, // bars, calculated at the previous callconstint begin, // starting index of dataconstdouble& price[] // array for the calculation
)
{
double price_current=price[rates_total-1];
//--- Initialization:if(prev_calculated==0)
{ // Generate and send "Initialization" eventif (!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 indicatorif (TerminalInfoInteger(TERMINAL_TRADE_ALLOWED) ) {
EventChartCustom(chart_id,custom_event_id+2,(long)_Period,price_current,_Symbol);
}
elsePrint("autotrading off !!");
//--- return value of prev_calculated for next callreturn(rates_total);
THİS CODE WORKİNG BUT A WARNİNG OCCURS ( possible loss of data due to type conversion ) line -->
rosen007 #: THİS CODE WORKİNG BUT A WARNİNG OCCURS ( possible loss of data due to type conversion ) line -->
inputlong chart_id=0; // chart idinputushort custom_event_id=0; // event id//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate (constint rates_total, // size of price[] arrayconstint prev_calculated, // bars, calculated at the previous callconstint begin, // starting index of dataconstdouble& price[] // array for the calculation
)
{
double price_current=price[rates_total-1];
//--- Initialization:if(prev_calculated==0)
{ // Generate and send "Initialization" eventEventChartCustom(chart_id,0,(long)_Period,price_current,_Symbol);
return(rates_total);
}
//--- Check if trading allowedif( (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 indicatorEventChartCustom(chart_id,custom_event_id+2,(long)_Period,price_current,_Symbol);
}
//--- return value of prev_calculated for next callreturn(rates_total);
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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
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?
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.
THİS CODE WORKİNG BUT A WARNİNG OCCURS ( possible loss of data due to type conversion ) line -->
nothing is changed same warning
thanks works fine :)