Inputs: test(0), test2(0), test3(0);
variables: Pivot(0), Res1(0), Sup1(0), nearness(0), trailing_trigger(0), ma_entry_value(0), ma_exit_value(0),stoploss_value(0);
Pivot = (HighD(1) + LowD(1) + CloseD(1))/3;
Res1 = 2 * Pivot - LowD(1);
Sup1 = 2 * Pivot - HighD(1);
nearness = 0.0017;
ma_entry_value = 3;
trailing_trigger = 0.0030;
ma_exit_value = 9;
stoploss_value = 0.0030;
If marketposition = 0 and date>=1100105
and low <= Pivot + nearness and lowd(0) >= Pivot - nearness
and c > AverageFC(c, ma_entry_value)
and lowd(0) > lowd(1)
Then buy("Long") this Bar;
If marketposition = 0 and date>=1100505
and high >= Pivot - nearness and highd(0) <= Pivot + nearness
and c < AverageFC(c, ma_entry_value)
and highd(0) < highd(1)
Then sell("Short") this Bar;
If c < AverageFC(c, ma_exit_value) and (openpositionprofit > trailing_trigger) then exitlong ("L trailing exit") this bar;
If c > AverageFC(c, ma_exit_value) and (openpositionprofit > trailing_trigger) then exitshort ("S trailing exit") this bar;
If openpositionprofit < -stoploss_value then exitlong ("L stoploss") this bar;
If openpositionprofit < -stoploss_value then exitshort ("S stoploss") this bar;