Thanks Dennis. AB is probably working as it is supposed to. If it is there is something wrong with my code, more than likely. Or it was not designed to do what I am trying to do.
The way I see it, the last (current) tick is the close at that instant. The "close" value will change with each tick until the bar period times out and the last tick will be the true close. During the bar, when the immediate "close" crosses the indicator line and satisfies the buy/short conditions, I want to act immediately. I don't want to wait until the bar is closed. I am designing this to auto trade futures and I really don't want to wait until the bar is closed before I take or exit a position. The close can end up anywhere. I want to act, submit an order, when the conditions exist. I will redesign the code if I have to get it to submit a buy when the conditions exist. I just can't understand why AB does not recognize the instantaneous signal as a buy. It does in that the arrow appears and I can see it momentarily during trading hours. But why doesn't AB recognize it is a buy and why isn't the BuyPrice updated and stored? When I run explore the value of the indicator is in BuyPrice and it is correct. That is probably due to the way I decide what value to use during explore. But the same logic is used live. What further difference is there between live data and back test data? I must be missing something. Barry --- In [email protected], Dennis Brown <[EMAIL PROTECTED]> wrote: > > Barry, > > AmiBroker is working as it is supposed to work. When you are working > with real time intraday data, each AFL pass over the data is a static > snapshot that is processed. The last bar will be incomplete 99% of > the time. The close will not actually be the close of the bar, but > the last realtime quote. The high and low of the bar may also change > to greater limits before the bar is truly completed. > > One simple thing you can do, is only work with the data only up to > the last completed bar (BarCount-2) or C=Ref(C,-1), etc. > > However, even simpler (if you only use close data) is to use the Open > data instead. It will be the next tick after the close of the last > full bar and should not change during the bar. > > A little more complicated is to keep track of how close the bar is to > running out of time, and accept a signal only when the bar is 90%+ > complete. That will give you a little jump on the situation with a > low probability of the signal turning out to be false. > > My own strategy would be to use the incomplete signals as a "warning > of imminent trade" signal (perhaps with a little ping sound) and then > give the big Trade Bong when the bar closes (i.e. the trade signal is > on the previous bar). > > When backtesting, you will only get the signals on the completed > bars. Realtime trading is very different from backtesting static data. > > Sorry I don't have any AFL for you on this --I am still working on my > own system strategy. > > Best regards, > Dennis > > On Jan 28, 2008, at 6:37 PM, Barry Scarborough wrote: > > > I am working on a system where I try to buy or sell when a couple of > > indicators become true within the bar. I using this intraday and was > > watching the charts. I have the conditions ANDed and it places arrows > > on the chart when the Buy is true. The problem I ran into today was > > that the conditions were true within a minute bar, the buy arrow > > flashed on, then off a number of times within the bar. But BuyPrice > > which is set at the same time, never changed. What is going on? > > > > I want to generate a buy/sell immediately when the conditions are > > true. I thought maybe the conditions had to be true at the end of the > > bar before the Buy and BuyPrice become active. That does not seem to > > be the case, at least not all the time. I noticed that if the > > conditions occurred during the bar but were not true at the end of > > the bar the Buy was not set. But if the conditions were true at the > > beginning of the next bar the Buy and BuyPrice were set immediately, > > before the end of the bar. What is going on? Is this a bug? How can > > Buy come on without BuyPrice being set. Why does it work at the > > beginning of the bar but not intra bar? How is this supposed to > > work? > > > > I added the code below with the exception of the system code. > > > > Another problem that we noticed was that using AddColumn to dump the > > trade prices to Excel does not always have the same value as what is > > plotted on the chart. > > > > Thanks for the help, > > Barry > > > > Code fragment: > > > > // AND the indicator conditions to find the buy points > > Buy = BuySigA AND upIND; > > // normal sell or if last bar and buy state > > Sell = (SellSigA AND dnIND) OR tod == timeclose; > > // AND the indicator conditions to find the short points > > Short = ShortSigA AND dnIND; > > // normal cover or if last bar and short state > > Cover = (CoverSigA AND upIND) OR tod == timeclose; > > > > // in the following code fInRAnge determines whether to use the > > calculated price or the open price on a gap. > > // roundd the price up or down then adds or subtracts a tick > > depending on the signal, buy or short. > > pBuyPrice = tick + fRound(fInRange(IIf(Buy, fInd2, 0), up), up); > > pShortPrice = -tick + fRound(fInRange(IIf(Short, fInd2, 0), dn), dn); > > pSellPrice = -tick + fRound(fInRange(IIf(Sell, fInd2, 0), dn), dn); > > pCoverPrice = tick + fRound(fInRange(IIf(Cover, fInd2, 0), up), up); > > > > > > // make sure there are no multiple buys OR sells while a like > > position is Open > > Buy = ExRem(Buy, Sell ); > > Sell = ExRem(Sell , Buy); > > Cover = ExRem(Cover, Short ); > > Short = ExRem(Short , Cover); > > BuyPrice = IIf(Buy, pBuyPrice, 0); > > SellPrice = IIf(Sell, pSellPrice, 0); > > CoverPrice = IIf(Cover, pCoverPrice, 0); > > ShortPrice = IIf(Short, pShortPrice, 0); > > > > Filter = Buy OR Sell OR Short OR Cover; // set the conditions to > > monitor in analysis - back test, scan and explore > > > > // plot buy and sell arrows on the chart > > PlotShapes(Buy * shapeUpArrow, uparrow, 0, Low); > > PlotShapes(Sell * shapeDownArrow, dnarrow,0,Low ); > > PlotShapes(Short * shapeCircle, dnarrow); > > PlotShapes(Cover * shapeHollowCircle, uparrow); > > > > // plotting functions > > Plot(C, Date() + " - System 1a " + NumToStr(search, 1.0) + " - C", > > background, styleCandle); // plot candles on the chart > > Plot(BuyPrice, "\nBuy Price", background , styleOwnScale | > > styleNoLine | styleNoLabel ); > > Plot(SellPrice, "Sell Price", background , styleOwnScale | > > styleNoLine | styleNoLabel ); > > Plot(ShortPrice, "Short Price", background , styleOwnScale | > > styleNoLine | styleNoLabel ); > > Plot(CoverPrice, "Cover Price", background , styleOwnScale | > > styleNoLine | styleNoLabel ); > > Plot(Buy, "\nBuy", background , styleOwnScale | styleNoLine | > > styleNoLabel ); > > Plot(Sell, "Sell", background , styleOwnScale | styleNoLine | > > styleNoLabel ); > > Plot(Short, "Short", background , styleOwnScale | styleNoLine | > > styleNoLabel ); > > Plot(Cover, "Cover", background , styleOwnScale | styleNoLine | > > styleNoLabel ); > > > > // code for exploration and export to spreadsheet > > AddColumn(BuyPrice, "Buy price", 1.3); > > AddColumn(SellPrice, "Sell price", 1.3); > > AddColumn(ShortPrice, "Short price", 1.3); > > AddColumn(CoverPrice, "Cover price", 1.3); > > > > > > > > > > > > Please note that this group is for discussion between users only. > > > > To get 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 > > > > > > >
