Coding help - page 492

 

Alert too much Re: Coding help

Hi Masters Thank for your great work ,I did like to share with everyone this TrendLine Alert,it origin Plays sound when Bid price crosses any trendline or horizontal line you draw , i mod it to popup Alert as well , the only problem with it is it Alert every tick when price(bid) cross a line , i try to mod it to Alert only one each bar when it cross the line by add a time stamp function to the end of it .it complie alright ,but it not work at all (no Alert) . please if you have time to look at it and point me to the right direction.Many many thank!! code i try to add are

static datetime lastbar;

datetime curbar = Time[0];

if(lastbar!=curbar)

{

lastbar=curbar;

return (true);

}

else return(false);

}

 
huang jin:
Hi Masters Thank for your great work ,I did like to share with everyone this TrendLine Alert,it origin Plays sound when Bid price crosses any trendline or horizontal line you draw , i mod it to popup Alert as well , the only problem with it is it Alert every tick when price(bid) cross a line , i try to mod it to Alert only one each bar when it cross the line by add a time stamp function to the end of it .it complie alright ,but it not work at all (no Alert) . please if you have time to look at it and point me to the right direction.Many many thank!! code i try to add are
static datetime lastbar;

datetime curbar = Time[0];

if(lastbar!=curbar)

{

lastbar=curbar;

return (true);

}

else return(false);

}

You are never assigning a value to Close_Time. As soon as you do that, it will alert only once per bar

 

@mladen I found this indicator on TradingView and is possible to make this for mt4?

Here is the source code:

//Created by user ChrisMoody 4-24-2014

//Plots The Majority of Moving Averages

//Defaults to Current Chart Time Frame --- But Can Be Changed to Higher Or Lower Time Frames

//2nd MA Capability with Show Crosses Feature

study(title="CM_Ultimate_MA_MTF", shorttitle="CM_Ultimate_MA_MTF", overlay=true)

//inputs

src = close

useCurrentRes = input(true, title="Use Current Chart Resolution?")

resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=resolution, defval="D")

len = input(20, title="Moving Average Length - LookBack Period")

