• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 10:54am
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 10:54am
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Printable Version

Similar Threads

Please code round number alert indicator (indi Request) 4 replies

4H Stochs Email Alert Code Help Please 19 replies

Please add email alert to this price alert indicator 0 replies

Please add alert to Parabolic Sar 2TF - Please Help! 0 replies

Please help add email alert to code 1 reply

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 21
Attachments: Help Please with Indicator Alert Code
Exit Attachments

Help Please with Indicator Alert Code

  • Last Post
  •  
  • Page 1 2
  • Page 1 2
  •  
  • Post #1
  • Quote
  • First Post: Edited at 3:39pm Dec 12, 2019 3:25pm | Edited at 3:39pm
  •  Burton
  • | Joined Jan 2008 | Status: Member | 215 Posts
Help Please with Indicator Alert Code

I have added alert code to this indicator, so it with alert when color/signal changes, yet not working correctly,

I have placed the words "// added" beside the code I added,

Simple indicator, yet my coding skills are not good

You Require the HP indicator in your indicators folder for the HP_DIFF_Alerts indicator to work,

All help greatly appreciated
Attached Files
File Type: mq4 HP_DIFF_Alerts.mq4   4 KB | 95 downloads
File Type: mq4 HP.mq4   2 KB | 109 downloads
  • Post #2
  • Quote
  • Edited Dec 13, 2019 12:13am Dec 12, 2019 11:56pm | Edited Dec 13, 2019 12:13am
  •  BlueRain
  • Joined Sep 2019 | Status: Member | 828 Posts
quick look.. and it seem your variable is not matching.

in this line,
for (int li_0 = Bars - IndicatorCounted() - 1; li_0 >= 0; li_0--)
you are using li_0 as your variable to iterate all.

But, in the body, you are using just "i"

if ( i <= AlertBar && Alerts) // added

i think you should change this to li_0.

there was another line

Basically, if you change this
if ( li_0 <= AlertBar && Alerts) , it should work.. ( You might want to change all li_0 to something else like "counter" as this was randomly generated code.



if ( i <= AlertBar && Alerts) // added

In addition, it is better to write this way for easier reading.

if ( ( i <= AlertBar) && Alerts )




FYI, I didn't test out..
I still don't know where is the Holy Grail
1
  • Post #3
  • Quote
  • Dec 13, 2019 12:02am Dec 13, 2019 12:02am
  •  BlueRain
  • Joined Sep 2019 | Status: Member | 828 Posts
I have feeling this code was generated by reverse engineering from ex4 file.
I still don't know where is the Holy Grail
1
  • Post #4
  • Quote
  • Dec 13, 2019 12:04am Dec 13, 2019 12:04am
  •  Burton
  • | Joined Jan 2008 | Status: Member | 215 Posts
Hello BlueRain, thank you for your helpful reply,

I made your suggested code changes, yet the Alert continues constantly...non stop alerts...lol

extern bool Alerts = TRUE;
extern int AlertBar = 1;

for (int li_0 = Bars - IndicatorCounted() - 1; li_0 >= 0; li_0--) {

if ( li_0 <= AlertBar && Alerts)
Alert(WindowExpertName(), ": ", _Symbol, " ", _Period, "SELL");
g_ibuf_80[li_0] = -1;
g_ibuf_84[li_0] = 1;
}
}
  • Post #5
  • Quote
  • Edited at 4:14am Dec 13, 2019 3:52am | Edited at 4:14am
  •  BlueRain
  • Joined Sep 2019 | Status: Member | 828 Posts
Reason it alert constantly is that it has to go all the bars every time there is new tick.
Whenever there is new tick, whole loop will rerun again and generate whole lot of alerts.

I looked into your code and you don't have any mean to store and check if alert happened before on that new bar.

You will need to set some variable to record what was last time it alerted and record whenever there is new bar.
like

static datetime previousAlertTime;
previousAlertTime = Time[0]; //this is latest bar open time


Now, check if time[0] is newer than last time.




if(Time[0]>previousAlertTime)
{
//new bar time, save this.
previousAlertTime=Time[0];

//your checking code for alert
if (condition == true) Alert( );


}


Time[0] shows open time of each bar. So, basically, you only check and alert 1 time per each bar.
Otherwise, it will generate alert on all bars.. endlessly.

datetime Time[]
Series array that contains open time of each bar of the current chart. Data like datetime represent time, in seconds, that has passed since 00:00 a.m. of 1 January, 1970.







Typically, you should check if there is new bar, if new bar...then check and alert.
Once you did alert, you have to record time so it won't do alert anymore until next bar.

There are a lot of MT4 indicator with alert - take those as sample and adjust your code a bit.

Steps are same:


<Update>: I made quick code change and it should work .. added those new logic to check new bar time.
Attached File
File Type: mq4 HP_DIFF_Alerts.mq4   5 KB | 76 downloads
I still don't know where is the Holy Grail
1
  • Post #6
  • Quote
  • Dec 13, 2019 4:33am Dec 13, 2019 4:33am
  •  BlueRain
  • Joined Sep 2019 | Status: Member | 828 Posts
