"objectGet" optimization issue

 
hi everybody. 
i had some objectGet issue when optimizing the values. 
the code is working but the value returns as 0.
if anyone could help. thank you.

see code example and pic attached.



//+------------------------------------------------------------------+
//|                                                   LineTST_v1.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   "1.00"
#property strict

extern int sl=300;
extern int tp=400;

//+------------------------------------------------------------------+
//|                             start                                |
//+------------------------------------------------------------------+
void OnTick()
  {
   calculateHigh();
   interactH();
   
  }
//+------------------------------------------------------------------+
//|                       external functions                         |
//+------------------------------------------------------------------+
void interactH()
  {
   if(ObjectFind(0,"line_H")==0)
   {
    double line_H=ObjectGet("line_H",OBJPROP_PRICE1);
    
    if(Low[1]>line_H) ObjectDelete(NULL,"line_H");
    
    if(Open[2]<line_H)
    if(Close[2]<line_H)
    if(High[1]>=line_H)
    if(Close[1]<Low[2])
    {
     int ticket=OrderSend(Symbol(),OP_SELL,0.01,Bid,3,Bid+sl*Point,Bid-tp*Point,"",0,0,clrRed);
    }
   }
  }
//+------------------------------------------------------------------+
void calculateHigh()
  {
   int high=iHighest(NULL,0,MODE_HIGH,100,10); 
   
   ObjectDelete(NULL,"line_H");
   ObjectCreate(NULL,"line_H",OBJ_TREND,0,Time[high],High[high],Time[0],High[high]);
   ObjectSet("line_H",OBJPROP_COLOR,clrPink);
   ObjectSet("line_H",OBJPROP_WIDTH,1);
   ObjectSet("line_H",OBJPROP_BACK,1);
   ObjectSet("line_H",OBJPROP_RAY,1);
  }
//+------------------------------------------------------------------+


Files:
111.jpg  41 kb
 
Alexander Chertnik: i had some objectGet issue when optimizing the values. the code is working but the value returns as 0. if anyone could help. thank you. see code example and pic attached.

Graphical objects do not work during optimisations.

Instead, write your code not to depend on graphical objects for data. Use variables (they are way faster).

Only use graphical objects for display purposes if really needed. Have an option to enable them or not for the user, but don't depend on them for the logic execution.

 

Operation of Programs in the Strategy Tester - MQL4 programs - MQL4 Reference

Graphical Objects in Testing

During visualization, the Expert Advisor interacts with a real chart. In case there is no visualization, the Expert Advisor works with a "virtual" chart that is not displayed. The former case has some peculiarities. During optimization, working with graphical objects is not supported.

Operation of Programs in the Strategy Tester - MQL4 programs - MQL4 Reference
Operation of Programs in the Strategy Tester - MQL4 programs - MQL4 Reference
  • docs.mql4.com
Operation of Programs in the Strategy Tester - MQL4 programs - MQL4 Reference
 
Fernando Carreiro #:

Operation of Programs in the Strategy Tester - MQL4 programs - MQL4 Reference

Graphical Objects in Testing

During visualization, the Expert Advisor interacts with a real chart. In case there is no visualization, the Expert Advisor works with a "virtual" chart that is not displayed. The former case has some peculiarities. During optimization, working with graphical objects is not supported.

got it, thank you very much:)