OnChartEvent() ... does not work in Indicator but in strategy do.
Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!

Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!

You agree to website policy and terms of use
dear, can OnChartEvent() work in indicator? ( according to manual yes) but this code as indicator doesn't work. Do you know why, please?
//+------------------------------------------------------------------+
//| ChartEvent function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
//---
//---
ResetLastError();
RefreshRates();
//--
static bool keyPressed=false;
//--- this is an Event of a keystroke
if(id==CHARTEVENT_KEYDOWN)
{
if(lparam==KEY_PLUS || lparam==KEY_MINUS)
{
if(!keyPressed) keyPressed=true;
else keyPressed=false;
}
//--
switch(int(lparam))
{
case KEY_PLUS:
{
//.... etc
MessageBox("PLUS");
}
break;
case KEY_MINUS:
{
//.... etc
MessageBox ("MINUS");
}
break;
}
}
}
//+------------------------------------------------------------------+