Params
Numeric Mult(4);
Numeric Length(30);
Numeric ExitOnCloseMins(15.10);
Numeric StopPercent(0.5);
Vars
Numeric DayOpen;
Numeric UpperBand;
Numeric LowerBand;
Numeric MyPrice;
Numeric myExitPrice;
NumericSeries EntryLots;
NumericSeries ATRValue;
Begin
ATRValue=AvgTrueRange(Length);
DayOpen=OpenD(0);
UpperBand=DayOpen+ATRValue[1]*Mult;
LowerBand=DayOpen-ATRValue[1]*Mult;
EntryLots=IntPart(Portfolio_CurrentCapital*0.3/(Close*ContractUnit*BigPointValue*MarginRatio));
If(MarketPosition!=1 && High>=UpperBand && Time<ExitOnCloseMins/100)
{
MyPrice=UpperBand;
If(Open>MyPrice) Myprice=Open;
Buy(1,MyPrice);
Return;
}
If(MarketPosition!=-1 && Low<=LowerBand && Time<ExitOnCloseMins/100)
{MyPrice=LowerBand;
If(Open<MyPrice) Myprice=Open;
SellShort(1,MyPrice);
Return;
}
If(MarketPosition==1)
{
If(Low<AvgEntryPrice*(1-StopPercent/100))
{
myExitPrice=AvgEntryPrice*(1-StopPercent/100);
myExitPrice=Min(Open,myExitPrice);
Sell(0,myExitPrice);
}
}
If(MarketPosition==-1)
{
If(High>AvgEntryPrice*(1+StopPercent/100))
{
myExitPrice=AvgEntryPrice*(1+StopPercent/100);
myExitPrice=Max(Open,myExitPrice);
BuyToCover(0,myExitPrice);
}
}
If(Time>=ExitonCloseMins/100)
{
Sell(0,Open);
BuyToCover(0,Open);
}
End