{----------------------------------------------------------------------------------------------------------------} 

Inputs: LenF(8), { Short MovAvg } 
LenS(24), { Long MovAvg } 
SL(0), { SL in % from entry price } 
CloseOut(0); { close position on last bar } 

vars: avgF(0), avgS(0), signal(0), StBar(0),EndBar(0), OneTick(MinMove/PriceScale), 
OrderSl_L(0),OrderSl_S(0),BuyPrice(0),SellPrice(0), LongEx(0),ShortEx(0); 
{----------------------------------------------------------------------------------------------------------------} 
{ рассчитаем средние } 
avgF=Average(V,lenF); 
avgS=Average(V,lenS); 

if avgF crosses above AvgS then begin { session started} 
signal=1; 
StBar=BarNumber; {remember channel start } 
end; 

if avgF crosses below AvgS then begin { session ended } 
signal=0; 
EndBar=BarNumber; { remember channel end } 
end; 

if StBar>EndBar then value1=StBar-EndBar; { channel length } 

if signal=1 then begin 
BuyPrice=Highest(H,value1)+OneTick; 
SellPrice=Lowest(L,value1)-OneTick; 
end; 
{----------------------------------------------------------------------------------------------------------------} 
{ place entry orders only during session } 
if signal=1 then begin 
if MarketPosition>=0 then Sell ("Dn") SellPrice Stop; 
if MarketPosition<=0 then Buy ("Up") BuyPrice Stop; 
end; 
{----------------------------------------------------------------------------------------------------------------} 
{SL} 
if SL>0 then begin { SL in % from Entry price } 

if MarketPosition=1 then begin 
OrderSL_L=(1-SL*0.01)*EntryPrice; 
ExitLong ("Sl_L") OrderSL_L stop; 
end; 

if MarketPosition=-1 then begin 
OrderSL_S=(1+SL*0.01)*EntryPrice; 
ExitShort ("Sl_S") OrderSL_S stop; 
end; 
end; 
{-------------------------------------------------------------------------------------------------------------------------------} 
{Last day closing out} 
if LastBarOnChart and CurrentContracts<>0 and CloseOut=1 then begin 
if MarketPosition>0 then exitlong ("LDayL") close; 
if MarketPosition<0 then exitshort ("LDayS") close; 
end; 
{----------------------------------------------------------------------------------------------------------------} 

    Source: geocities.com/fxapprentice/files

               ( geocities.com/fxapprentice)