I assume you want alert when there is color of bar change - which is trend changed.

Typically for this kind of alert, you should have some logic if color of bar is changed to another color like green bar changed to red bar.
As is now, Code just alert when new bar shows up.. ( you just added alert before this happens and no logic to detect trend changed )
I still don't know where is the Holy Grail
1
  • Post #7
  • Quote
  • Dec 13, 2019 3:19pm Dec 13, 2019 3:19pm
  •  Burton
  • | Joined Jan 2008 | Status: Member | 215 Posts
Hello BlueRain, yes wanting an alert when bar color changes, thank you for your replies, and help, I will continue code changing today, best wishes

Quoting BlueRain
Disliked
I assume you want alert when there is color of bar change - which is trend changed. Typically for this kind of alert, you should have some logic if color of bar is changed to another color like green bar changed to red bar. As is now, Code just alert when new bar shows up.. ( you just added alert before this happens and no logic to detect trend changed )
Ignored
  • Post #8
  • Quote
  • Edited at 4:18pm Dec 13, 2019 3:55pm | Edited at 4:18pm
  •  BlueRain
  • Joined Sep 2019 | Status: Member | 828 Posts
I had some free time this morning to fix your code as I won't do any more trading until new year.

It now checks if trend is changed ( basically compare two buffer value of previous two bars ) and alerts.
Plus, I have renamed few variable for easier reading.

I am sure you can figure it out.

Please test out
Attached File
File Type: mq4 HP_DIFF_Alerts.mq4   6 KB | 63 downloads
I still don't know where is the Holy Grail
1
  • Post #9
  • Quote
  • Dec 13, 2019 4:59pm Dec 13, 2019 4:59pm
  •  Burton
  • | Joined Jan 2008 | Status: Member | 215 Posts
Hello BlueRain, very kind of you, many thank yous, yes seems to be working perfectly

I added a sound file to the alerts

Thank you again for your generosity, best wishes
Attached File
File Type: mq4 HP_DIFF_Alerts.mq4   7 KB | 71 downloads
  • Post #10
  • Quote
  • Dec 13, 2019 5:15pm Dec 13, 2019 5:15pm
  •  Burton
  • | Joined Jan 2008 | Status: Member | 215 Posts
Hello BlueRain, oh! ok yes I will make that change and test when the market is open on Monday, thank you
  • Post #11
  • Quote
  • Dec 13, 2019 5:19pm Dec 13, 2019 5:19pm
  •  BlueRain
  • Joined Sep 2019 | Status: Member | 828 Posts
fix like -

if (UpTrend[AlertBar] > UpTrend[AlertBar + 1]) //trend up
{ Alert(WindowExpertName(), ": ", _Symbol, " ", _Period, " UPTREND ", " BUY");
if (AlertsSound) PlaySound(SoundFile); //"stops.wav" //"news.wav" //"alert2.wav" //"expert.wav"
}
else if ( UpTrend[AlertBar] < UpTrend[AlertBar + 1] )
{ Alert(WindowExpertName(), ": ", _Symbol, " ", _Period, " DOWNTREND "," SELL");
if (AlertsSound) PlaySound(SoundFile); //"stops.wav" //"news.wav" //"alert2.wav" //"expert.wav"
}
Attached File
File Type: mq4 HP_DIFF_Alerts.mq4   7 KB | 74 downloads
I still don't know where is the Holy Grail
1
  • Post #12
  • Quote
  • Dec 13, 2019 8:09pm Dec 13, 2019 8:09pm
  •  Burton
  • | Joined Jan 2008 | Status: Member | 215 Posts
Hello BlueRain, thank you for that sound coding fix,

You may have noticed that this HP line is similar, not the same, yet similar to the (T_S_R)-Signal Line.mq4 indicator you posted,

best wishes
  • Post #13
  • Quote
  • Dec 13, 2019 8:25pm Dec 13, 2019 8:25pm
  •  Burton
  • | Joined Jan 2008 | Status: Member | 215 Posts
Here are the complete set of mq4 indicator files for those interested
Attached Files
File Type: mq4 HP.mq4   2 KB | 133 downloads
File Type: mq4 HP_DIFF.mq4   2 KB | 128 downloads
File Type: mq4 HP_DIFF_Alerts.mq4   7 KB | 152 downloads
File Type: mq4 (T_S_R)-Signal Line.mq4   21 KB | 137 downloads
  • Post #14
  • Quote
  • Edited at 10:17pm Dec 13, 2019 10:06pm | Edited at 10:17pm
  •  BlueRain
  • Joined Sep 2019 | Status: Member | 828 Posts
I agree that HP and TSR has similar approach... using some kind of filter to smooth out MAs and provide trend changes.
Where TSR is using ZigZag style to show Up/Down Peaks and HP is using more of middle line.
TSR stands for Trend/Support/Resistance so it is trying to give max points. When Trend ends, it either becomes R or S.

