You are the man again Mike. I will make these changes and give it a test. When you say trade intraday, I just wanted to remind you that I only trade mutual funds.
Will this acutally fix the problem of the stop levels using the signal date price and not the purchase date pirce, which is CLOSE+1? Lastly, I think we've gone through this before, but I use the backtester to get live signals. I only trade around 12 symbols and they are typically within the portfolio backtester. An example would be a portfolio with 6 different signals for 6 different symbols. It seems to be the easiest and fastest way to get the signals each day. Otherwise, I would have to run 12-15 different individual symbols, instead of 3 portfolios. --- In [email protected], "Mike" <sfclimb...@...> wrote: > > Steve, > In response to both this post and your prior one: > 1. Ref(Array, -1) means "what was the value of Array on the bar > previous to this one?".2. BuyPrice = Close means "set the purchase > price to this bar's close". > On Monday you are getting a signal. On Tuesday you want to trade that > signal using Tuesday's Close. That is easily modeled using the two > points above: > BuyTrigger = ...;Buy = Ref(BuyTrigger, -1); // 1. If Monday had a > signal, then buy it today (Tuesday).BuyPrice = Close; // Use today's > (Tuesday) Close as the purchase price. > This sets you up perfectly for Scenario 2 of ApplyStop which says that > you trade on today's Close (Tuesday) and want to exit intraday from that > point on (i.e. you have a stop loss order with your broker that will > stop you out anytime the price falls below your stated max loss). The > ApplyStop is independent of your Sell logic. Your Sell will still exit > at the Close, but your stop may exit intraday. > Completing your code sample gives the following: > /* > Scenario 2: > You trade on today's close and want to exit intraday on stop price > > Correct settings: > A. ActivateStopsImmediately turned OFF > B. ExitAtStop = 1 > C. Trade delays set to zero > D. Trade price set to close > */ > > SetOption("ActivateStopsImmediately", false); // A. > ActivateStopsImmediately turned OFF > SetTradeDelays(0, 0, 0, 0); // C. Trade delays set to zero > > BuyTrigger = Cross(StochFinal, Trigger) AND (EMA(Close, EMAShort) > > EMA(Close, EMALong)); > Buy = Ref(BuyTrigger, -1); > BuyPrice = Close; // D. Trade price set to close > > SellTrigger = Cross(Trigger, StochFinal) AND (EMA(Close, EMAShort) < > EMA(Close, EMALong)); > Sell = Ref(SellTrigger, -1); > SellPrice = Close; // D. Trade price set to close > > ApplyStop( stopTypeLoss, > stopModePercent, > Optimize("max. loss stop level", 2, 2, 10, 2), > 1, // B. ExitAtStop = 1 > False); > > > I can't fully test your code since your assignments for StochFinal and > Trigger were not provided. But, I believe that the above will solve your > problem. > If you want to run an Exploration each night to see what you should be > trading the next day, just use AddColumn to output the values of > BuyTrigger and SellTrigger instead of Buy and Sell respectively. > Mike > > --- In [email protected], "graphman27" <steve@> wrote: > > > > I want to simplify my life, believe me. I'm having a bit of > difficulty following what you're saying to do. Here is some sample > code, just in case I'm not being clear: > > > > Buy = Cross(StochFinal,Trigger) AND (EMA( Close,EMAShort ) > EMA( > Close,EMALong )); > > > > Sell = Cross(Trigger,StochFinal) AND (EMA( Close,EMAShort ) < EMA( > Close,EMALong )); > > > > Plot( EMA ( Close,2 ),"Short EMA", colorGreen, styleThick ); > > Plot( EMA ( Close,10 ),"Long EMA", colorRed, styleThick ); > > Plot( StochFinal ,"Period", colorGreen, styleThick ); > > > > /* max loss stop optimization */ > > > > ApplyStop(stopTypeLoss, > > stopModePercent, > > Optimize( "max. loss stop level", 2, 2, 10, 2 ), > > 2, > > False ); > > > > What do I need to do to make sure: > > > > 1. All buys and sells are done as CLOSE+1 (I only use EOD data for > mutual funds). > > 2. Make sure stops are triggered based on the purchase price, not the > price on the -1 signal date. > > > > Right now, under settings, I have Buys and Sells set to CLOSE +1. > > > > Thanks! > > > > --- In [email protected], "Mike" sfclimbers@ wrote: > > > > > > Hi, > > > > > > Since you are trading the Close, you could simplify your life by > following one of the well defined scenarios from the ApplyStop > documentation: > > > > > > http://www.amibroker.com/guide/afl/afl_view.php?id=20 > > > > > > In your case, follow scenario 2 and take your trades based on > yesterday's signal. > > > > > > e.g. > > > > > > SetTradeDelays(0, 0, 0, 0); > > > > > > Trigger = ...; > > > Buy = Ref(Trigger, -1); > > > BuyPrice = Close; > > > > > > Your signal still shows up Monday night. But, you don't act on it > until Tuesday Close. That's what you're doing in real life anyway, so > just make your code show the same. > > > > > > Mike > > > > > > --- In [email protected], "graphman27" <steve@> wrote: > > > > > > > > Question: When stops are coded afl instead of setup under > settings, do they disregard the system settings for Buy Price and Buy > Delay? Currently, I have the latter set to Buy Price = Close+1 Day Buy > Delay. For a new strategy I am working on, I notice that during live > testing something doesn't jive. Here is an example... > > > > > > > > Note: I always use EOD data and CLOSE +1, to get "tradable" > signals for mutual funds and indices: > > > > > > > > Monday Night: Formula gave buy signal for Emerging Markets after > the close. With CLOSE+1 Day delay, that would mean buy at Tuesday's > Close. > > > > > > > > Tuesday Night: Max Loss Stop is triggered because of a -3.5% drop > in the Emerging Markets on Tuesday. > > > > > > > > Wednesday at the close, mutual fund is sold. > > > > > > > > Question: How could a Max Loss Stop be triggered if that fund > wasn't purchased until AFTER Tuesday's big drop? Since it was purchased > AFTER the drop, there was no loss of -3.5% going into Wednesday. > > > > > > > > Here is an example of a typical mutual fund compatible coded stop: > > > > > > > > ApplyStop(stopTypeLoss, > > > > stopModePercent, > > > > Optimize( "max. loss stop level", 2, 2, 10, 2 ), > > > > False ); > > > > > > > > Do I have to code something else to make sure the STOP is > triggered based on the CLOSE+1 purchase price and NOT the BUY SIGNAL > Price? Or, do I need to code the Buys and Sells inside the formula as > CLOSE+1 instead of relying on system settings? OR, none of the above? > > > > > > > > Thanks in advance for your help, as usual! > > > > > > > > Steve. > > > > > > > > > >
