PureBytes Links
Trading Reference Links
|
Gary
Many thanks for taking the trouble. Your code works flawlessly. Now comes the undersanding it bit to see what I was missing.
Regards
Rakesh"Gary A. Serkhoshian" <serkhoshian777@xxxxxxxxx> wrote:
Rakesh,Glad you posted the code. Otherwise, we would'veexchanged another dozen e-mails without gettinganywhere.The primary problem is having a cross of a triggeroccur when we are not in the appropriate condition. There are two ways to handle this.First, you put a time limit on the number of bars thatthe entry can be taken after it's established. Forexample, EntryOK = BarsSince(BuyCondition, 1) <=5;Another method to to define which state your are in,and from there marry the state to your buy/sellcrosses to ensure that a cross is occuring when youwant to take advantage of it.I've coded the changes using the second method sinceit's a bit more confusing, and it'll help to see thecode. Also, I've added exrems to get the extra buyand sell signals out. You may want them
back. If so,just get rid of the exrem.BTW, you may wonder why I use not instead of two flipsto define buy states vs. sell states. Reason being,in a case where both the buy condition and sellcondition are true, Flip(buycondition, sellcondition)yields a false as does Flip(Buycondition,sellconditon). As such, nothing would happen. Toaccount for this we use not BuyState. In other words,if we are not in a buy state, then by definition weare in a sell state. Just play with the code, andyou'll see what I mean.Kind Regards,GaryEMA1=EMA(C,8.3896);EMA2=EMA(C,17.5815);DMACD=EMA1-EMA2;M_TRGR1=EMA(DMACD,3);M_TRGR2=EMA(M_trgr1,5);D_M_HIST=DMACD-M_TRGR2;B_XOVER=Cross(DMACD,M_TRGR2);S_XOVER=Cross(M_TRGR2,DMACD);OnBuyXOver = Flip(B_XOver, S_XOver);OnSellXOver = NOT
OnBuyXOver;B_X_TRGR=ValueWhen(B_XOVER,H+.05,1);S_X_TRGR=ValueWhen(S_XOVER,L-.05,1);HIST_B_SGNL=Cross(D_M_HIST,Ref(D_M_HIST,-1));HIST_S_SGNL=Cross(Ref(D_M_HIST,-1),D_M_HIST);OnHistBuySignal = Flip(HIST_B_SGNL, HIST_S_SGNL);OnHistSellSignal = NOT OnHistBuySignal;HIST_B_TRGR=ValueWhen(HIST_B_SGNL,H+.05,1);HIST_S_TRGR=ValueWhen(HIST_S_SGNL,L-.05,1);B_PRC_BRK1= Cross(C, B_X_TRGR);S_PRC_BRK1=Cross(S_X_TRGR ,C);B_PRC_BRK2=Cross(C,HIST_B_TRGR);S_PRC_BRK2=Cross(HIST_S_TRGR,C);bc1=B_PRC_BRK1 AND OnBuyXOver;bc2=B_PRC_BRK2 AND OnHistBuySignal;Sc1=S_prc_bRK1 AND OnSellXOver;Sc2= S_PRC_BRK2 AND OnHistSellSignal;Buy= bc1 OR BC2;Sell=SC1 OR SC2 ;Buy = ExRem(Buy, Sell);Sell = ExRem(Sell,
Buy);Plot(DMACD,"MACD",4);Plot(M_TRGR1,"DM_TRGR1",5);Plot(M_TRGR2,"DM_TRGR2",6);Plot(D_M_HIST,"D_M_HIST",10,2);PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBrightGreen);PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);--- Rakesh Sahgal <rakeshsahgal@xxxxxxxxx> wrote:> Gary> > Am pasting the offending code here and attaching a> graphic showing the wrong arrow.> > > EMA1=EMA(C,8.3896);> > EMA2=EMA(C,17.5815);> > DMACD=EMA1-EMA2;> > M_TRGR1=EMA(DMACD,3);> > M_TRGR2=EMA(M_trgr1,5);> > D_M_HIST=DMACD-M_TRGR2;> > B_XOVER=Cross(DMACD,M_TRGR2);> > S_XOVER=Cross(M_TRGR2,DMACD);> > B_X_TRGR=ValueWhen(B_XOVER,H+.05,1);> > S_X_TRGR=ValueWhen(S_XOVER,L-.05,1);> > HIST_B_SGNL=Cross(D_M_HIST,Ref(D_M_HIST,-1));>
> HIST_S_SGNL=Cross(Ref(D_M_HIST,-1),D_M_HIST);> > HIST_B_TRGR=ValueWhen(HIST_B_SGNL,H+.05,1);> > HIST_S_TRGR=ValueWhen(HIST_S_SGNL,L-.05,1);> > B_PRC_BRK1= Cross(C, B_X_TRGR);> > S_PRC_BRK1=Cross(S_X_TRGR ,C);> > B_PRC_BRK2=Cross(C,HIST_B_TRGR);> > S_PRC_BRK2=Cross(HIST_S_TRGR,C);> > bc1=B_PRC_BRK1;> > bc2=B_PRC_BRK2;> > Sc1=S_prc_bRK1; > > Sc2= S_PRC_BRK2;> > Buy= bc1 OR BC2;> > Sell=SC1 OR SC2 ;> > Plot(DMACD,"MACD",4);> > Plot(M_TRGR1,"DM_TRGR1",5);> > Plot(M_TRGR2,"DM_TRGR2",6);> > Plot(D_M_HIST,"D_M_HIST",10,2);> > PlotShapes(IIf(Buy,shapeUpArrow,shapeNone)> ,colorBrightGreen);> >PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed);> > Regards> > > Rakesh>
> "Gary A. Serkhoshian" <serkhoshian777@xxxxxxxxx>> wrote:> Rakesh,> > Put some code up here. Otherwise, we are going to> get> mired in generalities.> > Regards,> Gary> --- Rakesh Sahgal <rakeshsahgal@xxxxxxxxx> wrote:> > Gary> > > > The way I have structured my formula is:> > > > 1. Look for condition 1 and mark the high of the> day> > condition1 occurs as trigger level..> > 2. If trigger level is crossed, only then am I> > triggered into the trade - I am using the cross> > function to determine the crossover.> > > > Once the crossover happens the relevance of such a> > trigger is nil as an entry point. Problem is the> > formula is still remembering that trigger level.> It> > forgets it alright when the next buy signal
is> given> > by the indicator and accepts the new trigger> level.> > But if prior to a new buy signal the price gyrates> > around the earlier trigger level an arrow is> > plotted.> > > > Some loud thinking - Is it possible to write a> > condition that says only the n=1 occurence of the> > crossover of the trigger level by the price is to> be> > used? I also tried using valuewhen and couldnt> make> > it work. If this is possible what function is to> be> > used?> > > > Rakesh> > > > > > > > "Gary A. Serkhoshian" <serkhoshian777@xxxxxxxxx>> > wrote:> > Rakesh,> > > > Make sure you AND your conditions to create your> > Buy,> > and that you are using the Buy to create the> arrow.> >
> > Buy = Condition1 and Condition2;> > Sell = SellCondition1 and SellCondition2;> > > > Buy = Exrem(Buy, Sell);> > Sell = Exrem(Sell, Buy);> > > > PlotShapes(Buy * shapeUpArrow, colorgreen, 0, L);> > > > > > --- Rakesh Sahgal <rakeshsahgal@xxxxxxxxx> wrote:> > > I have a formula that says:> > > > > > 1. Go long when long StochK crosses StochD and> > vice> > > versa for short.> > > > > > 2. Trigger to be crossed for executing the trade> > is> > > close higher than the high of the crossover day> > and> > > once again vice versa for short.> > > > > > Once a long signal is given both in terms of> > > indicator and price crossover, the value of the> > high> > > of the
crossover bar is irrelevant.> > > > > > Now the problem:> > > > > > However what is happening is:> > > > > > 1. Buy Trade arrow is displayed - Correctly .> > > 2. Sell Trade arrow is displayed - Correctly.> > > > > > this is where the foul up is happening:> > > > > > 3. When the price again crosses the level> > determined> > > in 1 an arrow is plotted even though it has no> > > relevance/significance.> > > > > > I experimented with EXREM, but to no avail. Can> > > someone kindly point out the error in my> > > logic/coding which is causing this wrong display> > of> > > arrows to occur? > > > > > > TIA> > > > > > > > >
Rakesh> > > > > > > > > > > > ---------------------------------> > > Do you Yahoo!?> > > SBC Yahoo! - Internet access at a great low> price.> > > > > > > > > > > > __________________________________> > Do you Yahoo!?> > SBC Yahoo! - Internet access at a great low price.> > http://promo.yahoo.com/sbc/> > > > > > Send BUG REPORTS to bugs@xxxxxxxxxxxxx> > Send SUGGESTIONS to suggest@xxxxxxxxxxxxx> > -----------------------------------------> > Post AmiQuote-related messages ONLY to:> > amiquote@xxxxxxxxxxxxxxx >
> (Web page:> > http://groups.yahoo.com/group/amiquote/messages/)> > --------------------------------------------> > Check group FAQ at:> >>http://groups.yahoo.com/group/amibroker/files/groupfaq.html> > > > > > > > Yahoo! Groups SponsorADVERTISEMENT> > > > > > ---------------------------------> > Yahoo! Groups Links> > > > To visit your group on the web, go to:> > http://groups.yahoo.com/group/amibroker/> > > > To unsubscribe from this group, send an email> to:> > amibroker-unsubscribe@xxxxxxxxxxxxxxx> > >
> Your use of Yahoo! Groups is subject to the> > Yahoo! Terms of Service. > > > > > > > > ---------------------------------> > Do you Yahoo!?> > SBC Yahoo! - Internet access at a great low price.> > > > > > __________________________________> Do you Yahoo!?> SBC Yahoo! - Internet access at a great low price.> http://promo.yahoo.com/sbc/> > > Send BUG REPORTS to bugs@xxxxxxxxxxxxx> Send SUGGESTIONS to suggest@xxxxxxxxxxxxx> -----------------------------------------> Post AmiQuote-related messages ONLY to:> amiquote@xxxxxxxxxxxxxxx > (Web page:> <A
href="">http://groups.yahoo.com/group/amiquote/messages/)> --------------------------------------------> Check group FAQ at:>http://groups.yahoo.com/group/amibroker/files/groupfaq.html> > > > Yahoo! Groups SponsorADVERTISEMENT> > > ---------------------------------> Yahoo! Groups Links> > To visit your group on the web, go to:> http://groups.yahoo.com/group/amibroker/> > To unsubscribe from this group, send an email to:> amibroker-unsubscribe@xxxxxxxxxxxxxxx> > Your use of Yahoo! Groups is subject to the> Yahoo! Terms of Service. > > > >
> ---------------------------------> Do you Yahoo!?> SBC Yahoo! - Internet access at a great low price.> ATTACHMENT part 2 image/bmp name=arrow_error.PNG __________________________________Do you Yahoo!?SBC Yahoo! - Internet access at a great low price.http://promo.yahoo.com/sbc/Send BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS to suggest@xxxxxxxxxxxxx-----------------------------------------Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: http://groups.yahoo.com/group/amiquote/messages/)--------------------------------------------Check group FAQ at: <A
href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Do you Yahoo!?SBC Yahoo! - Internet access at a great low price.
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Yahoo! Groups Links
To visit your group on the web, go to:http://groups.yahoo.com/group/amibroker/
To unsubscribe from this group, send an email to:amibroker-unsubscribe@xxxxxxxxxxxxxxx
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
|