After quick check, it seems HP has more smoother line which gives better longer /stronger trend indication and TSR has more accurate on shorter term reversal lines with more up/down. combined together, it might work together nicely.

I have attached indicator which should give bar style for TSR signal.

if you don't like TSR's thick vertical line, change to 1 so it should match with HP vertical line style like

SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,1,Green);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,1,Red);
Attached Image (click to enlarge)
Click to Enlarge

Name: Screenshot3.png
Size: 35 KB
Attached File
File Type: mq4 (T_S_R)-Signal Line-seperate.mq4   16 KB | 111 downloads
I still don't know where is the Holy Grail
1
  • Post #15
  • Quote
  • Dec 13, 2019 11:17pm Dec 13, 2019 11:17pm
  •  Burton
  • | Joined Jan 2008 | Status: Member | 215 Posts
Hello BlueRain, thank you for the Bar converter indicator, yes an interesting combo to play with

best wishes
  • Post #16
  • Quote
  • Edited at 6:00pm Dec 29, 2019 4:34pm | Edited at 6:00pm
  •  BlueRain
  • Joined Sep 2019 | Status: Member | 828 Posts
Updae 2:
Found some bug.. fixed now.
Try new attached HP.

Update:

This is HP.mq4 with added features as requested by Ray.

//+------------------------------------------------------------------+
//| HP.mq4 |
//| Ver: V2 |
//| Date: 12/29/2019 |
//| By: BlueRain |
//| Added colored Uptrend/Downtrend |
//| Added Arrows, Alerts, Email |
//| No Change to HP line function itself made |
//| See details on
//| https://www.forexfactory.com/showthr...&reply=1#reply |
//+------------------------------------------------------------------+

Some of features code are borrowed from HalftTrend3.mq4 (alerts,emails etc) which has identical requirement as HP v2 requirement.

HP_DIFF_Alerts.mq4 should work without any change as it is still calling HP.mq4 arryindexed 0 which is hpf values.

Happy New Year..
Attached Image (click to enlarge)
Click to Enlarge

Name: HP with arrow and color.JPG
Size: 99 KB
Attached File
File Type: mq4 HP.mq4   9 KB | 78 downloads
I still don't know where is the Holy Grail
1
  • Post #17
  • Quote
  • Dec 29, 2019 5:45pm Dec 29, 2019 5:45pm
  •  Burton
  • | Joined Jan 2008 | Status: Member | 215 Posts
Thank you BlueRain for your generous coding, Happy New Year

Quoting BlueRain
Disliked
Update: This is HP.mq4 with added features as requested by Ray. //+------------------------------------------------------------------+ //| HP.mq4 | //| Ver: V2 | //| Date: 12/29/2019 | //| By: BlueRain | //| Added colored Uptrend/Downtrend | //| Added Arrows, Alerts, Email | //| No Change to HP line function itself made | //| See details on //| https://www.forexfactory.com/showthr...&reply=1#reply | //+------------------------------------------------------------------+ Some of features code are borrowed from HalftTrend3.mq4...
Ignored
  • Post #18
  • Quote
  • Edited at 6:49pm Dec 29, 2019 6:01pm | Edited at 6:49pm
  •  BlueRain
  • Joined Sep 2019 | Status: Member | 828 Posts
Found a minor bug - and fixed.
Try a new one.

this part is rolled back to original
for(int n=0;n<nobs;n++) xn[n]=Close[n];
HPF(nobs,lambda,xn,hpf);

2nd Bug fix:
some arrow was redrawn as it was trying to draw from last point.
fixed by completely go over all data every thick.

- In need of looking a bit more on arrow repainting while still in same trend.
this one has improved but I will update later I feel it needs some change.
Not a big functional blocker but still some eye sore.

Updated one more time.
Attached File
File Type: mq4 HP.mq4   9 KB | 63 downloads
I still don't know where is the Holy Grail
  • Post #19
  • Quote
  • Dec 29, 2019 6:10pm Dec 29, 2019 6:10pm
  •  Burton
  • | Joined Jan 2008 | Status: Member | 215 Posts
Great thank you BlueRain

Quoting BlueRain
Disliked
Found a minor bug - and fixed. Try a new one. this part is rolled back to original for(int n=0;n<nobs;n++) xn[n]=Close[n]; HPF(nobs,lambda,xn,hpf); {file}
Ignored
  • Post #20
  • Quote
  • Dec 29, 2019 7:12pm Dec 29, 2019 7:12pm
  •  BlueRain
  • Joined Sep 2019 | Status: Member | 828 Posts
Quoting Burton
Disliked
Great thank you BlueRain {quote}
Ignored
Can you try this one and let me know?
I have moved arrow handling block to its own block.
It seems to be working but if you find any issue, please let me know.
Attached File
File Type: mq4 HP.mq4   9 KB | 74 downloads
I still don't know where is the Holy Grail
  • Platform Tech
  • /
  • Help Please with Indicator Alert Code
  • Reply to Thread
    • Page 1 2
    • Page 1 2
0 traders viewing now
  • More
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2021