[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Applystop StopLoss - trade on next day OPEN when PREVIOUS day CLOSE



PureBytes Links

Trading Reference Links

Hi,

Both codes are WRONG. There are trades with the same buyprice and 
sellprice, i.e. 0% profit.

I am sorry to say that it is not possible to program a useful system 
with combined StopLoss and Profittarget with TRADE DELAY in 
Amibroker. Let's forget the trailing stop that we discussed below. 
Let's make it simple.

OK, show me a simple system that has any buy condition based on Close 
price and Buyprice is on next day Open. It exits anytime if the High 
hits Profittarget% OR it exits if the Close price drops below StopLoss
% of the BuyPrice and exits on next day at Open price.

Please copy the code here and I will show you that it has wrong exits.

BR,
Zozuka



--- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@xxx> 
wrote:
>
> Hello,
> 
> Of course it should be:
> ApplyStop( stopTypeLoss, stopModePoint, Close - High + 
OrigStopAmount, 2, True );
> 
> The rest (the second formula) is OK. 
> 
> Best regards,
> Tomasz Janeczko
> amibroker.com
> ----- Original Message ----- 
> From: "zozuzoza" <zozuka@xxx>
> To: <amibroker@xxxxxxxxxxxxxxx>
> Sent: Tuesday, October 14, 2008 3:23 PM
> Subject: [amibroker] Re: Applystop StopLoss - trade on next day 
OPEN when PREVIOUS day CLOSE
> 
> 
> > Hello,
> > 
> > Please note that SetOption("AllowSameBarExit",1) is NOT wrong 
because 
> > I want to use Profittarget since Buyprice=Open triggered on 
previous 
> > day Buy signal (SetTradeDelays( 1, 1, 1, 1 )). I want to exit on 
the 
> > same day with Profittarget if possible.
> > 
> > Your code is not according to the AFL Function Reference, which 
says
> > ApplyStop( type, mode, amount, exitatstop, volatile = False, 
> > ReEntryDelay = 0 )
> > 
> > and your code is
> > ApplyStop( stopTypeLoss, stopModePoint, OrigStopAmount, Close - 
High 
> > + OrigStopAmount, 2, True );
> > 
> > I have already tried the 2nd code and I could not get it right. I 
try 
> > again but I doubt that the exit signals will be right.
> > 
> > Best regards,
> > Zozuka
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@> 
> > wrote:
> >>
> >> Hello,
> >> 
> >> *Everything* is possible in AFL. 
> >> You can print it and hang over your desk.
> >> 
> >> What's more there are usually many ways to do every thing.
> >> From complicated ones to easy ones.
> >> 
> >> The fact that you don't know how to do given thing
> >> does not mean that it is impossible. It only means that
> >> you need to learn.
> >> 
> >> Answering original poster:
> >> >> The settings I would like to use is as follows.
> >> >> SetOption("AllowSameBarExit",1);
> >> WRONG. Should be set to zero (false).
> >> This should be only set to true when SINGLE BAR trade is allowed.
> >> In your case it is NOT because exit is based on PREVIOUS BAR 
close.
> >> 
> >> If you want to use CLOSE instead of High-Low range for stop loss,
> >> you should simply use Volatile = True setting in ApplyStop
> >> and add the difference between High and Close to your stop 
amount:
> >> 
> >> OrigStopAmount = 0.3;
> >> 
> >> ApplyStop( stopTypeLoss, stopModePoint, OrigStopAmount, Close - 
> > High + OrigStopAmount, 2, True );
> >> 
> >> This is assuming that you need stop in points.
> >> 
> >> The other method is presented in the Knowledge Base and it does
> >> not require ApplyStop at all. It is general-purpose code for any 
> > kind of stop 
> >> with any imaginable setup
> >> http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-
stop-
> > in-the-price-chart/
> >> 
> >> With modification of two lines we can adopt it to max. loss stop 
> > that acts on next
> >> open based on prev day penetration of stop level by close price
> >> 
> >> stopLevel = 1 - Param("stop %", 3, 0.1, 10, 0.1)/100; 
> >> 
> >> Buy = Cross( MACD(), Signal() ); 
> >> Sell = 0; 
> >> trailARRAY = Null; 
> >> trailstop = 0; 
> >> 
> >> for( i = 1; i < BarCount; i++ ) 
> >> { 
> >>    if( trailstop > 0 AND Low[ i ] < trailstop ) 
> >>    { 
> >>       Sell[ i ] = 1; 
> >>       SellPrice[ i ] = Open[ i ]; 
> >>       trailstop = 0; 
> >>    } 
> >> 
> >>    if( trailstop == 0 AND Buy[ i ] ) 
> >>    { 
> >>       trailstop = Close[ i ] * stoplevel; 
> >>    } 
> >>    else Buy[ i ] = 0; // remove excess buy signals 
> >> 
> >>    if( trailstop > 0 ) 
> >>    {   
> >>        trailARRAY[ i ] = trailstop; 
> >>    } 
> >> 
> >> } 
> >> 
> >> PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low); 
> >> PlotShapes(Sell*shapeDownArrow,colorRed,0,High); 
> >> 
> >> Plot( Close,"Price",colorBlack,styleBar); 
> >> Plot( trailARRAY,"trailing stop level", colorRed ); 
> >> 
> >> Best regards,
> >> Tomasz Janeczko
> >> amibroker.com
> >> ----- Original Message ----- 
> >> From: "zozuzoza" <zozuka@>
> >> To: <amibroker@xxxxxxxxxxxxxxx>
> >> Sent: Tuesday, October 14, 2008 2:16 PM
> >> Subject: [amibroker] Re: Applystop StopLoss - trade on next day 
> > OPEN when PREVIOUS day CLOSE
> >> 
> >> 
> >> > Unfortunately, this is not possible in AFL I am afraid. I 
tried 
> > the 
> >> > following but does not work either because sometimes it gives 
> > wrong 
> >> > signals. 
> >> > 
> >> > Sell=C<(1-StopLoss/100)*ValueWhen(Buy,Ref(O,1),1)
> >> > 
> >> > I wonder if anybody managed to build proper trading system 
based 
> > on 
> >> > EOD data in Amibroker, which can be used in real trading. If 
your 
> >> > indicators are based on Close then you have to trade on next 
day 
> >> > Open, in which case you need to use Settradedelays and you are 
> >> > immediately dead as AFL does not support this. If you want to 
use 
> >> > combined StopLoss and Profittarget exits together, it does not 
> > work. 
> >> > If you want to use combined Trailing stop and PT exits, it 
does 
> > not 
> >> > work.  You can find couple of useless examples in AFL Function 
> >> > Reference under ApplyStop, which has nothing to do with real 
> > trading.
> >> > 
> >> > I am really disappointed with Amibroker and AFL. I have been 
> >> > programming it for 2 years so I know what I am talking about. 
You 
> >> > cannot find out what the reason of the bad exit signals are. 
It 
> > is 
> >> > like a black box.
> >> > 
> >> > 
> >> > --- In amibroker@xxxxxxxxxxxxxxx, "zozuzoza" <zozuka@> wrote:
> >> >>
> >> >> Hi,
> >> >> 
> >> >> I would like to apply a stoploss on next day OPEN when 
PREVIOUS 
> > day
> >> >> CLOSE hits stop and Sellprice=Open. In the AFL library, I 
could 
> > only
> >> >> find the solution for
> >> >> "Scenario 3:
> >> >> you trade on next day OPEN and want to exit by stop on OPEN 
price
> >> >> when PREVIOUS day H-L range hits stop"
> >> >> 
> >> >> This is almost good for me except I want the Applystop 
function 
> > to
> >> >> check the PREVIOUS day Close instead of the H-L range.
> >> >> 
> >> >> The settings I would like to use is as follows.
> >> >> SetOption("AllowSameBarExit",1);
> >> >> SetOption( "ActivateStopsImmediately", 1);
> >> >> SetTradeDelays( 1, 1, 1, 1 );
> >> >> BuyPrice=O;
> >> >> SellPrice=O;
> >> >> 
> >> >> I am stucked. Could anybody help me please how I can do it.
> >> >> 
> >> >> Thank you.
> >> >>
> >> > 
> >> > 
> >> > 
> >> > ------------------------------------
> >> > 
> >> > **** IMPORTANT ****
> >> > This group is for the discussion between users only.
> >> > This is *NOT* technical support channel.
> >> > 
> >> > *********************
> >> > TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail 
> > directly to 
> >> > SUPPORT {at} amibroker.com
> >> > *********************
> >> > 
> >> > For NEW RELEASE ANNOUNCEMENTS and other news always check 
DEVLOG:
> >> > http://www.amibroker.com/devlog/
> >> > 
> >> > For other support material please check also:
> >> > http://www.amibroker.com/support.html
> >> > 
> >> > *********************************
> >> > Yahoo! Groups Links
> >> > 
> >> > 
> >> >
> >>
> > 
> > 
> > 
> > ------------------------------------
> > 
> > **** IMPORTANT ****
> > This group is for the discussion between users only.
> > This is *NOT* technical support channel.
> > 
> > *********************
> > TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail 
directly to 
> > SUPPORT {at} amibroker.com
> > *********************
> > 
> > For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> > http://www.amibroker.com/devlog/
> > 
> > For other support material please check also:
> > http://www.amibroker.com/support.html
> > 
> > *********************************
> > Yahoo! Groups Links
> > 
> > 
> >
>



------------------------------------

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

*********************
TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com
*********************

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html

*********************************
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:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto: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/