Please fix this indicator or EA - page 47

 

And if you want to make an indicator that will show % (the relative position of the price to bollinger bands as a %) here is one version that already exists : https://www.mql5.com/en/forum/173534

k3rn3l:
I have thought of something like this:

#property indicator_separate_window

#property indicator_buffers 8

#property indicator_color1 Blue

#property indicator_color2 Red

#property indicator_color3 Green

#property indicator_color4 Yellow

#property indicator_color5 Blue

//---- input parameters

extern int AtrBandPeriod=10;

extern int BandsShift=0;

extern double BandsDeviations=2.0;

//---- buffers

double AtrBuffer[];

double TempBuffer[];

double Matr[];

double MovingBuffer[];

double UpperBuffer[];

double LowerBuffer[];

double Bandwidth[];

double MaBandwidth[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

SetIndexBuffer(0,AtrBuffer); SetIndexDrawBegin(0,AtrBandPeriod);

SetIndexBuffer(1,TempBuffer); SetIndexDrawBegin(1,AtrBandPeriod);

SetIndexBuffer(2,Matr); SetIndexDrawBegin(2,AtrBandPeriod);

SetIndexStyle(3, DRAW_LINE); SetIndexDrawBegin(3,AtrBandPeriod+BandsShift);

SetIndexBuffer(3,Bandwidth);

SetIndexStyle(4,12); SetIndexDrawBegin(4,AtrBandPeriod+BandsShift);

SetIndexBuffer(4,MovingBuffer);

SetIndexStyle(5,12); SetIndexDrawBegin(5,AtrBandPeriod+BandsShift);

SetIndexBuffer(5,UpperBuffer);

SetIndexStyle(6,12); SetIndexDrawBegin(6,AtrBandPeriod+BandsShift);

SetIndexBuffer(6,LowerBuffer);

SetIndexStyle(7, DRAW_LINE); SetIndexDrawBegin(7,AtrBandPeriod+BandsShift);

SetIndexBuffer(7,MaBandwidth);

IndicatorShortName("ATR("+AtrBandPeriod+")");

return(0);

}

//+------------------------------------------------------------------+

//| Average True Range |

//+------------------------------------------------------------------+

int start()

{

int countedBars = IndicatorCounted();

if (countedBars<0) return(-1);

if (countedBars>0) countedBars--;

int limit = MathMin(Bars-countedBars,Bars-1);

for(int i=limit; i>=0; i--)

if(i==Bars-1)

TempBuffer=High-Low;

else TempBuffer=MathMax(High,Close)-MathMin(Low,Close);

for(i=0; i<limit; i++) AtrBuffer = iMAOnArray(TempBuffer,0,AtrBandPeriod,0,MODE_SMA,i);

for(i=0; i<limit; i++) Matr = iMAOnArray(AtrBuffer,0,AtrBandPeriod,0,MODE_SMA,i);

int k,counted_bars=IndicatorCounted();

double deviation;

double sum,oldval,newres;

Print("here");

if(Bars<=AtrBandPeriod) return(0);

if(counted_bars<1)

for(i=1;i<=AtrBandPeriod;i++)

{

MovingBuffer=EMPTY_VALUE;

UpperBuffer=EMPTY_VALUE;

LowerBuffer=EMPTY_VALUE;

Bandwidth=EMPTY_VALUE;

Print("Buffers cleaned");

}

limit=Bars-counted_bars;

if(counted_bars>0) limit++;

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

MovingBuffer=iMA(NULL,0,AtrBandPeriod,BandsShift,MODE_SMA,PRICE_CLOSE,i);

i=Bars-AtrBandPeriod+1;

if(counted_bars>AtrBandPeriod-1) i=Bars-counted_bars-1;

while(i>=0)

{

sum=0.0;

k=i+AtrBandPeriod-1;

oldval=MovingBuffer;

while(k>=i)

{

newres=Close[k]-oldval;

sum+=newres*newres;

k--;

}

deviation=BandsDeviations*MathSqrt(sum/AtrBandPeriod);

UpperBuffer=oldval+deviation;

LowerBuffer=oldval-deviation;

Bandwidth=MathFloor((UpperBuffer - LowerBuffer)*100);

for(i=0; i<limit; i++) MaBandwidth = iMAOnArray(Bandwidth,0,AtrBandPeriod,0,MODE_SMA,i);

return(0);

}

}

 
mladen:
Try something like this :
#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 Blue

#property indicator_color2 Red

extern int DevPeriod=10;

extern int AvgPeriod=10;

double DevBuffer[];

double AvgBuffer[];

//------------------------------------------------------------------

//

//------------------------------------------------------------------

int init()

{

SetIndexBuffer(0,DevBuffer);

SetIndexBuffer(1,AvgBuffer);

IndicatorShortName("StdDev ("+DevPeriod+")");

return(0);

}

int start()

{

int i,countedBars = IndicatorCounted();

if (countedBars<0) return(-1);

if (countedBars>0) countedBars--;

int limit = MathMin(Bars-countedBars,Bars-1);

for(i=0; i<limit; i++) DevBuffer = iStdDev(NULL,0,DevPeriod,0,MODE_SMA,PRICE_CLOSE,i);

for(i=0; i<limit; i++) AvgBuffer = iMAOnArray(DevBuffer,0,AvgPeriod,0,MODE_SMA,i);

return(0);

}

