Get Object Data only once

 

I have a pre-existing ARROW OBJECT on chart on candle 80

I can get its value from ObjectGetDouble and its Time for candle as well

now i copy price and time of arrow to run under OnTimer function

I want to shift arrows back and forth by creating a new object of ARROW

but when I do this, its time do not update because its using

long arrowtime = ObjectGetInteger(0,arrow_lower,OBJPROP_TIME);

and pre existing arrow by default do not move. But i want to create new arrow and move it back and forward

so i want to ask how can i get the value of arrowtime so it can be changeable from keys such as N for next and B for previous.

I want to get

arrowtime

only once so it can be saved as variable so i can do modify shift or do whatever i want with this.

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Maybe it's only me, but I don't understand your issue at all. You have a pre-existing object on the chart...so what ?

If you want to change an object's property use ObjectSetInteger() or other ObjectSetXXX() functions.

 
Alain Verleyen #:

Maybe it's only me, but I don't understand your issue at all. You have a pre-existing object on the chart...so what ?

If you want to change an object's property use ObjectSetInteger() or other ObjectSetXXX() functions.

that pre-existing object lets say its name is "arrow_up"

so I get its details on Ontimer function using ObjectGetInteger(0,"arrow_up"OBJ_TIME) but if you notice its time wont change as pre existed object wont move its calculation is being updated from another indicator

Now i want to save this time and price in a way so i can make  it static and further use for modifying position of new arrow i created using the price and time i got of pre existed arrow.

How can i store this data as static?

 
Alain Verleyen #:

Maybe it's only me, but I don't understand your issue at all. You have a pre-existing object on the chart...so what ?

If you want to change an object's property use ObjectSetInteger() or other ObjectSetXXX() functions.

Here is my code. I expect when you press "N" key it should move arrow but it does not move.

To make this indicator work you have to use Price Line 3  on same chart.

Thanks for your time on looking onto this.

//+------------------------------------------------------------------+
//|                                                   testobject.mq5 |
//|                                                   Copyright 2023 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023"
#property version   "1.00"
#property indicator_chart_window
#property indicator_plots 0

long lowtime,newarrowtime;
double lowprice;
int shift_candle_1=0,shift;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {
//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]) {
//---
   lowtime = ObjectGetInteger(0,"viewport_text_L",OBJPROP_TIME);
   lowprice = ObjectGetDouble(0,"viewport_text_L",OBJPROP_PRICE);
   shift = iBarShift(NULL,0,lowtime);
   newarrowtime = iTime(NULL,0,(shift+shift_candle_1));
   
//Print((datetime)lowtime);
   crearFlecha("Arrow_",lowtime,lowprice,clrLimeGreen,251,ANCHOR_TOP);


//--- return value of prev_calculated for next call
   return(rates_total);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

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

   if(id==CHARTEVENT_KEYDOWN) {

      switch(int(lparam)) {
      case 78 : //N = Next
         shift_candle_1=shift_candle_1-1;
         Print("Moving ",shift_candle_1);
         crearFlecha("Arrow2_",newarrowtime,lowprice,clrLimeGreen,251,ANCHOR_TOP);
         break;
      }

   }
}
//+------------------------------------------------------------------+
//| CREATE ARROWS
//+------------------------------------------------------------------+
bool crearFlecha(string nameAux, datetime timeAux, double priceAux, color clrAux, int code, ENUM_ARROW_ANCHOR anchorAux) {
   const long              chart_ID=0;           // chart's ID
   const string            name=nameAux;         // arrow name
   const int               sub_window=0;         // subwindow index
   datetime                time=timeAux;         // anchor point time
   double                  price=priceAux;       // anchor point price
   const int               arrow_code=code;      // arrow code
   const ENUM_ARROW_ANCHOR anchor=anchorAux;     // anchor point position
   const color             clr=clrAux;           // arrow color
   const ENUM_LINE_STYLE   style=STYLE_SOLID;    // border line style
   const int               width=5;              // arrow size
   const bool              back=true;            // in the background
   const bool              selection=false;      // highlight to move
   const bool              hidden=true;          // hidden in the object list
   const long              z_order=0;            // priority for mouse click

   ObjectCreate(chart_ID,name,OBJ_ARROW,sub_window,time,price);
   ObjectSetInteger(chart_ID,name,OBJPROP_ARROWCODE,arrow_code);
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchorAux);
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
   return(true);
}


//+------------------------------------------------------------------+
Price Line 3
Price Line 3
  • www.mql5.com
Shows moving Last Price on Bid Line, LAst 24 hours percentage change, switch chart from arrow keys and more..
 
Arpit T #:

Here is my code. I expect when you press "N" key it should move arrow but it does not move.

To make this indicator work you have to use Price Line 3  on same chart.

Thanks for your time on looking onto this.

Why are you expecting it to move when you created it always with the same time/price ?

         crearFlecha("Arrow2_",newarrowtime,lowprice,clrLimeGreen,251,ANCHOR_TOP);
 
Alain Verleyen #:

Why are you expecting it to move when you created it always with the same time/price ?

Thank you. Problem solved.  ✓   ★ ★ ★ ★ ★ 

 
Arpit T #:

Thank you. Problem solved.  ✓   ★ ★ ★ ★ ★ 

crearFlecha("Arrow2_",newarrowtime,lowprice,clrLimeGreen,251,ANCHOR_TOP);

Crear flecha? (Create arrow) Do you speak Spanish? Just a curiosity.   

 
Miguel Angel Vico Alba #:

Crear flecha? (Create arrow) Do you speak Spanish? Just a curiosity.   

I bet for copy and paste code.
 
Alain Verleyen #I bet for copy and paste code.

With how beautiful it is to code...  

 
Alain Verleyen #:
I bet for copy and paste code.

Yes. I hire worldwide freelancer to get my complex projects coded. so this one was from a spanish developer. It help me learn. I learnt MQL5 from reverse engineering.  just from codes i learnt

 
Arpit T #:

Yes. I hire worldwide freelancer to get my complex projects coded. so this one was from a spanish developer. It help me learn. I learnt MQL5 from reverse engineering.  just from codes i learnt

Good practice, congratulations !
Reason: