Download MetaTrader 5

I have some problem with "ObjectCreate"

To add comments, please log in or register
Do you have Linux? Find out how to install MetaTrader on it!
haoxiang xie
1076
haoxiang xie 2013.03.17 10:46 

i have write the code like this :

void OnTick()
  {
      // some codes...

        if(!PositionSelect(_Symbol))
        {
            CTrade trade;
            trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,0.1,
                               SymbolInfoDouble(_Symbol,SYMBOL_ASK),
                               0,0,"");
          
            bool res = ObjectCreate(0,"test obj",OBJ_ARROW_THUMB_UP,0,TimeCurrent(),SymbolInfoDouble(_Symbol,SYMBOL_ASK)+1);
           
            if (res) printf("------------ObjectCreate return TURE");
            else printf("----------------ObjectCreate return FALSE");
         }
    

    // some codes.... 

  }

when i run the ea in strategy tester , nothing has create in the chart , and the journal have this "------------ObjectCreate return TURE".

Can someone tell me why?

thanks 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types
Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Standard Constants, Enumerations and Structures / Objects Constants / Object Types - Documentation on MQL5
Alain Verleyen
Moderator
30742
Alain Verleyen 2013.03.17 10:52  
xhxiang:

i have write the code like this :

...

when i run the ea in strategy tester , nothing has create in the chart , and the journal have this "------------ObjectCreate return TURE".

Can someone tell me why?

thanks 

  1. Please use the SRC button when you post code.
  2. Object aren't plotted in normal mode, read here.
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.03.17 11:26  
xhxiang:

i have write the code like this :

void OnTick()
  {
      // some codes...

        if(!PositionSelect(_Symbol))
        {
            CTrade trade;
            trade.PositionOpen(_Symbol,ORDER_TYPE_BUY,0.1,
                               SymbolInfoDouble(_Symbol,SYMBOL_ASK),
                               0,0,"");
           
            bool res = ObjectCreate(0,"test obj",OBJ_ARROW_THUMB_UP,0,TimeCurrent(),SymbolInfoDouble(_Symbol,SYMBOL_ASK)+1);
            
            if (res) printf("------------ObjectCreate return TURE");
            else printf("----------------ObjectCreate return FALSE");
         }
    

    // some codes.... 

  }

when i run the ea in strategy tester , nothing has create in the chart , and the journal have this "------------ObjectCreate return TURE".

Can someone tell me why?

thanks 

Maybe the Objects are created but not at the time or price that you expect,  add a Print()  statement and output the time and price that you are using for the position of the Object and check it is correct.  Print these . . .

TimeCurrent(),SymbolInfoDouble(_Symbol,SYMBOL_ASK)+1

 

Objects are not created when you are running the Optimizer.

haoxiang xie
1076
haoxiang xie 2013.03.17 13:07  
angevoyageur:
  1. Please use the SRC button when you post code.
  2. Object aren't plotted in normal mode, read here.
thank you for your advice,and i have found the reason.  
Pasi Hakamaki
4715
Pasi Hakamaki 2013.03.17 14:59  
Also remember that each object must have a unique name.
Br, Candles
phi nuts
2184
phi nuts 2013.03.17 16:51  
xhxiang:
thank you for your advice,and i have found the reason.  

Good. because if for example EURUSD is 1.23456, then this code below

SymbolInfoDouble(_Symbol,SYMBOL_ASK)+1

will draw your object on EURUSD at 2.23456.

Just press Ctrl + O to see the object list and you will find your object at about 10,000 pips away :D.

BTW, why you need this arrow ?. Is MT5 deal arrow is not enough ?, you can activate it by open Option (Ctrl + O), click "Trade" tab and select "Show real time history on chart" .

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.03.17 17:56  
phi.nuts:

Good. because if for example EURUSD is 1.23456, then this code below

will draw your object on EURUSD at 2.23456.

Just press Ctrl + O to see the object list and you will find your object at about 10,000 pips away :D.

BTW, why you need this arrow ?. Is MT5 deal arrow is not enough ?, you can activate it by open Option (Ctrl + O), click "Trade" tab and select "Show real time history on chart" .

I was going to suggest the same,  unfortunately that won't work in the Strategy Tester  :-(  how do we get a list of the Objects in the Strategy Tester ?
Alain Verleyen
Moderator
30742
Alain Verleyen 2013.03.17 18:20  
RaptorUK:
I was going to suggest the same,  unfortunately that won't work in the Strategy Tester  :-(  how do we get a list of the Objects in the Strategy Tester ?
Object aren't plotted in Strategy Tester in "normal" mode, and in visual mode you can't almost do anything. Don't know why.
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2013.03.17 18:37  
angevoyageur:
Object aren't plotted in Strategy Tester in "normal" mode, and in visual mode you can't almost do anything. Don't know why.
In my world Visual Mode  IS normal mode ;-)  I have an indicator that uses Objects without problems in Visual Mode.
phi nuts
2184
phi nuts 2013.03.18 02:14  
Candles know the answer for that, it's a ghost in a PC :).
Pasi Hakamaki
4715
Pasi Hakamaki 2013.03.18 17:34  
phi.nuts:
Candles know the answer for that, it's a ghost in a PC :).
Haha, and it still there :(
To add comments, please log in or register