Coding help - page 173

 

hi coders,

i have created a very simple indicator which shows an alert when the last bar is above the sma10 or below it. nothing more. but i would like to check it in 3 different time frames. i have never worked with mtf-indicators and so i have some problems with it. this version checks the m1, m5 and m15 chart. it works fine but there is the problem that the alert is displayed on every tick and not just once in the timeframe the conditions are met.

i would be happy if anybody helped me with that. i think it could only be a syntax-problem..

thank you!

Files:
test.mq4  3 kb
 

Hi,

I have to ask again, because I can't find an error, but I am getting only the wrong values :-(

Perhaps anybody see my failure?!

This it the code from the indicator

#property indicator_chart_window

#property indicator_buffers 5

double WidestChannel_high[];

double InsideChannel_high[];

double StandardDeviation[];

double InsideChannel_low[];

double WidestChannel_low[];

extern int STD.Rgres.period=0; /*default 0 means the channel will use the open

time from "x" bars back on which ever time period

the indicator is attached to. one can change to 1,5,

15,30,60...etc to "lock" the start time to a specific

period, and then view the "locked" channels on a different time period...*/

extern int STD.Rgres.length=56; // bars back regression begins

extern double STD.Rgres.width=1.618;// widest channel

extern double STD.width=0.618; // inside channel

int init()

{

SetIndexBuffer(0,WidestChannel_high);

SetIndexLabel(0,"WidestChannel_high");

SetIndexBuffer(1,InsideChannel_high);

SetIndexLabel(1,"InsideChannel_high");

SetIndexBuffer(2,StandardDeviation);

SetIndexLabel(2,"StandardDeviation");

SetIndexBuffer(3,InsideChannel_low);

SetIndexLabel(3,"InsideChannel_low");

SetIndexBuffer(4,WidestChannel_low);

SetIndexLabel(4,"WidestChannel_low");

return(0);

}

int deinit() {

ObjectDelete("regression channel");ObjectDelete("std channel");return(0);

}

int start() {

int counted_bars=IndicatorCounted(),limit, iTF;

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//to refresh properly delete old objects...

ObjectDelete("regression channel");ObjectDelete("std channel");

//widest channel

ObjectCreate("regression channel",OBJ_STDDEVCHANNEL,0,iTime(Symbol(),STD.Rgres.period,STD.Rgres.length),

Close[STD.Rgres.length],Time[0],Close[0]);

ObjectSet("regression channel",OBJPROP_DEVIATION,STD.Rgres.width);

ObjectSet("regression channel",OBJPROP_COLOR,Orange);

ObjectSet("regression channel",OBJPROP_RAY,true);

//inside channel

ObjectCreate("std channel",OBJ_STDDEVCHANNEL,0,iTime(Symbol(),STD.Rgres.period,STD.Rgres.length),

Close[STD.Rgres.length],Time[0],Close[0]);

ObjectSet("std channel",OBJPROP_DEVIATION,STD.width);

ObjectSet("std channel",OBJPROP_COLOR,Olive);

ObjectSet("std channel",OBJPROP_RAY,true);

for(int i=0; i<limit; i++)

{

double dev = iStdDev(NULL,STD.Rgres.period,STD.Rgres.length,0,MODE_SMA,PRICE_CLOSE,i);

double innerWidth = STD.width*dev;

double outerWidth = STD.Rgres.width*dev;

double price = ObjectGetValueByShift("std channel", i);

WidestChannel_high= price + outerWidth/2;

InsideChannel_high= price + innerWidth/2;

StandardDeviation= price;

InsideChannel_low= price - innerWidth/2;

WidestChannel_low= price - outerWidth/2;

}

return(0);}
 
sunshineh:
Hi,

I have to ask again, because I can't find an error, but I am getting only the wrong values :-(

Perhaps anybody see my failure?!

This it the code from the indicator

#property indicator_chart_window

#property indicator_buffers 5

double WidestChannel_high[];

double InsideChannel_high[];

double StandardDeviation[];

double InsideChannel_low[];

double WidestChannel_low[];

extern int STD.Rgres.period=0; /*default 0 means the channel will use the open

time from "x" bars back on which ever time period

the indicator is attached to. one can change to 1,5,

15,30,60...etc to "lock" the start time to a specific

period, and then view the "locked" channels on a different time period...*/

extern int STD.Rgres.length=56; // bars back regression begins

extern double STD.Rgres.width=1.618;// widest channel

extern double STD.width=0.618; // inside channel

int init()

{

SetIndexBuffer(0,WidestChannel_high);

SetIndexLabel(0,"WidestChannel_high");

SetIndexBuffer(1,InsideChannel_high);

SetIndexLabel(1,"InsideChannel_high");

SetIndexBuffer(2,StandardDeviation);

SetIndexLabel(2,"StandardDeviation");

SetIndexBuffer(3,InsideChannel_low);

SetIndexLabel(3,"InsideChannel_low");

SetIndexBuffer(4,WidestChannel_low);

SetIndexLabel(4,"WidestChannel_low");

return(0);

}