atype = input(1,minval=1,maxval=7,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA")

cc = input(true,title="Change Color Based On Direction?")

smoothe = input(2, minval=1, maxval=10, title="Color Smoothing - 1 = No Smoothing")

doma2 = input(false, title="Optional 2nd Moving Average")

len2 = input(50, title="Moving Average Length - Optional 2nd MA")

atype2 = input(1,minval=1,maxval=7,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA")

cc2 = input(true,title="Change Color Based On Direction 2nd MA?")

warn = input(false, title="***You Can Turn On The Show Dots Parameter Below Without Plotting 2nd MA to See Crosses***")

warn2 = input(false, title="***If Using Cross Feature W/O Plotting 2ndMA - Make Sure 2ndMA Parameters are Set Correctly***")

sd = input(false, title="Show Dots on Cross of Both MA's")

res = useCurrentRes ? period : resCustom

//hull ma definition

hullma = wma(2*wma(src, len/2)-wma(src, len), round(sqrt(len)))

//TEMA definition

ema1 = ema(src, len)

ema2 = ema(ema1, len)

ema3 = ema(ema2, len)

tema = 3 * (ema1 - ema2) + ema3

avg = atype == 1 ? sma(src,len) : atype == 2 ? ema(src,len) : atype == 3 ? wma(src,len) : atype == 4 ? hullma : atype == 5 ? vwma(src, len) : atype == 6 ? rma(src,len) : tema

//2nd Ma - hull ma definition

hullma2 = wma(2*wma(src, len2/2)-wma(src, len2), round(sqrt(len2)))

//2nd MA TEMA definition

sema1 = ema(src, len2)

sema2 = ema(sema1, len2)

sema3 = ema(sema2, len2)

stema = 3 * (sema1 - sema2) + sema3

avg2 = atype2 == 1 ? sma(src,len2) : atype2 == 2 ? ema(src,len2) : atype2 == 3 ? wma(src,len2) : atype2 == 4 ? hullma2 : atype2 == 5 ? vwma(src, len2) : atype2 == 6 ? rma(src,len2) : tema

out = avg

out_two = avg2

out1 = security(tickerid, res, out)

out2 = security(tickerid, res, out_two)

ma_up = out1 >= out1[smoothe]

ma_down = out1 < out1[smoothe]

col = cc ? ma_up ? lime : ma_down ? red : aqua : aqua

col2 = cc2 ? ma_up ? lime : ma_down ? red : aqua : aqua

circleYPosition = out2

plot(out1, title="Multi-Timeframe Moving Avg", style=line, linewidth=4, color = col)

plot(doma2 and out2 ? out2 : na, title="2nd Multi-TimeFrame Moving Average", style=circles, linewidth=4, color=col2)

plot(sd and cross(out1, out2) ? circleYPosition : na,style=cross, linewidth=5, color=yellow)

 

Screenshot of the indicator:

Files:
pepqyie.png  84 kb
 

Any example of shared file access from multiple code instances?

 
apprentice coder:
Any example of shared file access from multiple code instances?

You can see one example here : https://www.mql5.com/en/forum/175881/page5

 
mladen:
You can see one example here : https://www.mql5.com/en/forum/175881/page5

Got it

 

May i know is that have any ea using indicator "HalfTrend-1.02" ?

I need some example code .

I was try to use this indi for filtering , but i saw that is missing many trade .

I dont know what wrong of that ....

double MA_Signal = iCustom(Symbol(),0,"HalfTrend-1.02",Amplitude,false,false,false,false,false,false,false,0);

double MA_Signal1 = iCustom(Symbol(),0,"HalfTrend-1.02",Amplitude,false,false,false,false,false,false,false,1);

double MA_Signala = iMA(Symbol(),0,UpperMa,UpperMaShift,UpperMaMode,UpperMaPrice,0);

double MA_Signalb = iMA(Symbol(),0,LowerMa,LowerMaShift,LowerMaMode,LowerMaPrice,0);

double Bbands = iCustom(Symbol(),0,"BBands_Stop_v2",Length,Deviation,MoneyRisk,Shift,2);

double Bbands2 = iCustom(Symbol(),0,"BBands_Stop_v2",Length,Deviation,MoneyRisk,Shift,3);

double Ma_Bid_Diff = MathAbs(MA_Signala - Bid)/vPoint;

double Ma_Bid_Diff1 = MathAbs(MA_Signalb - Bid)/vPoint;

if ( MA_Signal>MA_Signala ) if ( Bbands MAOpenDistance && Bid > MA_Signala ) Signal = 1;

if ( MA_Signal1MA_Signal1 ) if ( Ma_Bid_Diff1 > MAOpenDistance && Bid < MA_Signalb ) Signal = -1;
 
stevenpun:
May i know is that have any ea using indicator "HalfTrend-1.02" ?

I need some example code .

I was try to use this indi for filtering , but i saw that is missing many trade .

I dont know what wrong of that ....

double MA_Signal = iCustom(Symbol(),0,"HalfTrend-1.02",Amplitude,false,false,false,false,false,false,false,0);

double MA_Signal1 = iCustom(Symbol(),0,"HalfTrend-1.02",Amplitude,false,false,false,false,false,false,false,1);

double MA_Signala = iMA(Symbol(),0,UpperMa,UpperMaShift,UpperMaMode,UpperMaPrice,0);

double MA_Signalb = iMA(Symbol(),0,LowerMa,LowerMaShift,LowerMaMode,LowerMaPrice,0);

double Bbands = iCustom(Symbol(),0,"BBands_Stop_v2",Length,Deviation,MoneyRisk,Shift,2);

double Bbands2 = iCustom(Symbol(),0,"BBands_Stop_v2",Length,Deviation,MoneyRisk,Shift,3);

double Ma_Bid_Diff = MathAbs(MA_Signala - Bid)/vPoint;

double Ma_Bid_Diff1 = MathAbs(MA_Signalb - Bid)/vPoint;

if ( MA_Signal>MA_Signala ) if ( Bbands MAOpenDistance && Bid > MA_Signala ) Signal = 1;

if ( MA_Signal1MA_Signal1 ) if ( Ma_Bid_Diff1 > MAOpenDistance && Bid < MA_Signalb ) Signal = -1;

Hi Stevenpun,

Two things you can try immediately:

1) Add Print and Comments to see ALL your values...and make sure you are getting all your indicator values properly...

Prints will go in the LOG...and Comments will show on the screen so you can see them immediately.

2) Minimize your "Trade Logic"...and test EACH signal by itself... Then if they work...start combining them back together.

If they don't work...then you've found your problem.

The fewer "nested if's" you have the easier it will be to trace down your problems with no trades...

Also...multiple "if's" filter out most trades...so even when working well...there may not be many trades...

Hope this helps,

Robert

 

Thanks Mladen ,

mladen:
.................. it will alert only once per bar

that is exactly what i want it to do , see the pic i att ,price jump up and down with the line every few tick ,cause the indi alert every time it pass or touch the line .......... what i want it to do is if the bar already have one Alert ,wait for the new bar to give Alert again if it pass the line. But the code I added make the indi not work at all (no Alert) . could you ple have a look again what I did wrong ? and Many many thank!!