Grover, Sorry, I don't get attachments as I only view messages on the web where attachments aren't saved.
However, on doing as you suggested with GE, but changing the Buy/Short conditions of the ApplyStop version to be the same as the loop version (ie. MA crossover rather than MACD signal crossover), I noticed the following: - Your loop stop uses close as the entry price and high or low as the stop price. I think ApplyStop uses your trade price settings programmed in the AA settings (although I've never really experimented with ApplyStop to be sure what it's using). Consequently, if they are not set to sell on low and cover on high, there will be some difference. - Your loop code can display signals for concurrent long and short trades, whereas ApplyStop with Equity(1) can't (in reality you wouldn't have both, as the second would be a sell/cover of the first rather than a new position, but I've never checked what happens if you have a short signal while you're already long without a corresponding sell). The ApplyStop version doesn't show any short trades because the whole period is mostly in long trades and all short signals are within open long trades (I only have a limited amount of data for GE though). Remember, when you use Equity(1), it leaves your signal arrays showing the actual trades that would be taken, removing all signals that wouldn't be taken. You can't have an open long and short trade in the same stock at the same time. Hope this helps. Regards, GP --- In [email protected], "Grover Yowell" <[EMAIL PROTECTED]> wrote: > > GP, I will try to get on the same sheet of music with you. > > I went to the daily database that ships with AB, and pulled up GE. Put in > ticksize = .01 in the window brought up by the little "I" icon. Then I > changed the parameter values for stop level ticks to range up to 200 ticks > which would be 200 X .01 = $2.00 of price change for GE. Then I put the > ApplyStop version in the upper pane and the loop version in the lower pane > and set the stoplevel ticks to 200 for each pane. Then I exported the image > to MaxLoss.png which is attached. Then what I see is no stop levels on the > Applystop version in the top pane and two stop levels with the two short > signals for the loop version in the lower pane. Checking the price shown > for the stop levels in the lower pane, they check out exactly at $2.00 above > the short price. > > > > Next I reduced the stoplevel ticks on the upper pane until I had stop levels > showing. This was at 70 ticks, or $0.70 stop loss. No stop levels were > showing until I reached 70 ticks on the upper pane. But on the lower pane, > the stop level moved smoothly from it's location at 200 ticks down to 70 > ticks. I have attached the png file for this image as > MaxLossStopTicks70.png. > > > > Conclusions: > > > > I would think that the two versions should give similar results. > > Something is different using the ApplyStop version. > > I don't know for sure that my loop version is correct, but it works more > like I expect it to work. > > > > Any ideas? > > > > Thanks again for your help! > > > > Grover > > > > From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf > Of gp_sydney > Sent: Saturday, October 04, 2008 4:24 PM > To: [email protected] > Subject: [amibroker] Re: How to plot a maximum loss stop line > > > > Grover, > > I'm not familiar with those futures. What's the current price? > > And what do you see when it is not working? Is there no sell signal, > no stop line, a stop line with an incorrect value? > > Perhaps give an example of one bar where it's not working, providing > the OHLC values and the value of the stop line at that bar, the entry > price, and the value of maxlossticks. > > Regards, > GP > > --- In [email protected] <mailto:amibroker%40yahoogroups.com> , > "Grover Yowell" <gyowell1@> wrote: > > > > Hi GP, > > > > > > > > Thanks for the reply. > > > > The Ticksize is set to 0.25 since I am using the ESZ8-GLOBEX-FUT > futures > > for quotes. > > > > > > > > What I am finding is that the max loss stop works over a very > limited range > > of values of max loss, say 1 - 5 ticks., > > > > > > > > To understand what is going on, I have also taken TJ's code > > > > for the loop version of the trailing stop referenced in the kb > article, and > > adapted it to do a loop version maxloss stop both long and short. > > Hopefully I don't have any errors in that code. And I have used > the loop > > version to compare with the this other version which we can call the > > ApplyStop version. The loop version works smoothly over the whole > range of > > values of max loss while the ApplyStop version works only over a small > > limited range. Here is the code for the loop version. For my > comparison, I > > changed the code in my earlier post to use identical buy/sell rules. > > > > > > > > My objective is to have a max loss stop function which will provide > a signal > > as an indicator as opposed to the backtester. If I can confirm that > my loop > > version is doing the job, I will go with it instead of the ApplyStop > > version. > > > > > > > > Again, thanks for your help. I would welcome any comments on the code > > below. > > > > > > > > Grover Yowell > > > > > > > > ///////////////////////////////////////////Loop Code > > begins/////////////////////////////// > > > > Buy = Cross( MA( C, 10 ), MA( C, 20 ) ); > > > > Short = Cross( MA( C, 20 ), MA( C, 10 ) ); > > > > Sell = 0; > > > > Cover = 0; > > > > > > > > maxlossticks = Param( "MaxLossTicks", 5, 0, 20, 1 ); > > > > maxlosspoints = maxlossticks * TickSize; > > > > > > > > MaxlossbuyARRAY = Null; > > > > MaxlossshortARRAY = Null; > > > > priceatbuy = 0; > > > > priceatshort = 0; > > > > > > > > for ( i = 1; i < BarCount; i++ ) > > > > { > > > > //if( traillongstop == 0 AND Buy[ i ] ) > > > > if ( priceatbuy == 0 AND Buy[i] ) //buy signal and not intrade > > > > { > > > > //traillongstop = High[ i ] - trailpoints; > > > > priceatbuy = Close[i]; //take the > > trade > > > > } > > > > else > > > > Buy[ i ] = 0; // remove excess buy signals > > > > if ( priceatbuy > 0 ) //we are > intrade long > > > > { > > > > maxlossbuyARRAY[i] = priceatbuy - Maxlosspoints; > > > > } > > > > if ( priceatbuy > 0 AND Low[i] < priceatbuy - Maxlosspoints ) > //trade > > closed out > > > > { > > > > Sell[ i ] = 1; > > > > SellPrice[ i ] = Close[i]; > > > > priceatbuy = 0; > > > > } > > > > > > > > //short > > > > if ( priceatshort == 0 AND Short[ i ] ) > > > > { > > > > priceatshort = Close[i]; > > > > } > > > > else > > > > Short[ i ] = 0; // remove excess short signals > > > > > > > > if ( priceatshort > 0 ) > > > > { > > > > maxlossshortARRAY[i] = priceatshort + Maxlosspoints; > > > > } > > > > > > > > if ( priceatshort > 0 AND High[i] > priceatshort + Maxlosspoints ) > > //trade closed out > > > > { > > > > Cover[ i ] = 2; > > > > CoverPrice[ i ] = Close[i]; > > > > priceatshort = 0; > > > > } > > > > } > > > > PlotShapes( Buy*shapeUpArrow, colorBrightGreen, 0, Low ); > > > > PlotShapes( Sell*shapeHollowDownArrow, colorRed, 0, High ); > > > > PlotShapes( Short*shapeDownArrow, colorRed, 0, H ); > > > > PlotShapes( Cover*shapeHollowUpArrow, colorBrightGreen, 0, L ); > > > > > > > > SetBarFillColor( IIf( C > O, colorBrightGreen, colorRed ) ); > > > > Plot( Close, "Price", colorWhite, styleCandle ); > > > > Plot( maxlossbuyARRAY, "maxlossbuyArray", colorBrightGreen ); > > > > Plot( maxlossShortARRAY, "maxlossShortARRAY", colorRed ); > > > > Plot( MA( C, 10 ), "MA fast", colorBrightGreen ); > > > > Plot( MA( C, 20 ), "MA slow", colorRed ); > > > > InTradelong = Flip( Buy, Sell ); > > > > InTradeshort = Flip( Short, Cover ); > > > > Plot( 2, /* defines the height of the ribbon in percent of pane width > > > > */"ribbon", > > > > IIf( intradelong, colorBrightGreen, IIf( intradeshort, colorRed, > > colorYellow ) ), /* choose color */ > > > > styleOwnScale | styleArea | styleNoLabel, -0.5, 100 ); > > > > Title = _DEFAULT_NAME() + StrFormat( "{{NAME}} - > > {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g ", O, H, L, C ); > > > > > > > > /////////////////////////////////////////////////Loop Code > > Ends////////////////////////////////////// > > > > > > > > From: [email protected] <mailto:amibroker%40yahoogroups.com> > [mailto:[email protected] <mailto:amibroker%40yahoogroups.com> ] > On Behalf > > Of gp_sydney > > Sent: Friday, October 03, 2008 7:43 PM > > To: [email protected] <mailto:amibroker%40yahoogroups.com> > > Subject: [amibroker] Re: How to plot a maximum loss stop line > > > > > > > > What is your value of "TickSize"? If it's zero, ApplyStops seems to do > > nothing and you don't get any sell signals. If it's a positive value, > > then it is in dollars and the resulting value of stopLevelPoints may > > be too large for the current share price. > > > > If I try your formula with a tick size of 0.01 (ie. 1 cent), it works > > as expected. > > > > Regards, > > GP > > > > --- In [email protected] <mailto:amibroker%40yahoogroups.com> > <mailto:amibroker%40yahoogroups.com> , > > "gyowell2000" <gyowell1@> wrote: > > > > > > I have been attempting to plot a maximum loss stop line following the > > > code for plotting a trailing stop provided by TJ in the Knowledge > > > base: > > > > > > http://www.amibroker.com/kb/2007/03/24/how-to-plot-a-trailing-stop-in- > > > the-price-chart/ > > > > > > My code follows, unfortunately it doesn't work! I have used ticks > > > for max loss allowed instead of percentages. I also wanted a system > > > that would accomodate either long or short sales. > > > > > > ////////////////////////Code begins///////////////////////////// > > > StopLevelticks = Param("stoplevel ticks", 3, 0, 20, 1 ); > > > stoplevelpoints = stoplevelticks*TickSize; > > > SetTradeDelays(0,0,0,0); > > > > > > Buy = Cross( MACD(), Signal() ); > > > Short = Cross(Signal(), MACD() ); > > > Sell = 0; > > > Cover = 0; > > > ApplyStop( stopTypeLoss, stopModePoint, StopLevelpoints, True ); > > > > > > Equity( 1, 0 ); // evaluate stops, all quotes > > > > > > InTradelong = Flip( Buy, Sell ); > > > InTradeshort = Flip( Short, Cover ); > > > > > > SetOption("EveryBarNullCheck", True ); > > > stoplinelong = IIf( InTradelong, ValueWhen( Buy, BuyPrice) - > > > stoplevelpoints , Null ); > > > stoplineshort = IIf( InTradeshort, ValueWhen( Short, ShortPrice) + > > > stoplevelpoints , Null ); > > > > > > PlotShapes(Buy*shapeUpArrow,colorBrightGreen,0,Low); > > > PlotShapes(Short*shapeDownArrow,colorRed,0,High); > > > PlotShapes(Cover*shapeHollowUpArrow,colorBrightGreen,0,Low); > > > PlotShapes(Sell*shapeHollowDownArrow,colorRed,0,High); > > > > > > SetBarFillColor( IIf( C > O, colorBrightGreen, colorRed ) ); > > > > > > Plot( Close,"Price",colorWhite,styleCandle); > > > Plot( stoplinelong, "maxloss line long", colorBrightGreen ); > > > Plot( stoplineshort, "maxloss line short", colorRed ); > > > //////////////////////////Code Ends///////////////////////////////// > > > > > > Converting TJ's code from a trailing stop to a maximum loss stop and > > > getting the functionality to handle shorts proved to be be more > > > difficult than I had anticipated. > > > > > > I would appreciate any help in clearing up the problems in the code > > > above. > > > > > > Thanks in advance, > > > > > > Grover Yowell > > > > > >
