expert advisor - miscellaneous questions - page 12

 
Marco vd Heijden:

I guess so.

It's slightly different tho.

The global versus static is neither here nor there. But your method of reset is good. It prevents the overrun.
 
honest_knave:
The global versus static is neither here nor there. But your method of reset is good. It prevents the overrun.

I spoke too soon. Yours overruns the other way. It will trigger on a later CTRL press. If you click on the chart, then press CTRL it fires.

 

@honest_knave - thanks for your comment. Much appreciate that - but I started try first @Marco vd Heijden comment. ( I read all your comments about that. )

@Marco vd Heijden - Thanks man.

But I think I am doing something wrong, maybe I do not understand more clearly. Anyway I tried, you can find it below code.
Where is my mistake, please?

//+------------------------------------------------------------------+
//|                                                      keydown.mq4 |
//|      Copyright 2016, Marco vd Heijden, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Marco vd Heijden, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

string prefix = "Custom Expert |";
string lotedit = prefix + "Edit Name";
string lotbtnplus = prefix + "Lot button Plus";
string lotbtnminus = prefix + "Lot button Minus";

double lot = 0.01, lotstep = 0.01 ;
bool ctrl_click;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create timer
   EventSetTimer(60);

   graphicsObj();

//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
    EventKillTimer();
    ObjectsDeleteAll( 0, prefix );
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---
    graphicsObj();
}
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---

  }
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{

    if( id == CHARTEVENT_CLICK )
    {
        if ( sparam == lotbtnplus )
        {
            ObjectSetInteger( 0, sparam, OBJPROP_STATE, false );
            lot = lot + lotstep;
            update();

            Print( " | lot plus :  ", lot );
            return;
        }

        Print( "Click" );
        ctrl_click = 1;
    }

    if( id == CHARTEVENT_KEYDOWN )
    {
        //Print(lparam);// print to identify keycode

        if( lparam == 17 )  // ctrl key
        {
            if( ctrl_click == 1 )// if mouse click
            {
                //Do Something when CTRL (keycode 17) is pressed
                if ( sparam == lotbtnplus )
                {
                    ObjectSetInteger( 0, sparam, OBJPROP_STATE, false );
                    lot = lot + ( lotstep * 10 );
                    Print( " | lot plus + Ctrl initial:  ", lot );
                    update();

                    Print( " | lot plus + Ctrl:  ", lot );
                    return;
                }
                Print( "Ctrl + Click" );
                ctrl_click = 0;  // reset
            }
        }
        ctrl_click = 0; // reset if not ctrl
    }
}

//|+--------------------------------------------------------------------------------+
//| -   Function Update                                                             |
//|+--------------------------------------------------------------------------------+
void update()
{
    //---
    ObjectSetString( 0, lotedit, OBJPROP_TEXT, DoubleToString( lot, 2 ) );
    //---
    return;
}
void graphicsObj()
{
    ObjectCreate(0, lotedit, OBJ_EDIT, 0,0,0);
    ObjectSetInteger(0, lotedit, OBJPROP_XDISTANCE, 30);
    ObjectSetInteger(0, lotedit, OBJPROP_YDISTANCE, 30);
    ObjectSetInteger(0, lotedit, OBJPROP_XSIZE, 60);
    ObjectSetInteger(0, lotedit, OBJPROP_YSIZE, 30);
    ObjectSetString(0, lotedit, OBJPROP_TEXT, DoubleToString( lot, 2 ));

    ObjectCreate( 0, lotbtnplus, OBJ_BUTTON, 0, 0, 0);
    ObjectSetString( 0, lotbtnplus, OBJPROP_TEXT, "+");
    ObjectSetInteger( 0, lotbtnplus, OBJPROP_XDISTANCE, 100);
    ObjectSetInteger( 0, lotbtnplus, OBJPROP_YDISTANCE, 30);
    ObjectSetInteger( 0, lotbtnplus, OBJPROP_XSIZE, 70);
    ObjectSetInteger( 0, lotbtnplus, OBJPROP_YSIZE, 30);
    ObjectSetInteger( 0, lotbtnplus, OBJPROP_BACK, false);
    ObjectSetInteger( 0, lotbtnplus, OBJPROP_SELECTABLE, false);
}
 

Your first problem is that CHARTEVENT_CLICK is not the same as CHARTEVENT_OBJECT_CLICK. You want to catch clicks on an object, not just any click on the chart.

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{

//    if( id == CHARTEVENT_CLICK )
    if( id == CHARTEVENT_OBJECT_CLICK )
 
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   static bool wasCTRL=false;
   if(id==CHARTEVENT_OBJECT_CLICK && sparam == lotbtnplus)
     {
      ObjectSetInteger( 0, sparam, OBJPROP_STATE, false );
      lot+=(wasCTRL)?lotstep*10:lotstep;
      update();
      Print( " | lot plus :  ", lot );
      return;
     }
   wasCTRL=(id==CHARTEVENT_KEYDOWN && lparam==17);
}
This may help. You might find that it only goes to 0.1 on the second click of the mouse, depending on how quickly you press the button after CTRL.
 
honest_knave:
This may help. You might find that it only goes to 0.1 on the second click of the mouse, depending on how quickly you press the button after CTRL.

#Ctrl + Mouse Button - Closed

Wow, just like it, amazing huge thanks honest!

Special thanks to @honest_knave and @Marco vd Heijden

 
#SpreadSheet - Open

Latest Friday 'Spreadsheet' was updates by OnTick function ( which one I need, it was good for me ).

( MT4 platform updated twice. ) After that updates this spreadsheet does not update on the chart, I checked out everything about spreadsheet I do not see any problem.

I need to inform I also use Bid and Ask prices above spreadsheet, Bid and Ask works good, but spreadsheet does not.

So I use Label Function for Label Objects - every Label objects works good without 'Spreadsheet'. Also I need to inform when I create Label object for spreadsheet without function, it works good.
That problem starts after MT4 Platform upgrades, I am not sure where is that problem comes.

If you understand my concern, let me know how can I solve this issue.
Thanks in advance.

 

Did you have some code about spreadsheet ?

 
Marco vd Heijden:

Did you have some code about spreadsheet ?

I am still researching about that, also I will post some of code from it, which is working which is not, soon.
 

Can I write 2 different Label Function?
( e.g: 1 for text, 2 for text and font size. ) 

Reason: