Need help with my code, my iSar(...) code is not working...

 

Sorry, I'm a newbie trying to learn how to code my own EA. I'm trying to simply push the string, "Top" or "Bottom" to my variable, "SAR_DIRECTION" when the dot is on the top or bottom of the candle on the 1hr chart. It now says top...even though it's not on the top. It usually is correct only the 1st time ran...and then it does not update.


Here is my code:

double SAR_PRICE = iSAR(NULL,PERIOD_H1,0.02,0.2,0)

double CURRENT_PRICE = Bid;

string SAR_DIRECTION;


if (SAR_PRICE > CURRENT_PRICE)
SAR_DIRECTION = "TOP";
else
SAR_DIRECTION = "BOTTOM";

Comment("DIRECTION: " + SAR_DIRECTION ); // to display this on the main screen so I know it is correct

I also tried this and it's not working correctly...

if(SAR_PRICE > CURRENT_PRICE)
SAR_DIRECTION = "TOP";
if (SAR_PRICE < Ask)
SAR_DIRECTION = "BOTTOM";

Comment("DIRECTION: " + SAR_DIRECTION ); // to display this on the main screen so I know it is correct

Would "Bid" be the correct reserved variable to use?
 
Yes.
 
Roger:
Yes.

Well...my question is why it's not working correctly. It's not giving me accurate results.

 

Add to your comment func:

Comment("DIRECTION: " + SAR_DIRECTION," Bid - ",Bid," indic - ",SAR_PRICE );

and you can control all variables.

 

The commenting works fine...the problem is that it's not telling the truth. I think there's an issue with the logic of how it decides if the dot is on the top or the bottom. Again, right now the comment is telling me that it's on the bottom and yet the dot is actually on the top. That's why I posted my code...I wanted to see if anyone else could see what I'm doing wrong.


Again, it's not a problem of the comment...it's a problem with the logic behind the decision of top/bottom. What is wrong with the logic that I have?

 

if (SAR_PRICE > CURRENT_PRICE)

Should be:

if(NormalizeDouble(SAR_PRICE,4) > NormalizeDouble(CURRENT_PRICE,4))

 
USForexGuy:

if (SAR_PRICE > CURRENT_PRICE)

Should be:

if(NormalizeDouble(SAR_PRICE,4) > NormalizeDouble(CURRENT_PRICE,4))

Interesting! So what does tihs "NormalizeDouble" do? Also, I realized what was causing all my problems...it's because iSAR(NULL,PERIOD_H1,0.02,0.2,0) the Parabolic sar I was using in my indicator had .2, .2 and the function I was calling was using .02, .2...which caused the prices to be correct only sometimes...and other times it would go unchanged. After I made that correction it worked fine...but I'm still curious as to what benefits the "NormalizeDouble" does...or rather how that entire statement is different (sorry...I'm still learning and it looks complex).


Thanks!!!!

 
rortiz77:

Interesting! So what does tihs "NormalizeDouble" do? Also, I realized what was causing all my problems...it's because iSAR(NULL,PERIOD_H1,0.02,0.2,0) the Parabolic sar I was using in my indicator had .2, .2 and the function I was calling was using .02, .2...which caused the prices to be correct only sometimes...and other times it would go unchanged. After I made that correction it worked fine...but I'm still curious as to what benefits the "NormalizeDouble" does...or rather how that entire statement is different (sorry...I'm still learning and it looks complex).


Thanks!!!!

 

sir rortiz77, im also a newbie trying to learn, i have came across this normalizeDouble(), the function is if im not mistaken is to correct the count of the decimal point. lets say the sar price value is 1.2345, so if

you use normalizeDouble - NormalizeDouble(SAR_PRICE,2)    - the output would then become 1.23 ,  because i set the count to '2' in (SAR_PRICE,2)

i hope it helps :)

anyway im also trying to use iSAR in my programming code, i have problem back then but after i read your comment here it solve a bit of my problem.. thanks! 

 
springyard:

sir rortiz77, im also a newbie trying to learn, i have came across this normalizeDouble(), the function is if im not mistaken is to correct the count of the decimal point. lets say the sar price value is 1.2345, so if

you use normalizeDouble - NormalizeDouble(SAR_PRICE,2)    - the output would then become 1.23 ,  because i set the count to '2' in (SAR_PRICE,2)

i hope it helps :)

anyway im also trying to use iSAR in my programming code, i have problem back then but after i read your comment here it solve a bit of my problem.. thanks! 

Why has it taken you  4 years to answer this question ?  do you think the OP will still be waiting for an answer ?  please do not dredge up old threads unless you have a very good reason,  it seems you do not.

 

Thread started - 2009.06.09 

Reason: