Any one know the problem here?

 

hi all

iam making my first indicator

but ther is some thing wrong

here is the code

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 Aqua

#property indicator_color2 Red

//---- input parameters

extern int rsiPeriod = 10;

//---- buffers

double buySignal[];

double sellSignal[];

static datetime lastAlertTime;

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

SetIndexStyle(0, DRAW_ARROW);

SetIndexStyle(1, DRAW_ARROW);

SetIndexBuffer(0, buySignal);

SetIndexBuffer(1, sellSignal);

SetIndexEmptyValue(0, 0.0);

SetIndexEmptyValue(1, 0.0);

SetIndexArrow(0, 233);

SetIndexArrow(1, 234);

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

for (int i = Bars - IndicatorCounted(); i >= 0; i--)

{

double rsi1 = iRSI(NULL, 0, rsiPeriod, PRICE_CLOSE, i+1);

double rsi2 = iRSI(NULL, 0, rsiPeriod, PRICE_CLOSE, i+2);

double displacement = GetArrowDisplacement(i);

if (rsi1>40&&rsi250&&rsi2<50)

{

buySignal = Low - displacement;

}

if (rsi150||rsi140)

{

sellSignal = High + displacement;

}

}

return(0);

}

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

void SignalAlert(string message)

{

if (Time[0] != lastAlertTime)

{

Alert(message, Symbol(), ", ", Period(), " Minutes chart");

lastAlertTime = Time[0];

}

}

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

double GetArrowDisplacement(int i)

{

double high = iMA(NULL, 0, 10, 0, MODE_SMA, PRICE_HIGH, i);

double low = iMA(NULL, 0, 10, 0, MODE_SMA, PRICE_LOW, i);

return ((high - low) / 2);

as you see in the pic when the RSI line across level 50 and 40 it give me two arrow!!

is there is any code to solve this?

 
(rsi150||rsi140)

its doing as its told, first arrow the rsi at close is less than 50 but the previous was greater than 50, the second arrow is the same but with 40

 

What's wrong?

I can not see what you mean by wrong.

Each arrow represents the up or down passage of the 40 and 50 levels you have defined.

See attached picture. If you still do not agree, mark the locations where you have your doubts.

Cheers

Herbert

Files:
testindi.gif  20 kb
 

i mean the problem is when rsi gives me buy signal it gives many arrows

many arrows tell me keep buy signal]

i want one arrow only says to me buy. then when rsi gives sell signal i want one arrow appears only.

u can notice here many arrows tell me buy i just want one arrow.

i know my program is making the arrows alot i want a code or some thing to not

the same arrows appears many time

 

Mod

OK, here you have the modified result.

It now only switches between the Buy and Sell status. (Red - Blue - Red - Blue etc.)

Cheers

Herbert

Files:
testindi.mq4  3 kb
 
 

Please explain first

gm6510:
thank you HerbertH

i added MA to my indicator but there is problem can you help me?

the code

With pleasure, but it's not a matter of fixing, you went back to the original coding and replaced 1 of the RSI values for 2 SMA's. By doing that you have removed the logic for detecting the RSI crossing.

Please explain what you want to achieve and then I can help or modify the code for you.

 

hi

my indicator consists of two indicator

rsi and moving average

i want to get buy signal when rsi >50 and ema5 croosing ema15

i want to get sell signal when rsi<50 and ema15 crosing ema5

 

Result

gm6510:
hi

my indicator consists of two indicator

rsi and moving average

i want to get buy signal when rsi >50 and ema5 croosing ema15

i want to get sell signal when rsi<50 and ema15 crosing ema5

Find attached the indicator, now behaving like you described.

Cheers

Files:
testindi2.mq4  4 kb
 

HerbertH

Good work....

 

lots of false signals...