int deinit() {

ObjectDelete("regression channel");ObjectDelete("std channel");return(0);

}

int start() {

int counted_bars=IndicatorCounted(),limit, iTF;

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//to refresh properly delete old objects...

ObjectDelete("regression channel");ObjectDelete("std channel");

//widest channel

ObjectCreate("regression channel",OBJ_STDDEVCHANNEL,0,iTime(Symbol(),STD.Rgres.period,STD.Rgres.length),

Close[STD.Rgres.length],Time[0],Close[0]);

ObjectSet("regression channel",OBJPROP_DEVIATION,STD.Rgres.width);

ObjectSet("regression channel",OBJPROP_COLOR,Orange);

ObjectSet("regression channel",OBJPROP_RAY,true);

//inside channel

ObjectCreate("std channel",OBJ_STDDEVCHANNEL,0,iTime(Symbol(),STD.Rgres.period,STD.Rgres.length),

Close[STD.Rgres.length],Time[0],Close[0]);

ObjectSet("std channel",OBJPROP_DEVIATION,STD.width);

ObjectSet("std channel",OBJPROP_COLOR,Olive);

ObjectSet("std channel",OBJPROP_RAY,true);

for(int i=0; i<limit; i++)

{

double dev = iStdDev(NULL,STD.Rgres.period,STD.Rgres.length,0,MODE_SMA,PRICE_CLOSE,i);

double innerWidth = STD.width*dev;

double outerWidth = STD.Rgres.width*dev;

double price = ObjectGetValueByShift("std channel", i);

WidestChannel_high= price + outerWidth/2;

InsideChannel_high= price + innerWidth/2;

StandardDeviation= price;

InsideChannel_low= price - innerWidth/2;

WidestChannel_low= price - outerWidth/2;

}

return(0);}

sunshineh,

You do not have to divide deviation by 2 to get the high and the low - remove the "/2" part and it should be OK provided that the middle price is OK. Width of the channel is always constant : current standard reviation should be used for the with, not some other value. And the last, as far as I see, ObjectGetValueByShift("std channel", i); does not work on standard deviation channel as it works on trendlines. What value is it returning I do no know (see the attached indicator and you will see why I say that I do not know what is that price)

Files:
_test_4.mq4  3 kb
 

HI mladen,

i attach a sample indicator using internal preset symbols, quite difficult for me to comprehend inside , is it possible to get some hints from this indicator to adapt to my indicators or/& yours indicators to prevent repaint or refresh shift line problem/tick problems or make some kind of sy nergy? Thanks for looking.

 
kenwa:
HI mladen, i attach a sample indicator using internal preset symbols, quite difficult for me to comprehend inside , is it possible to get some hints from this indicator to adapt to my indicators or/& yours indicators to prevent repaint or refresh shift line problem/tick problems or make some kind of sy nergy? Thanks for looking.

kenwa

I do not work on decompiled stuff. Sorry

 
mladen:
kenwa I do not work on decompiled stuff. Sorry

ok, then i remove it, but interestingly why no one view it but you can know it is decomplie stuff

 
kenwa:
ok, then i remove it, but interestingly why no one view it but you can know it is decomplie stuff

Everybody that knows a bit about coding knows that it is a decompiled code

And even if you do not know anything at all about any coding, when you have a thing like this :

/*

Generated by EX4-TO-MQ4 decompiler FREEWARE V4.0.451.1 [-]

Website: MetaTrader 5 Trading Platform / MetaQuotes Software Corp.

E-mail : support@metaquotes.net

*/

written in the first few lines of the indicator you posted it seems rather obvious that anybody could see that it is a decompiled code, so, please ...

All the best

 

mladen, my code is not decompiled. maybe you would like to have a short look at it?

 
Marbo:
mladen, my code is not decompiled. maybe you would like to have a short look at it?

Marbo

You can do something like in the attached one. It will alert you once per target time frame bar or when the state (type of the alert) changes. If you wish to ignore type, the skip the type check in the doAlert procedure. If you wish to skip the time check (in which case only type would be checked) then skip the time check in the doAlert procedure

Files:
test_4.mq4  3 kb
 

Hi mladen,

You will probably recall that I asked for some help with an MA cross EA last week. and of course referred improperly to the Elite section. Where can you suggest I should ask for this please. I have looked and not found an obvious answer. To refresh your memory this was the spec:

1.SMA EMA cross

2.On close of candle

3.OCO with place new order in new direction

4.Ability to adjust slippage

5.Audible signal of cross

6.Cross is not a real cross without a settable pip gap

7.If possible in-candle monitoring so if a candle is more than X times the ATR (settable number to count), an order is placed with an alarm in direction of this candle, and likewise to close an order but then not start a new one

8. preferably if an order is placed as in 7 to sound an alarm

9.Reliability of cross is paramount. In my charts - FXCM, Vantage, FX Choice - some EAs, including Universal Cross do not take trades or are too late

10. Settable SL but can leave out if not needed

11.Trailing Stop

12.SL goes to breakeven automatically after X pips profit

13. Max open trades number

14. magic number

Regards

Jeff

Reason: