/*[[ Name := Bunnygirl Cross and Daily Open Author := David W Thomas Link := davidwt@usa.net Notes := This is too inform on the last ema cross and the daily open price for use in Bunnygirl's wma cross. Separate Window := No First Color := DarkViolet First Draw Type := Line First Symbol := 217 Use Second Data := No Second Color := DarkViolet Second Draw Type := Symbol Second Symbol := 218 ]]*/ Input : PipsForBounce(3), TimeZoneOfData(2); Variables : shift(0), prevbars(0), first(True), loopbegin(0), dailyopen(0), lastcrossamount(0), lastcrosstime(0), lastcrossdir(""), diff0(0), diff1(0), diff2(0), //ema5c(0), ema5p1(0), ema5p2(0); ema20c(0), ema20p1(0), ema20p2(0), placedlines(False), spread2(2), filter(25); SetLoopCount(0); // use comment to print the daily open in the upper left. if (Period <= 60) then Comment("Current daily open = ", dailyopen, "\nLast MA cross/bounce: ", TimeToStr(lastcrosstime), ", ", lastcrossdir, " at ", lastcrossamount) else Comment("Last MA cross/bounce: ", TimeToStr(lastcrosstime), ", ", lastcrossdir, " at ", lastcrossamount); If (not placedlines) and (Period == 30) and (lastcrossamount > 0) Then Begin spread2 = (ask - bid + Point) / 2; // since the close is the median of the bid/ask. if (Symbol == "EURUSD") then filter = 20 * Point + spread2 else filter = 25 * Point + spread2; if lastcrossdir == "bull" then begin MoveObject("buy filter", OBJ_HLINE, lastcrosstime, lastcrossamount+filter, Time[0], lastcrossamount+filter, Blue, 1, STYLE_DASHDOT); DelObject("sell filter", 0, 0, 0, 0); end else begin MoveObject("sell filter", OBJ_HLINE, lastcrosstime, lastcrossamount-filter, Time[0], lastcrossamount-filter, Red, 1, STYLE_DASHDOT); DelObject("buy filter", 0, 0, 0, 0); end; placedlines = True; //Print("filter = ", filter, ", spread/2 = ", spread2, ", point = ", Point, ", bid = ", bid, ", ask= ", ask); End; // check conditions are ok. if Bars < 21 Or Bars = prevbars then exit; // check for additional bars loading or total reloading If Bars < prevbars or Bars-prevbars>1 Then first = True; prevbars = Bars; If first Then Begin // loopbegin prevent counting of counted bars exclude current loopbegin = min(Bars, 500); first = False; End; loopbegin += 2; // loop from first bar to current bar (with shift=0) For shift=loopbegin Downto 0 Begin if ((Period <= 60) and (TimeMinute(Time[shift]) == 0) and (TimeHour(Time[shift]) - TimeZoneOfData == 0)) then begin dailyopen = Open[shift]; end; SetIndexValue(shift, dailyopen); /*ema5c = iMAEx(5, MODE_EMA, 0, PRICE_CLOSE, shift); ema5p1 = iMAEx(5, MODE_EMA, 0, PRICE_CLOSE, shift+1); ema5p2 = iMAEx(5, MODE_EMA, 0, PRICE_CLOSE, shift+2);*/ ema20c = iMAEx(20, MODE_EMA, 0, PRICE_CLOSE, shift); ema20p1 = iMAEx(20, MODE_EMA, 0, PRICE_CLOSE, shift+1); ema20p2 = iMAEx(20, MODE_EMA, 0, PRICE_CLOSE, shift+2); diff0 = iMAEx(5, MODE_EMA, 0, PRICE_CLOSE, shift) - ema20c; diff1 = iMAEx(5, MODE_EMA, 0, PRICE_CLOSE, shift+1) - ema20p1; diff2 = iMAEx(5, MODE_EMA, 0, PRICE_CLOSE, shift+2) - ema20p2; SetIndexValue2(shift, 0); // bull signals: if (diff0 > 0) then begin if (diff1 < 0) then // simple bull cross. begin lastcrossdir = "bull"; placedlines = False; // determine which bar is closer to the cross: if (abs(diff0) < abs(diff1)) then begin lastcrosstime = Time[shift]; lastcrossamount = ema20c; SetIndexValue2(shift, lastcrossamount); end else lastcrosstime = Time[shift+1]; lastcrossamount = ema20p1; SetIndexValue2(shift+1, lastcrossamount); begin end; end else if (diff1 = 0 and diff2 < 0) then // exact cross on last bar. begin lastcrossdir = "bull"; lastcrosstime = Time[shift+1]; lastcrossamount = ema20p1; placedlines = False; SetIndexValue2(shift+1, lastcrossamount); end else if (diff1 > 0 and diff2 > diff1 and diff0 >= diff1 and diff1 <= PipsForBounce*Point) then // a bounce. begin lastcrossdir = "bull"; lastcrosstime = Time[shift+1]; lastcrossamount = ema20p1; placedlines = False; SetIndexValue2(shift+1, lastcrossamount); end; end else // bear signals: if (diff0 < 0) then begin if (diff1 > 0) then // simple bear cross. begin lastcrossdir = "bear"; placedlines = False; // determine which bar is closer to the cross: if (abs(diff0) < abs(diff1)) then begin lastcrosstime = Time[shift]; lastcrossamount = ema20c; SetIndexValue2(shift, lastcrossamount); end else lastcrosstime = Time[shift+1]; lastcrossamount = ema20p1; SetIndexValue2(shift+1, lastcrossamount); begin end; end else if (diff1 = 0 and diff2 > 0) then // exact cross on last bar. begin lastcrossdir = "bear"; lastcrosstime = Time[shift+1]; lastcrossamount = ema20p1; placedlines = False; SetIndexValue2(shift+1, lastcrossamount); end else if (diff1 < 0 and diff2 < diff1 and diff0 <= diff1 and abs(diff1) <= PipsForBounce*Point) then // a bounce. begin lastcrossdir = "bear"; lastcrosstime = Time[shift+1]; lastcrossamount = ema20p1; placedlines = False; SetIndexValue2(shift+1, lastcrossamount); end; end; loopbegin--; End;