Trigger an Alert/Action when the candle closes - page 2

To add comments, please log in or register
Ahmad Zuhairdi Noh
7405
Ahmad Zuhairdi Noh  
Elixium:
Thanks. I tried this and the alert executed immediately, It does limit the alert to once per hour but I need the alert to be delayed until a new bar appears, not to show up immediately.

then, you change this one:

int barMark = 0;

to

int barMark = Hour();

You will have to wait next hour for the alert to give a first signal.

Elixium
70
Elixium  

I've fixed the compile errors.

But now I have the problem where it's executing the alert on every tick.

I don't know how to adjust it from every tick to Once per bar.


  
void OnTick(){
   static datetime timeCur; datetime timePre = timeCur; timeCur=Time[0];
   bool isNewBar = timeCur != timePre;
   if(isNewBar && Close[1] < targetPrice ) { 
   }
   Alert("Hello"); 
   }

 // extern double targetPrice = 52.75; //put this line above OnInit so you can easily change it in the Input section\
 // (I have this above OnInit)
Elixium
70
Elixium  
Ahmad Zuhairdi Noh:

then, you change this one:

to

You will have to wait next hour for the alert to give a first signal.

Ok I'll check this out. Thanks.

Ernst Van Der Merwe
6477
Ernst Van Der Merwe  
void OnTick()
  {
//---
   double threshold=52.75;
   static datetime preTime=0;
   if(preTime==Time[1])
     {
      if(Open[1]>threshold)
         Alert("Hello");
     }
   preTime=Time[0];
  }
Elixium
70
Elixium  
Ahmad Zuhairdi Noh:

then, you change this one:

to

You will have to wait next hour for the alert to give a first signal.


int barMark = Minute()=5; 


What's the correct syntax of Minute() If I wanted to change it to be e.g. 5 minutes instead of 1 hour?

Ahmad Zuhairdi Noh
7405
Ahmad Zuhairdi Noh  
Elixium:



What's the correct syntax of Minute() If I wanted to change it to be e.g. 5 minutes instead of 1 hour?

This is why you need to be more specific when asking a question. Because you may end up getting a different way of solving the problem.

BTW, if you want to be more flexible, use iBarShift instead.

extern double targetPrice = 52.75; //put this line above OnInit so you can easily change it in the Input section
extern int timeframe = 0;

datetime barMark = TimeCurrent(); //put this line above OnInit to initialize the mark in a global scope

void OnTick(){

  int counter = iBarShift(NULL,timeframe,barMark); //this will count how many bar after last marking. 

  if(Close[0] > targetPrice && counter != 0){
    Alert("Price exceed level!");
    barMark = TimeCurrent(); //this mark will reset the counter to 0 thus preventing the alert to be called.
  }

}

There might be some bug, I didn't check the code. But, that's another way of doing it. You can change 'timeframe' from the input section according to your setup (ex. 5, 15, 30, 60,...).

Goodluck.

Elixium
70
Elixium  
Ahmad Zuhairdi Noh:

This is why you need to be more specific when asking a question. Because you may end up getting a different way of solving the problem.

BTW, if you want to be more flexible, use iBarShift instead.

There might be some bug, I didn't check the code. But, that's another way of doing it. You can change 'timeframe' from the input section according to your setup (ex. 5, 15, 30, 60,...).

Goodluck.


Hi, your code works fine. I wanted to make a small tweak but there's a compile error. What would be the correct syntax?

Alert if above price or Alert if below price.


  if(Close[0] > targetPriceHigh OR < targetPriceLow && counter != 0){
Ahmad Zuhairdi Noh
7405
Ahmad Zuhairdi Noh  
Elixium:


Hi, your code works fine. I wanted to make a small tweak but there's a compile error. What would be the correct syntax?

Alert if above price or Alert if below price.


extern double targetPriceHigh = 52.75; //put this line above OnInit so you can easily change it in the Input section
extern double targetPriceLow = 42.75;
extern int timeframe = 0;

datetime barMark = TimeCurrent(); //put this line above OnInit to initialize the mark in a global scope

void OnTick(){

  int counter = iBarShift(NULL,timeframe,barMark); //this will count how many bar after last marking. 

  if((Close[0] > targetPriceHigh || Close[0] < targetPriceLow)  && counter != 0){
    Alert("Price exceed level!");
    barMark = TimeCurrent(); //this mark will reset the counter to 0 thus preventing the alert to be called.
  }
}
Elixium
70
Elixium  
Ahmad Zuhairdi Noh:

With your new code it triggered the alert instantly for both low & high, it didn't wait for the candle to be closed.


datetime barMark = TimeCurrent(); //put this line above OnInit to initialize the mark in a global scope


Does this line have to be above OnInit for it to work?

Ahmad Zuhairdi Noh
7405
Ahmad Zuhairdi Noh  
Elixium:

With your new code it triggered the alert instantly for both low & high, it didn't wait for the candle to be closed.



Does this line have to be above OnInit for it to work?

So? did you try it? does it work if you put it above OnInit?

You should try it yourself. Try and error.

You'll learn faster that way.

123
To add comments, please log in or register