Thank you...it's this that I need

 

slight modification needed of repainting/recalculating indicator

When this indicator is running it puts an arrow type symbol on the grey line pointing up or down. But as the indicator will repaint/recalculate, that arrow will change.

What I was hoping to get is for the indicator to leave a dot or other symbol on the line when it recalculates/repaints so I can see all of the false calls.

Hope that makes sense and thanks for any help that can be given.

Files:
 
godrich:
When this indicator is running it puts an arrow type symbol on the grey line pointing up or down. But as the indicator will repaint/recalculate, that arrow will change.

What I was hoping to get is for the indicator to leave a dot or other symbol on the line when it recalculates/repaints so I can see all of the false calls.

Hope that makes sense and thanks for any help that can be given.

Not sure if my last post makes sense, so I wanted to see if I could clarify what I am saying.

I don't want to really change how the indicator works, I just want it to leave behind a symbol of some sort (grey dot ?) on the horizontal grey line so that I can see all of the false signals it has given.

thanks again

 

...

godrich, in order to make it a "total repainter" find every line where it assigns 0 to som e buffer and comment it out. Here is an example : this line

MinorCycleBuy[pos + BarNumber - Price1BuyB]=0;[/PHP]

should go like this

[PHP]//MinorCycleBuy[pos + BarNumber - Price1BuyB]=0;

That will prevent it from clearing some previous value and the signal (if there was one before_ should stay on the chart even if it is not valid any more

godrich:
Not sure if my last post makes sense, so I wanted to see if I could clarify what I am saying.

I don't want to really change how the indicator works, I just want it to leave behind a symbol of some sort (grey dot ?) on the horizontal grey line so that I can see all of the false signals it has given.

thanks again
 
mladen:
:)

godrich, in order to make it a "total repainter" find every line where it assigns 0 to som e buffer and comment it out. Here is an example : this line

MinorCycleBuy[pos + BarNumber - Price1BuyB]=0;[/PHP]

should go like this

[PHP]//MinorCycleBuy[pos + BarNumber - Price1BuyB]=0;
That will prevent it from clearing some previous value and the signal (if there was one before_ should stay on the chart even if it is not valid any more

Mladen,

Thanks for the info. I treid to do what you said, or what I thought I should have done, but now the indicator will not load.

Wanted to send you the code with changes but now sure how to include it in my response.

Sorry to be a pain...

 

...

Try this

It should be what you are looking for. Here is how it compares to the "regular" one (on the bottom)

godrich:
Mladen,

Thanks for the info. I treid to do what you said, or what I thought I should have done, but now the indicator will not load.

Wanted to send you the code with changes but now sure how to include it in my response.

Sorry to be a pain...
 
mladen:
Try this

It should be what you are looking for. Here is how it compares to the "regular" one (on the bottom)

mladen,

thanks for that, will give it a try.

take care

 

Help

Hello coders,

could someone help me? I am creating hedging ea and there is a situation when it closes one sell and one buy trade at the same time(in reality very similar). (but with different open time) So far I have managed to find situation of last closed buy and sell trades together. I need counter, how many times it happens in a row.. My code is:

int TradesAdder() {

int last_buy_closed_order_ticket;

int last_sell_closed_order_ticket;

int last_buy_closed_time = 0;

int last_sell_closed_time = 0;

int ct=0;

int LowerLimit = 0;

int HigherLimit = 0;

int SecondsLimit = 20;

bool IsTrue;

for(int k=20;k>=0;k--) {

if(OrderSelect(k,SELECT_BY_POS,MODE_HISTORY) && OrderSymbol() == Symbol() && OrderType()==OP_BUY){

if(OrderCloseTime()>last_buy_closed_time){

last_buy_closed_time=OrderCloseTime();

last_buy_closed_order_ticket=OrderTicket();

}

}

if (OrderSelect(last_buy_closed_order_ticket, SELECT_BY_TICKET, MODE_HISTORY)){

LowerLimit = last_buy_closed_time - SecondsLimit;

HigherLimit = last_buy_closed_time + SecondsLimit;

}

if(OrderSelect(k,SELECT_BY_POS,MODE_HISTORY) && OrderSymbol() == Symbol() && OrderType()==OP_SELL){

if(OrderCloseTime()>last_sell_closed_time){

last_sell_closed_time=OrderCloseTime();

last_sell_closed_order_ticket=OrderTicket();

}

}

}

if (OrderSelect(last_sell_closed_order_ticket, SELECT_BY_TICKET, MODE_HISTORY)){

int SellCloseTime = OrderCloseTime();

}

for (int j=20;j>=0;j--) {

if (LowerLimit<SellCloseTime && SellCloseTime<HigherLimit) {

//IsTrue = true;

ct = ct+1;

}

Print ("ct ",ct);

return(ct);

}

}

I am quessing that it can only select last order and thats why the ct variable (counter) does not work.. (I use Seleck by ticket, which is wrong???) Could anyone help me? Thanks a lot..

 

ATR Levels

Hi mladen,

can you please check attached atr levels indicator. It works fine but the problem is it recalculate the levels in trending market. Is this possible to make the levels fixed? I just need the daily fixed levels. Another question (just my curiosity, it would sound silly ), is there any indicator or system that detect the direction of the whole day at the starting of the day? Thought you're the expert so I could ask you. I really appreciate your help.

Regards,

fx47

Files:
Reason: