New to scripts

 

I am new to scripts.

Created as a try.

int start()
  {
  int A;
    while(0==0)
    {
     A++;
     Comment(A);
      Sleep(10);
      if(Close[1]-Open[1]>0)
      {
        Alert("Bullish bar");
        break;
      }
    
    }
   return(0);
  }

The problem is: when I put it while previous bar is bullish, it alerts but

if not bullish, it not alerts even if in future previous bar is bullish.

Please help.

Thanks a lot.

 

Anybody?

 

.

The problem is: when I put it while previous bar is bullish, it alerts but

if not bullish, it not alerts even if in future previous bar is bullish.

Have a read about RefreshRates () ie, MUST work on latest symbol data otherwise your 'issues' will always come back to haunt you - where ever your code/terminal functions need up-to-date symbol data.

You need to have that in your loop. NOTE:how often you call it should be considered too. Why? what's point in overloading terminal with redundant work... it can indeed be a very busy bee at times :)

Since your script does not return to terminal, the script will 'continue' to use symbol data that is in reality ONLY valid until the next incoming data tick.

At which time RefreshRates() is ONLY way to get this 'latest' data...

Also, 10ms is very short time. what happens when incoming data ticks are separated by 'many' seconds, remembering that 100 Sleep(10); calls will be made for each second (but in reality, terminal can not guarantee that it will return in whatever timeperiod you specify in Sleep() call)

ie, that redundant work I mentioned above will/can cause overheads that are just not needed, especially when your code gets big and involved!

So, for sake of argument, why not Sleep(1000); just until get this going?

Then once you know the code works, well... is up to you of course!

.

hth

 

while(0==0) whats this about? You are simply stuck in an endless loop.

This should do it :-

int start()
{
   if(Close[1]-Open[1]>0)Alert("Bullish bar");
}

Whats the int A and the Sleep for?

 

I see you mentioned that you are new to scripts. Just remember that anytime you use a While or an If condition, one side of the equation has to change, so it has to be a variable.

 
Since it's a script not an EA he needs an infinite loop until the alert. Should have written:
while(true) {...
But you must refreshRates after sleep or all you'll get is the same value each time.
 

Thanks for the great helps.

What I was trying to do (since I know script lives only 1 tick)

is to make the script check as long as bulish bar is found.

I put Sleep(10) to ease pressure on processor.

I put int A to see the the script is running.

This is what I got (thanks to your help) and it works.

int start()
  {
  int A;
    while(true)
    {
     A++;
     Comment(A);
      Sleep(10);
      RefreshRates();
      if(Close[1]-Open[1]>0)
      {
        Alert("Bullish bar");
        break;
      }
    }
   return(0);
  }

My question : is thre any way to simplify it or

to make better for platform and processor?

Can I run 2 scripts at the same time?

Thank you all.

I like scripts using for testing market.

 

Thanks a lot for ur sharing.

It's very helpful for me.



[url=http://www.softwareoutsourcing.biz/dedicated-developer/net-developer.html]Hire .NET Developer [/url]
 
Beankyu:

Thanks a lot for ur sharing.

It's very helpful for me.

[url=http://www.softwareoutsourcing.biz/dedicated-developer/net-developer.html]Hire .NET Developer [/url]

Looks like we have some players here.
 
Thread is a duplicate of https://www.mql5.com/en/forum/127644