I made an indicator to help me with backtesting to show the parabolic sar on different timeframes.
When I use the indicator it works fine, but the EA with the same code basically reacts differently even if the logic applied is the same.
Code: Select all
#property copyright "Copyright 2012, Crappy Code"
#property link "crappycoder@allcrap.com"
#property indicator_separate_window
#property indicator_minimum 0.0
#property indicator_maximum 2.0
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
extern int thickness = 1;
extern int tmf_1 = 1440;
extern int tmf_2 = 240;
extern int tmf_3 = 60;
extern bool alertEnabled = false;
static double alertBar;
double step = 0.02;
double maximum = 0.2;
double long[];
double short[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0, long);
SetIndexStyle(0, DRAW_ARROW, EMPTY, thickness);
SetIndexArrow(0, 117);
SetIndexEmptyValue(0, 0.0);
SetIndexBuffer(1, short);
SetIndexStyle(1, DRAW_ARROW, EMPTY, thickness);
SetIndexArrow(1, 117);
SetIndexEmptyValue(1, 0.0);
IndicatorShortName("Triple Screen Parabolic Sar");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
/**
*@ param1 is the parabolic sar reading from the d1/4h/h1 chart
*@ param2 is the timeframe to check
*@ param3 is the shift of the actual bar to read
*@ return 2 if psar is above the high and 1 if is below or bullish
*/
int detectPsar(double psar, int tmf, int shift) {
if (psar >= iHigh(Symbol(), tmf, shift) ) {
return (2);
} else {
return (1);
}
return (0);
}
int start()
{
int counted_bars=IndicatorCounted();
//----
int totBars, tmf_1_shift, tmf_2_shift, tmf_3_shift;
double tmf_1_psar, tmf_2_psar, tmp_3_psar;
if (counted_bars < 0) counted_bars = 0;
if (counted_bars > 0) counted_bars--;
totBars = Bars - counted_bars - 1;
for (int i = 0; i <= totBars; i++) {
tmf_1_shift = iBarShift(Symbol(), tmf_1, iTime(Symbol(), 0, i), false);
tmf_2_shift = iBarShift(Symbol(), tmf_2, iTime(Symbol(), 0, i), false);
tmf_3_shift = iBarShift(Symbol(), tmf_3, iTime(Symbol(), 0, i), false);
tmf_1_psar = iSAR(Symbol(), tmf_1, step, maximum, tmf_1_shift + 1);
tmf_2_psar = iSAR(Symbol(), tmf_2, step, maximum, tmf_2_shift);
tmp_3_psar = iSAR(Symbol(), tmf_3, step, maximum, tmf_3_shift);
if (detectPsar(tmf_1_psar, tmf_1, tmf_1_shift + 1) == 2 &&
detectPsar(tmf_2_psar, tmf_2, tmf_2_shift) == 2 &&
detectPsar(tmp_3_psar, tmf_3, tmf_3_shift) == 2) {
short[i] = 1;
Print("it seems a downtrend");
}
if (detectPsar(tmf_1_psar, tmf_1, tmf_1_shift + 1) == 1 &&
detectPsar(tmf_2_psar, tmf_2, tmf_2_shift) == 1 &&
detectPsar(tmp_3_psar, tmf_3, tmf_3_shift) == 1) {
long[i] = 1;
Print("it seems an uptrend");
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
When I run the EA with the same code, the EA keep sayng downtrend or uptrend when the indicator does not show anything. The point is why in backtesting with ForexTester the indicator works fine and the EA does not ?
Thank you in advance.