Download MetaTrader 5

script doesnt run

To add comments, please log in or register
brettosm8
241
brettosm8  

hi there,

thanks for your assistance. I'm trying to write some code that will print out my horizontal lines but the script is loaded and then removed. Does the mrket have to be open to run or why doent it work?

anks, brad.

int TotalHLines=0;

void OnStart()
  {
  Print("hello");
   TotalHLines=ObjectsTotal(OBJ_HLINE);
   for(int i=0;i<TotalHLines;i++)
      {
         Print(ObjectName(i));
      }//End of for loop
  }// End of OnStart
Alain Verleyen
Moderator
31603
Alain Verleyen  
brad:

hi there,

thanks for your assistance. I'm trying to write some code that will print out my horizontal lines but the script is loaded and then removed. Does the mrket have to be open to run or why doent it work?

anks, brad.

There is no problem with this script.

Do you have some horizontal lines on your chart ?

Keith Watford
Moderator
10065
Keith Watford  
Are you checking the Expert tab/logs to see if the print worked, or are you expecting a pop-up alert?
whroeder1
15073
whroeder1  
brad: Does the mrket have to be open to run or why doent it work?
No ticks on the weekend when market is closed.
Keith Watford
Moderator
10065
Keith Watford  
WHRoeder:
No ticks on the weekend when market is closed.


Does a script using the function void OnStart() need a tick?
whroeder1
15073
whroeder1  
Scripts shouldn't. I didn't read close enough.
brettosm8
241
brettosm8  

when i drop the script on the chart the screen appears like this:

thanks,

Brad.

whroeder1
15073
whroeder1  
Try looking in the Experts tab for your printout, as previously answered.
GumRai: Are you checking the Expert tab/logs
This finds that there are 2 HLINEs on the chart of nnn objects, and then prints out the names of the first two objects, not the names of the HLINEs.
TotalHLines=ObjectsTotal(OBJ_HLINE);
for(int i=0;i<TotalHLines;i++){
      Print(ObjectName(i));
If you want to print out the names of the HLINEs, you need to find them, wherever they are in the list.
TotalHLines=0;
for(int i=ObjectsTotal() - 1; i >= 0; i--){
      string on = ObjectName(i);
      if( ObjectType(on) == OBJ_HLINE){
         Print(on); TotalHLines++; }
brettosm8
241
brettosm8  
you're right! had to che k the experts tab.
To add comments, please log in or register