How can I get some description stored in an OBJ_LABEL to FLASH at a 'reasonably' consistent interval ?

 

Given Terminal rumblings internally, I'm not at issue with having any type of exact on/off cycle. Just require something that will cycle on/off without 'user' help alongs (**)

background:

1. OBJ_LABEL object created with text.

2. eg:

ObjectSet(sName,OBJPROP_CORNER,<0..3>);

ObjectSet(sName,OBJPROP_XDISTANCE,iX);

ObjectSet(sName,OBJPROP_YDISTANCE,iY);

ObjectSetText (sName,"some text to flash",iSize,sFont,cColor);

.

3. ok, the text displays with the creation of sName OBJ_LABEL

4. now, we want to wait (somehow) for a predefined time period eg, 2000ms

5. if use Sleep() it can happen that a few weeks can pass by prior to it's return to caller. (yessss, I am being contentious, but I relay my experiences over this)

6. assuming get control back in reqd. time period, we want to turn off text for a predefined time period.

eg: various ways to do this but let's say just set text to ""

ObjectSetText (sName,"",iSize,sFont,cColor); //turn off

7. do Sleep(..); //give the off/on effect

8. ObjectSetText (sName,"some text to flash",iSize,sFont,cColor); //turn back on

9. goto 4

.

above could be in loop with a defined terminal condition eg, while( !IsExpertEnabled() ) {...}

other stuff needed to finally turn off and continue on our way but that's design dependant...

.

(**)

above is what I basically do but the flash can appear only when there is a 'reason' for Terminal to do display work.

Even a new data tick refuses to cause on/off to make reliable transition.

IF you click on the chart THEN hey presto! Terminal will plot whatever is in the sName's text datum.

.

is all hit 'n miss.

.

have done short,long, whatever Sleep's. Have done while loop based on GetTickCount(), and even a for() loop with large start, end values etc.

Only thing happens with inline code stuff is 100% cpu loading.

Sleep() of course does not have this issue since caller code is suspended...

.

I could always be totally missing the point here - whatever...

H.E.L.P

 
fbj:

Given Terminal rumblings internally, I'm not at issue with having any type of exact on/off cycle. Just require something that will cycle on/off without 'user' help alongs (**)

[...] H.E.L.P

I'm not entirely sure what the issue is here.

I assume from context that you're trying to do all this in a script, in a loop, rather than in an EA which is driven by the ticks coming in from the market to its start() function. If so, the answer may be as simple as needing to call WindowRedraw() to make sure that the chart gets updated whenever you flash your object on and off.

For example, the following script works fine for me - and appears to be broadly the sort of thing which you are after. But it doesn't work properly if you remove the WindowRedraw().

// Display the object for this number of milliseconds - i.e. the object can appear to "pulse" 
// rather than "flash" if you set the display-period to longer than the hide-period
#define  DISPLAY_FOR_MILLISECONDS         500   
// After display, hide the object for this number of milliseconds
#define  HIDE_FOR_MILLISECONDS            50    
// Accuracy of above wait-periods, subject also to the granularity of the system clock 
#define  WAIT_GRANULARITY_MILLISECONDS    20    

int start()
{
   // Create a label object 50 pixels from the top (left) corner of the chart 
   string strObjectName = StringConcatenate("Test", GetTickCount()); // Name is more-or-less guaranteed to be unique

   ObjectCreate(strObjectName, OBJ_LABEL, 0, 0, 0);
   ObjectSet(strObjectName, OBJPROP_XDISTANCE, 50);
   ObjectSet(strObjectName, OBJPROP_YDISTANCE, 50);
   
   // Flag which handles whether we're currently displaying or not 
   bool bDisplay = true;
   
   // Keep looping until the script is removed from the chart 
   while (!IsStopped()) {
      // Alternate between displaying the actual text and blank text    
      if (bDisplay) {
         ObjectSetText(strObjectName, "Hello world", 10);
      } else {
         ObjectSetText(strObjectName, " ", 10);
      }
      
      // Force a redraw of the window 
      WindowRedraw();      
   
      // Wait the specified number of milliseconds, depending on whether the
      // text is currently visible or not. Start by establishing the 
      // time until which we wait...
      int CurrentTickCount = GetTickCount(), WaitUntilTickCount;
      if (bDisplay) {
         WaitUntilTickCount = CurrentTickCount + DISPLAY_FOR_MILLISECONDS;
      } else {
         WaitUntilTickCount = CurrentTickCount + HIDE_FOR_MILLISECONDS;
      }
      
      // And then do the wait, in small increments so that we can check for 
      // removal of the script from the chart 
      while (GetTickCount() < WaitUntilTickCount && !IsStopped()) {
         Sleep(WAIT_GRANULARITY_MILLISECONDS);      
      }
      
      // Switch between non-display and display
      bDisplay = !bDisplay;
   }

   // Delete the graphical object before exiting the script 
   ObjectDelete(strObjectName);
}
 
jjc:

I'm not entirely sure what the issue is here.

I assume from context that you're trying to do all this in a script, in a loop, rather than in an EA which is driven by the ticks coming in from the market to its start() function. If so, the answer may be as simple as needing to call WindowRedraw() to make sure that the chart gets updated whenever you flash your object on and off.

For example, the following script works fine for me - and appears to be broadly the sort of thing which you are after. But it doesn't work properly if you remove the WindowRedraw().

THANK YOU ... THANK YOU

As I key this in and stare DUMBLY at the bloody screen with code plus added WindowRedraw(); AND... at the fixed times the label flashes at me

well jjc, I can only produce a dropped jaw - LOL

.
Why? I have used this many times in past - past being keyword here cuz my memory never ever prompted me to use this sys call.

I can only think that old man time is genuinely creeping into thought processes and perhaps more annoyingly my problem solving methods - oh MERDE!

Man o man, how in the heck could this have happened to me. I honestly have spent way to much time devising ever more bizarre constructs attempting to get GUI o/p "when I wanted it displayed".

I assume from context that you're trying to do all this in a script,

no, in EA - user trading I/F to remove drudge + finger trouble via F9 functionality...

.

Your FULLY annotated example is, as usual, up to jjc excellent quality.

.

With a sub nanosec edit, I have smile.

However, I have other areas of 'discovery' that need such edits and as with your other offerings, I'm going to study it (always, always - 'code review' is my motto as 'getting to grips' with others code is good for self in that further KB entries can be made/updated and new ones entered :-).

Also... if for no other reason than that you code in a very likeable manner with rules close to my heart, esp. ye old Hungarian notation/variant concept.

Geeeze, I am truly bowled over.

.

Your The Dude, jjc

Reason: