OrderCalcMargin() gives error - 4014: System function is not allowed to call

 

Could anyone shed some light on this error, I am adding an example code

#property indicator_chart_window
int OnInit()
{
    double dVol = 1.0;
    double dMargin = 0.0;
    double dAsk = SymbolInfoDouble(_Symbol, SYMBOL_ASK);

   if(!OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,dVol,dAsk,dMargin)) {
        Print("Last error = ",GetLastError());//,": (OrderCalcMargin()) ",ErrorDescription(GetLastError()));
   }

   Print("dMargin = ",dMargin);

   return(INIT_SUCCEEDED);

}


Many thanks

George

 

Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

 
geodeas:

Could anyone shed some light on this error, I am adding an example code



Many thanks

George

You can't call trading related functions in an indicator.

See https://www.mql5.com/en/docs/runtime/running

Documentation on MQL5: MQL5 programs / Program Running
Documentation on MQL5: MQL5 programs / Program Running
  • www.mql5.com
MQL5 programs / Program Running - Documentation on MQL5
 
angevoyageur:

Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

Thanks, I'll keep it in mind.
 
angevoyageur:

You can't call trading related functions in an indicator.

See https://www.mql5.com/en/docs/runtime/running

OK, thank you.