Why does this return 0?

 

I am using the iSAR-Function in my EA. It is returning an accurate result.
When, however, I try to add something, it returns 0:

double SAR_C = iSAR(NULL,0,0.02,0.2,1)+0.00005;
Print("SAR_C: "+SAR_C);

This prints "SAR_C: 0.00000". Why is this? How can I prevent this/add something to the iSAR-Result?

 
ChrisK99:

I am using the iSAR-Function in my EA. It is returning an accurate result.
When, however, I try to add something, it returns 0:

double SAR_C = iSAR(NULL,0,0.02,0.2,1)+0.00005;
Print("SAR_C: "+SAR_C);

This prints "SAR_C: 0.00000". Why is this? How can I prevent this/add something to the iSAR-Result?

I obtain this result on EURUSD H1:

2013.06.07 17:50:49    testing EURUSD,H1: SAR_C: 1.32855000

On what chart/timeframe did you run your code ?

 

That's strange. I am using this in the strategy tester on M5, EURUSD.

Edit: Everything else seems to work perfectly. 

 
ChrisK99:

That's strange. I am using this in the strategy tester on M5, EURUSD.

Edit: Everything else seems to work perfectly. 

Ha, in the strategy tester, I tried it on a demo account. Are you sure there is a value for iSAR for the candle corresponding to your shift (1) ?
 

Yes, iSAR(NULL,0,0.02,0.2,1) was originally (still is in another part) appointed to another variable that's giving out the right result. When I use that variable in the EA, everything works out, but not when I try to add (or substract) something.

 
ChrisK99:

Yes, iSAR(NULL,0,0.02,0.2,1) was originally (still is in another part) appointed to another variable that's giving out the right result. When I use that variable in the EA, everything works out, but not when I try to add (or substract) something.

Can you post some code to demonstrate your issue ?
 

Sure. This is the relevant part:

double SAR_Current   = iSAR(NULL,0,0.02,0.2,1);

double SAR_C = iSAR(NULL,0,0.02,0.2,1)+0.00005;
   Print("SAR_Current: "+SAR_Current+"  SAR_C: "+SAR_C);

This prints at one point: 

SAR_Current: 1.33079513 SAR_C: 0.000000000 (give or take a couple of 00).

Same, when I have SAR_Current in SAR_C instead of the iSAR-function..

 

Are you sure you don't have any modification of SAR_C in your original code between these 2 lines

double SAR_C = iSAR(NULL,0,0.02,0.2,1)+0.00005;
   Print("SAR_Current: "+SAR_Current+"  SAR_C: "+SAR_C);
 

Yes, the only thing between these 2 lines is a bool function that checks whether there is a new candle. No other changes to (or even use of) SAR_C anywhere else, either.

 
ChrisK99:

Sure. This is the relevant part:

This prints at one point: 

SAR_Current: 1.33079513 SAR_C: 0.000000000 (give or take a couple of 00).

Same, when I have SAR_Current in SAR_C instead of the iSAR-function..

Please copy and paste what you actually have in your code and what is output to avoid errors and misleading people   . . .
 

Complete code:

double SAR_Current   = iSAR(NULL,0,0.02,0.2,1); 
                       
			double SAR_C = iSAR(NULL,0,0.02,0.2,1)+0.00005;
                        if(IsNewCandle_Current())
                           {
                           Print("SAR_Current: "+SAR_Current+"  SAR_C: "+SAR_C);
                           if(OrderStopLoss()>SAR_Current && SAR_Current!=0)
                              {
                              Print("SAR_Current < Stop Loss");
                              OrderModify(OrderTicket(),OrderOpenPrice(),SAR_Current,OrderTakeProfit(),0,CLR_NONE);
                              }
                           }

This is the output:

2013.06.07 18:25:34 2011.01.05 01:10  My EA 5 EURUSD,M5: SAR_Current: 1.33131122  SAR_C: 0.00000000
2013.06.07 18:25:30 2011.01.05 01:05  My EA 5 EURUSD,M5: SAR_Current: 1.33108859  SAR_C: 0.00000000
2013.06.07 18:25:26 2011.01.05 01:00  My EA 5 EURUSD,M5: SAR_Current: 1.33093371  SAR_C: 0.00000000
2013.06.07 18:25:23 2011.01.05 00:55  My EA 5 EURUSD,M5: SAR_Current: 1.33079513  SAR_C: 0.00000000
2013.06.07 18:25:22 2011.01.05 00:50  My EA 5 EURUSD,M5: SAR_Current: 1.33067681  SAR_C: 0.00000000
2013.06.07 18:25:21 2011.01.05 00:45  My EA 5 EURUSD,M5: SAR_Current: 1.33058610  SAR_C: 0.00000000