PureBytes Links
Trading Reference Links
|
dear all,
i am trying to test intraday trading system with simple break out entry rule.
but want to exit in steps as follow.
entry rule : h > hhv of till 13.30 pm.
stop loss : (at time of entry) previous 3 bar low.
exit 1 : if price moves by 2 times atr(14) value than trail first
exit with high - atr(14) for 50 % of positions.
exit 2 : if exit 1 is true, than trail remaining position by
privious 3 bar low OR stop loss value which ever is high.
exit 3 : if market near closing time (ie 15.25 pm)
note atr(14) value for this purpose is value at time 13.30.(ie stationary
figure).
following is afl. it works ok as far as entry & stop loss is concern.
but not following scalin out code while i backtested on some intraday data. can some one help
in correcting my mistake.
help is highly appriciated.
asit.
//Bars = 1 + BarsSince( Day() != Ref( Day(), -1 ));
//tvol = Sum(V,bars); // total Volume up to time
SetTradeDelays(0,0,0,0);
tradetime = TimeNum() > 133000 AND TimeNum() < 151500 ;
exittime = TimeNum() > 152000 ;
//Avgvol = MA(V,20 );
breakoutime = 133000;
afterbreakout = Cross(TimeNum(),133000);
NewDay = Day()!= Ref(Day(), -1);
highestoftheday = HighestSince(newday,H,1); // gets the highest of the day so far
Lowestoftheday =LowestSince(newday,L,1); // gets the lowest of the day do far
ORBHigh = ValueWhen(afterbreakout,highestoftheday,1); // gets the highest of the day when time crossed 10:15
ORBLow = ValueWhen(afterbreakout,lowestoftheday,1); // gets the lowest of the day when time crossed 10:15
//ORBHigh and low are retained through the whole trading day since afterbreakout can only occure once per day
xx = IIf(C<150,0.15,IIf(C>150 AND C < 300 ,0.25,IIf(C>300 AND C<500,0.5,IIf(C>500 ,1,Null))));
Buy = tradetime AND H > ORbhigh ;//AND C > Ref(C,-1) AND C > BBandTop(C,20,2) AND tvol > 500000 AND V > 1.25*Avgvol
BuyPrice = ORBhigh + xx ;
Sell = 0;
sl = (BuyPrice - LLV(Low,3));
// the system will exit
// 50% of position if FIRST PROFIT TARGET stop is hit
// 100% of position if TRAILING STOP is hit
xatr = ATR(14) ;
breakatr = ValueWhen(Buy,Ref(xatr,-1),1);
ProfitTargetlooptrigger = H > (BuyPrice + 2*breakatr); //price move by more than 2*atr
//firstprofit target = ProfitTargetlooptrigger - breakatr ;
TrailingStoptrigger = L < Ref(C < LLV(L,3),1); //
trailingstop = 0;
priceatbuy = 0;
highsinceprtrigger = 0;
exit = 0;
for( i = 0; i < BarCount; i++ )
{
if( priceatbuy == 0 AND Buy[ i ] )
{
priceatbuy = BuyPrice[ i ];
}
if( priceatbuy > 0 AND exittime[i] )
{
Sell[i] = exit + 1 ;
}
if( priceatbuy > 0 AND ProfitTargetlooptrigger[i] )
{
highsinceprtrigger = Max( High[ i ], highsinceprtrigger );
if( exit == 0 AND
Low[ i ] <= (highsinceprtrigger[i] - breakatr[i]))
{
// scale-out 50 %
exit = 1;
Buy[ i ] = sigScaleOut;
}
if( exit == 1 AND TrailingStoptrigger[i] )
{
// trailing stop hit - exit
exit = 3;
SellPrice[ i ] = Open[ i ];
}
if( exit >= 2 )
{
Buy[ i ] = 0;
Sell[ i ] = exit + 1; // mark appropriate exit code
exit = 0;
priceatbuy = 0; // reset price
highsinceprtrigger = 0;
}
}
}
SetPositionSize( 50, spsPercentOfEquity );
SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) ); // scale out 50% of position
ApplyStop(0,stopModePoint,sl,1);
//Sell = exittime ;//OR C < ORblow ;
//ApplyStop(0,1,1,1);
//ApplyStop(0,2,0.25*trd,1);
------------------------------------
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
amibroker-digest@xxxxxxxxxxxxxxx
amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|