Vars:V1(Range),MinProfit(1500),StopValue(1),Limits(30),Pct(0.25),ExitDays(30),ChanDays(70),LongEntry(0),LongExit(0),ShortEntry(0),ShortExit(0),AvgR(0),Multiplier(1);
If (CurrentBar=1) then begin MinProfit = 1500; StopValue = (1500/BigPointValue); Pct = 0.25; Limits = 35; ExitDays = 30; Multiplier =0.4; end;
V1 = Pct * Average(TrueRange,10);AvgR = Average(TrueRange,5)[1];
{***CALCULATE ORDERS***}LongEntry = 99999.0;ShortEntry = 0.0;
If TrueRange > Multiplier*AvgR then beginLongEntry = Highest(TrueHigh,70) + V1;ShortEntry = Lowest(TrueLow,70) - V1;LongEntry = MinList(Close+V1,LongEntry); ShortEntry = MaxList(Close-V1,ShortEntry);end;
LongExit = EntryPrice - StopValue;ShortExit = EntryPrice + StopValue;
If MaxPositionProfit > MinProfit then begin LongExit = MaxList(Lowest(TrueLow,ExitDays),LongExit); ShortExit = MinList(Highest(TrueHigh,ExitDays),ShortExit);end;
{ BUY ORDERS}If MarketPosition =-1 and ShortExit < LongEntry then BuytoCover("Short Exit") next bar at ShortExit Stop; {SHORT EXIT}If LongEntry <> 99999.0 and (MarketPosition=-1 and LongEntry <= ShortExit) or (MarketPosition=0)then Buy("Long Entry") next bar at LongEntry Stop; {LONG ENTRY}
{ SELL ORDERS}If MarketPosition=1 and LongExit > ShortEntry then Sell("Long Exit") next bar at LongExit Stop; {LONG EXIT}If ShortEntry <> 0.0 and (MarketPosition=1 and ShortEntry >= LongExit) or (MarketPosition=0) then Sell Short("Short Entry") next bar at ShortEntry Stop; {SHORT ENTRY} |