Download MetaTrader 5

expert advisor - miscellaneous questions - page 20

Max Enrik
1000
Max Enrik  
#Stop Loss, Take Profit - Drags - Open

Since my latest comment I was started research forum and article for Stop Loss and Take Profit - Object Drags.
I just only found this article MQL5 COOKBOOK: HANDLING TYPICAL CHART EVENTS
But it's for MT5.

So before I started read it or trying that article, please let me know is that article would be useful for MT4?
Also if it's possible please share with me good article for Objects Drags.

Thanks in advance.
Marco vd Heijden
Moderator
5089
Marco vd Heijden  
Yes the OnChartEvent() is the same for both languages.
Max Enrik
1000
Max Enrik  
Marco vd Heijden:
Yes the OnChartEvent() is the same for both languages.
Oh! Nice to know, I can start to read it.
Thanks a lot.
Marco vd Heijden
Moderator
5089
Marco vd Heijden  

I have also found that many of the code that was written for MT5 now also works on MT4.

I know because i have tried many things in the past and things that did not work one year ago, do work now so this shows that they are still actively developing both languages.

Max Enrik
1000
Max Enrik  
Marco vd Heijden:

I have also found that many of the code that was written for MT5 now also works on MT4.
I know because i have tried many things in the past and things that did not work one year ago, do work now so this shows that they are still actively developing both languages.

Nice to know that. I always think ( / worry ) about it that MT4 language will not use soon. Thanks man.
Max Enrik
1000
Max Enrik  
// I say Once ' Do not turn... ' for ' if ' operator - this is good.
if  ( Morning || Midnight )
{
    // Do not turn on light just for today...
}

// I say Twice ' Do not turn... ' for ' switch ' operator - Q: Can I say ' Once '?
switch ( Today )
{
    case    Morning  :    // Do not turn on light just for today...
    break;
    case    Midnight :    // Do not turn on light just for today...
    break;
}   //---switch Close
Thanks in advance.
Max Enrik
1000
Max Enrik  

I already read article and checked out some other people codes for ' CHARTEVENT_OBJECT_DRAG ' that how to used from it.
But unfortunately that is not make senses for me. Just now I am think I was waste my time for just useless things. Because their code style really different from mine.
( my code style just simple - like mql4 documentation code style - which is I am understanding a little a bit more )

Just my purpose when I drag object ' Stop Loss, Take Profit, Pending Orders ' that could moves with that object. ( of course all of them could be separately )

Also I was seen one EA script for modify orders ( sl, tp etc. ) - and it works without ' CHARTEVENT_OBJECT_DRAG '... I hope you know that what I mean. 

Now, I am really need help just with simple example for ' CHARTEVENT_OBJECT_DRAG ' with HLine or Trendline Object. Or clearly explanation or just something good ( / more clearly ) comment.
I already spent a lot of time and I still researching about that. I hope I will get answer soon. 

All the best to you.
Thanks in advance.

Marco vd Heijden
Moderator
5089
Marco vd Heijden  
// I say Once ' Do not turn... ' for ' if ' operator - this is good.
if  ( Morning || Midnight )
{
    // Do not turn on light just for today...
}

This will be true Morning OR Midnight

// I say Twice ' Do not turn... ' for ' switch ' operator - Q: Can I say ' Once '?
switch ( Today )
{
    case    Morning  :    // Do not turn on light just for today...
    break;
    case    Midnight :    // Do not turn on light just for today...
    break;
}   //---switch Close

This has a separate case for Morning and a separate case for Midnight.

So those are two different things.

Max Enrik:

I already read article and checked out some other people codes for ' CHARTEVENT_OBJECT_DRAG ' that how to used from it.
But unfortunately that is not make senses for me. Just now I am think I was waste my time for just useless things. Because their code style really different from mine.
( my code style just simple - like mql4 documentation code style - which is I am understanding a little a bit more )

Just my purpose when I drag object ' Stop Loss, Take Profit, Pending Orders ' that could moves with that object. ( of course all of them could be separately )

Also I was seen one EA script for modify orders ( sl, tp etc. ) - and it works without ' CHARTEVENT_OBJECT_DRAG '... I hope you know that what I mean. 

Now, I am really need help just with simple example for ' CHARTEVENT_OBJECT_DRAG ' with HLine or Trendline Object. Or clearly explanation or just something good ( / more clearly ) comment.
I already spent a lot of time and I still researching about that. I hope I will get answer soon. 

All the best to you.
Thanks in advance.


You can drag a line when

OBJPROP_SELECTABLE ==1
OBJPROP_SELECTED ==1

Both are true and you can simple read the values in by using \

ObjectGetDouble(....

In stead of

ObjectSetDouble(....
It's not that hard and can be very useful.
Max Enrik
1000
Max Enrik  
Marco vd Heijden:

Almost I was not any idea how can I write code for Stop Loss and Take Profit Drags when I started to do that, thanks a lot man.
Now I feel I can do what I want after your great comment.

Market Closed 

So, I already tried and now I can get ' OBJPROP_PRICE ' which one I want.
When I drags ' HLine ' object and then Print() updates once in a second. Because I use EventSetTimer( 1 ).

But I need Print() won't updates once in a second. I would like to Print() should updates after I stopped drags.
If you understand me please help me or give me advice.

All the best to you.

Marco vd Heijden
Moderator
5089
Marco vd Heijden  

So you can store the value of OBJPROP_PRICE in a double and then compare them.

If they differ you know the dragging has been started, and then if they equal again you know the dragging has been stopped.

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

double price; // price variable;
bool drag;     // drag flag
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(1);
//--- create Hline
   ObjectCreate(0,"line",OBJ_HLINE,0,0,Ask);
//--- store value
   price=ObjectGetDouble(0,"line",OBJPROP_PRICE,0);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//--- compare values
   if(price!=ObjectGetDouble(0,"line",OBJPROP_PRICE,0))
     {
      drag=1;                                          // set drag flag
      price=ObjectGetDouble(0,"line",OBJPROP_PRICE,0); //store new value
     }
   if(drag==1)
     {
      if(price==ObjectGetDouble(0,"line",OBJPROP_PRICE,0))
        {
         drag=0; //reset drag flag
         Alert(" New value set: ", DoubleToString(price));
        }
     }
  }
//+------------------------------------------------------------------+

Or you could start a counter once dragging has been detected there are many ways to do it.,

1...131415161718192021222324252627...43
To add comments, please log in or register