//+-------------------------------------------------------------------+ //| Made/Modified by Alejandro Galindo /FAB4X | //| | //| If this work/modification is helpful to you | //| send me a PayPal donation to ag@elcactus.com | //| any help is apreciated :) | //| Thanks. | //+-------------------------------------------------------------------+ /*[[ Name := Pivot Point Breakout Author := Copyright © 2005 FAB4X Lots := 1.00 Stop Loss := 45 Take Profit := 75 Trailing Stop := 31 ]]*/ Define: TimeZoneofData(0); // NY 7,15; Define: StartHour(0); Define: StartMinute(0); Define: EndHour(23); Define: EndMinute(0); Define: FridayEndHour(21); Define: SecureProfit(20); Define: TrailSecureProfit(30); Define: TradeFriday(1); // 0- dont open trades on friday, 1- Trade on friday Define: DontReverse(1); Define: StartYear(2005); Define: TradesSet(2); Define: TypeSet(0); // 0 = NONE, 1 = SELL, 2 = BUY Define: ReverseSet(0); // 0=False, 1=True Define: mm(0); Define: risk(7); define: bps(15),sps(15); var: Today(0), RefDate(0), LastBarOfDay(0), FirstBarOfDay(0), Loop(0); var: pre_lo(0), pre_HI(0), myC(0), myO(0); var: cnt(0); var: lotsi(0); var: OpenTrades(0), FilledOrders(0); var: Slippage(5); var: BuyPrice(0), SellPrice(0); var: TimetoOpen(0), TimetoClose(0), tmp(0), i(0); var: Trades(2), Type("NONE"), Reverse(False); var: mode(0); var: myEndHour(0), myFridayEndHour(0), myStartHour(0); Var: FirstTime(True); var: range(0); var: hi_pass(0); var: lo_pass(0); var: mp(0); var: er_hi(0); var: er_lo(0); var: erange(0),erange2(0); var: r3(0); var: diffs(0),diffb(0),p(0); Var : shift(0); Var : sum(0); Var : v1(0); Var : v2(0); Var : fractal(0); Var : v45(0); Var : mml00(0); Var : mml0(0); Var : mml1(0); Var : mml2(0); Var : mml3(0); Var : mml4(0); Var : mml5(0); Var : mml6(0); Var : mml7(0); Var : mml8(0); Var : mml9(0); Var : mml98(0); Var : mml99(0); Var : octave(0); Var : mn(0); Var : mx(0); Var : finalH(0); Var : finalL(0); Var : x1(0); Var : x2(0); Var : x3(0); Var : x4(0); Var : x5(0); Var : x6(0); Var : y1(0); Var : y2(0); Var : y3(0); Var : y4(0); Var : y5(0); Var : y6(0); If TimeYear(time)EndYear then Exit; //If TimeMonth(Time)>EndMonth then Exit; if Curtime - LastTradeTime < 11 then exit; if mm<>0 then lotsi=Ceil(Balance*risk/10000)/10 else lotsi=Lots; if lotsi>100 then lotsi=100; if (FirstTime) then { if (TradesSet<>2 OR TypeSet<>0 OR ReverseSet<>0) then { Trades = TradesSet; if TypeSet == 0 then Type = "NONE"; if TypeSet == 1 then Type = "SELL"; if TypeSet == 2 then Type = "BUY"; if ReverseSet ==0 then Reverse = False; if ReverseSet ==1 then Reverse = True; }; FirstTime=False; }; Today=Floor(CurTime/86400)*86400; Cnt=1; If Today<>RefDate Then { // print("Today=",TimeToStr(Today)); RefDate=Today; While (Cnt<(Bars-1)) & (T[Cnt]-TimeZoneOfData*3600>=RefDate) { Cnt++; }; LastBarOfDay=Cnt; if DayofWeek==2 then RefDate=Today-86400*3 else RefDate=Today-86400; // print("RefDate=",TimeToStr(RefDate)); While (Cnt<(Bars-1)) & (T[Cnt]-TimeZoneOfData*3600>=RefDate) { Cnt++; }; FirstBarOfDay=Cnt-1; }; v2=High[1]; v1=Low[1]; //v2=High[highest(MODE_HIGH,FirstBarOfDay,FirstBarOfDay-LastBarOfDay+1)]; //v1=Low[Lowest(MODE_LOW,FirstBarOfDay,FirstBarOfDay-LastBarOfDay+1)]; myC=Close[LastBarOfDay]; // v1 = (L[lowest(MODE_LOW,beginer,periodtotake)]); //price H // v2 = (H[highest(MODE_HIGH,beginer,periodtotake)]); //price L //determine fractal..... If v2 <= 250000 AND V2 > 25000 Then fractal = 100000 Else If v2 <= 25000 AND V2 > 2500 Then fractal = 10000 Else If v2 <= 2500 AND V2 > 250 Then fractal = 1000 Else If v2 <= 250 AND V2 > 25 Then fractal = 100 Else If v2 <= 25 AND V2 > 12.5 Then fractal = 12.5 Else If v2 <= 12.5 AND V2 > 6.25 Then fractal = 12.5 Else If v2 <= 6.25 AND V2 > 3.125 Then fractal = 6.25 Else If v2 <= 3.125 AND V2 > 1.5625 Then fractal = 3.125 Else If v2 <= 1.5625 AND V2 > 0.390625 Then fractal = 1.5625 Else If v2 <= 0.390625 AND V2 > 0 Then fractal = 0.1953125; range = (v2 - v1); sum = Floor(log(fractal / range) / log(2)); octave = fractal * (pow(0.5,sum)); mn = Floor(v1 / octave) * octave; If (mn + octave) > v2 Then mx = mn + octave Else mx = mn + (2 * octave); // calculating xx If (v1 >= 3 / 16 * (mx - mn) + mn) and (v2 <= 9 / 16 * (mx - mn) + mn) Then x2 = mn + (mx - mn) / 2 Else x2 = 0; //x2 If (v1 >= mn - (mx - mn) / 8) and (v2 <= 5 / 8 * (mx - mn) + mn) and x2 = 0 Then x1 = mn + (mx - mn) / 2 Else x1 = 0; //x1 If (v1 >= mn + 7 * (mx - mn) / 16) and (v2 <= 13 / 16 * (mx - mn) + mn) Then x4 = mn + 3 * (mx - mn) / 4 Else x4 = 0; //x4 If (v1 >= mn + 3 * (mx - mn) / 8) and (v2 <= 9 / 8 * (mx - mn) + mn) and x4 = 0 Then x5 = mx Else x5 = 0; //x5 If (v1 >= mn + (mx - mn) / 8) & (v2 <= 7 / 8 * (mx - mn) + mn) & x1 = 0 & x2 = 0 & x4 = 0 & x5 = 0 Then x3 = mn + 3 * (mx - mn)/4 Else x3 = 0; //x3 If x1 + x2 + x3 + x4 + x5 = 0 Then x6 = mx Else x6 = 0; //x6 finalH = x1 + x2 + x3 + x4 + x5 + x6; // calculating yy If x1 > 0 Then y1 = mn Else y1 = 0; //y1 If x2 > 0 Then y2 = mn + (mx - mn) / 4 Else y2 = 0; //y2 If x3 > 0 Then y3 = mn + (mx - mn) / 4 Else y3 = 0; //y3 If x4 > 0 Then y4 = mn + (mx - mn) / 2 Else y4 = 0; //y4 If x5 > 0 Then y5 = mn + (mx - mn) / 2 Else y5 =0 ; //y5 If finalH > 0 and (y1 + y2 + y3 + y4 + y5 = 0) Then y6 = mn Else y6 = 0; //y6 finalL = y1 + y2 + y3 + y4 + y5 + y6; v45 = (finalH - finalL) / 8; mml00 = (finalL - v45 * 2); //-2/8 mml0 = (finalL - v45); //-1/8 mml1 = (finalL); // 0/8 mml2 = (finalL + v45); // 1/8 mml3 = (finalL + 2 * v45); // 2/8 mml4 = (finalL + 3 * v45); // 3/8 mml5 = (finalL + 4 * v45); // 4/8 mml6 = (finalL + 5 * v45); // 5/8 mml7 = (finalL + 6 * v45); // 6/8 mml8 = (finalL + 7 * v45); // 7/8 mml9 = (finalL + 8 * v45); // 8/8 mml99 = (finalL + 9 * v45); //+1/8 mml98 = (finalL + 10 * v45); //+2/8 MoveObject("mml1",OBJ_HLINE,time,mml1,time,mml1,RED,1,STYLE_SOLID); MoveObject("mml0",OBJ_HLINE,time,mml0,time,mml0,RED,1,STYLE_SOLID); MoveObject("mml00",OBJ_HLINE,time,mml00,time,mml00,RED,1,STYLE_SOLID); MoveObject("mml9",OBJ_HLINE,time,mml9,time,mml9,LimeGreen,1,STYLE_SOLID); MoveObject("mml99",OBJ_HLINE,time,mml99,time,mml99,LimeGreen,1,STYLE_SOLID); MoveObject("mml98",OBJ_HLINE,time,mml98,time,mml98,LimeGreen,1,STYLE_SOLID); SetObjectText("mml1_txt","SELL Here ","Arial",7,White); MoveObject("mml1_txt",OBJ_TEXT,time,mml1,time,mml1,White); SetObjectText("mml0_txt","SELL Here ","Arial",7,White); MoveObject("mml0_txt",OBJ_TEXT,time,mml0,time,mml0,White); SetObjectText("mml00_txt","SELL Here ","Arial",7,White); MoveObject("mml00_txt",OBJ_TEXT,time,mml00,time,mml00,White); SetObjectText("mml9_txt","BUY Here ","Arial",7,White); MoveObject("mml9_txt",OBJ_TEXT,time,mml9,time,mml9,White); SetObjectText("mml99_txt","BUY Here ","Arial",7,White); MoveObject("mml99_txt",OBJ_TEXT,time,mml99,time,mml99,White); SetObjectText("mml98_txt","BUY Here ","Arial",7,White); MoveObject("mml98_txt",OBJ_TEXT,time,mml98,time,mml98,White); comment(" PLACE A SELL ORDER AT ", mml1 ," or ",mml0," or ",mml00, "\n PLACE A BUY ORDER AT " , mml9," or ", mml99 ," or ", mml98,"\n ASK ",priceask, " BID ", pricebid ); OpenTrades=0; For cnt=1 to TotalTrades{ if OrderValue(cnt,VAL_SYMBOL)==Symbol then { OpenTrades++; If OrderValue(cnt,VAL_TYPE)==OP_SELL OR OrderValue(cnt,VAL_TYPE)==OP_BUY then { FilledOrders++; }; }; }; // We calculate the endHour based on the TimeZoneofData value cnt=0; i=TimeZoneofData; While (cnt<=EndHour) { if (i>23) then i=0; myEndHour=i; i++; cnt++; }; // Friday end of day offset //cnt=0; //i=TimeZoneofData; //While (cnt<=FridayEndHour) //{ // if (i>23) then i=0; // myFridayEndHour=i; // i++; // cnt++; //}; myFridayEndHour=FridayEndHour; if (Hour==myEndHour and Minute>=EndMinute) OR (DayOfWeek==6 AND Hour==myFridayEndHour AND Minute>=EndMinute) then { //cnt=0;While cnt<=10000 { cnt++; }; For cnt=1 to TotalTrades { mode = OrderValue(cnt,VAL_TYPE); If OrderValue(cnt,VAL_SYMBOL)==Symbol then { Trades=2; Type="NONE"; Reverse=False; If (mode == OP_BUYSTOP) then DeleteOrder(OrderValue(cnt,VAL_TICKET),Brown); If (mode == OP_SELLSTOP) then DeleteOrder(OrderValue(cnt,VAL_TICKET),Brown); If (mode == OP_BUYlimit) then DeleteOrder(OrderValue(cnt,VAL_TICKET),Brown); If (mode == OP_SELLlimit) then DeleteOrder(OrderValue(cnt,VAL_TICKET),Brown); If (mode == OP_BUY) then CloseOrder(ord(cnt,VAL_TICKET),ord(cnt,VAL_LOTS),bid,Slippage,Blue); If (mode == OP_SELL) then CloseOrder(ord(cnt,VAL_TICKET),ord(cnt,VAL_LOTS),ask,Slippage,red); Exit; }; }; }; // We get the StartHour offset cnt=0; i=TimeZoneofData; While (cnt<=StartHour) { if (i>23) then i=0; myStartHour=i; i++; cnt++; }; if (TradeFriday ==1 OR DayOfWeek<>6) then { if (Hour==myStartHour and Minute>=StartMinute) then { //if (open > buyprice) or (open < sellprice) then exit; If OpenTrades<1 then { // if (c[1] > p) then // { // Trades=1; // Type="NONE"; // Reverse=True; // SetOrder(OP_BUYSTOP,Lotsi,BuyPrice,Slippage,BuyPrice-StopLoss*Point,BuyPrice+TakeProfit*Point,blue); // // } // if (c[1] > mml1) then // { /// Trades=1; // Type="NONE"; // Reverse=True; // SetOrder(OP_BUYLIMIT,Lotsi,mml1,Slippage,mml1-StopLoss*Point,mml1+TakeProfit*Point,blue); // } if (c[1] > mml1) then { Trades=1; Type="NONE"; Reverse=True; SetOrder(OP_SELLSTOP,Lotsi,mml1,Slippage,mml1+StopLoss*Point,mml1-TakeProfit*Point,Red); } // if (c[1] < sellprice) then // { // Trades=1; // Type="NONE"; // Reverse=True; // SetOrder(OP_SELLLIMIT,Lotsi,SellPrice,Slippage,SellPrice+StopLoss*Point,SellPrice-TakeProfit*Point,Red); // // }; }; }; }; // if we only have one Stop order we place the another one to always have ready both sides If OpenTrades==1 and Trades>=1 then { for cnt=1 to TotalTrades { if (OrderValue(cnt,VAL_SYMBOL) == Symbol) then { if OrderValue(cnt,VAL_TYPE)==OP_SELLSTOP OR OrderValue(cnt,VAL_TYPE)==OP_SELLLIMIT then { if (c[1] < mml9) then { Trades=1; Type="NONE"; Reverse=True; SetOrder(OP_BUYSTOP,Lotsi,mml9,Slippage,mml9-StopLoss*Point,mml9+TakeProfit*Point,blue); Exit; } // if (c[1] > buyprice) then // { // Trades=1; // Type="NONE"; // Reverse=True; // SetOrder(OP_BUYlimit,Lotsi,BuyPrice,Slippage,BuyPrice-StopLoss*Point,BuyPrice+TakeProfit*Point,blue); // Exit; // } }; // if OrderValue(cnt,VAL_TYPE)==OP_BUYSTOP OR OrderValue(cnt,VAL_TYPE)==OP_BUYLIMIT then // { // if (c[1] > sellprice) then // { // Trades=1; // Type="NONE"; // Reverse=True; // SetOrder(OP_SELLSTOP,Lotsi,SellPrice,Slippage,SellPrice+StopLoss*Point,SellPrice-TakeProfit*Point,Red); // Exit; // } // if (c[1] < mml9) then // { // Trades=1; // Type="NONE"; // Reverse=True; // SetOrder(OP_SELLLIMIT,Lotsi,mml9,Slippage,mml9+StopLoss*Point,mml9-TakeProfit*Point,Red); // Exit; // } // }; }; }; }; if (DontReverse==1) then Reverse=False; // if one order was closed we reverse (only once in a day) If OpenTrades<1 and Trades==1 and Reverse then { if Type=="BUY") then { Trades=0; Type="NONE"; Reverse=False; SetOrder(OP_BUY,Lotsi,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,Blue); Exit; }; if Type=="SELL") then { Trades=0; Type="NONE"; Reverse=False; SetOrder(OP_SELL,Lotsi,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,Red); Exit; }; }; // if we have opened positions we take care of them for cnt=1 to TotalTrades { if OrderValue(cnt,VAL_SYMBOL) == Symbol then { if OrderValue(cnt,VAL_TYPE) == OP_BUY then { for i=1 to TotalTrades { if (OrderValue(i,VAL_SYMBOL)==Symbol) then { if OrderValue(i,VAL_TYPE)==OP_SELLSTOP OR OrderValue(i,VAL_TYPE)==OP_BUYSTOP OR OrderValue(i,VAL_TYPE)==OP_SELLLIMIT OR OrderValue(i,VAL_TYPE)==OP_BUYLIMIT then { // if OrderValue(i,VAL_TYPE)==OP_SELLLIMIT OR OrderValue(i,VAL_TYPE)==OP_BUYLIMIT then // { Trades=1; Type="SELL"; Reverse=True; DeleteOrder(OrderValue(i,VAL_TICKET),brown); Exit; // }; }; }; }; //We secure SecureProfit (10) pips after TrailSecureProfit (16) pips if Ord(cnt,VAL_STOPLOSS)<=(Ord(cnt,VAL_OPENPRICE)-(StopLoss*Point)) and ((Bid-(Ord(cnt,VAL_OPENPRICE)))>=TrailSecureProfit*Point) then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE),((Ord(cnt,VAL_OPENPRICE))+SecureProfit*Point),0,DeepSkyBlue); Trades=0; Type="NONE"; Reverse=False; tmp=(Ord(cnt,VAL_OPENPRICE))+SecureProfit*Point; Print("BUY Stoploss trailed to Openprice+SecureProfit=",tmp); Exit; }; // Trailing stop after profit secured If TrailingStop>0 then { If (Bid-OrderValue(cnt,VAL_OPENPRICE))>(SecureProfit+TrailingStop)*Point then { If OrderValue(cnt,VAL_STOPLOSS)<(Bid-Point*(TrailingStop+SecureProfit)) then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),Bid-Point*(SecureProfit+TrailingStop),0,Yellow); Trades=0; Type="NONE"; Reverse=False; Exit; }; }; }; }; if OrderValue(cnt,VAL_TYPE) == OP_SELL then { for i=1 to TotalTrades { if (OrderValue(i,VAL_SYMBOL)==Symbol) then { if OrderValue(i,VAL_TYPE)==OP_SELLSTOP OR OrderValue(i,VAL_TYPE)==OP_BUYSTOP OR OrderValue(i,VAL_TYPE)==OP_SELLLIMIT OR OrderValue(i,VAL_TYPE)==OP_BUYLIMIT then { // if OrderValue(i,VAL_TYPE)==OP_SELLLIMIT OR OrderValue(i,VAL_TYPE)==OP_BUYLIMIT then // { Trades=1; Type="BUY"; Reverse=True; DeleteOrder(OrderValue(i,VAL_TICKET),brown); Exit; // }; }; }; }; //We secure SecureProfit (10) pips after TrailSecureProfit (16) pips if Ord(cnt,VAL_STOPLOSS)>=(Ord(cnt,VAL_OPENPRICE)+(StopLoss*Point)) and (((Ord(cnt,VAL_OPENPRICE)-Ask))>=TrailSecureProfit*Point) then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE),((Ord(cnt,VAL_OPENPRICE))-SecureProfit*Point),0,DeepSkyBlue); Trades=0; Type="NONE"; Reverse=False; tmp=(Ord(cnt,VAL_OPENPRICE))-SecureProfit*Point; Print("SELL Stoploss trailed to Openprice-SecureProfit=",tmp); Exit; }; If TrailingStop>0 then { If (OrderValue(cnt,VAL_OPENPRICE)-Ask)>(Point*(TrailingStop+SecureProfit)) then { if OrderValue(cnt,VAL_STOPLOSS)>(Ask+Point*(TrailingStop+SecureProfit)) then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),Ask+Point*(TrailingStop+SecureProfit),0,Purple); Trades=0; Type="NONE"; Reverse=False; Exit; }; }; }; }; }; }; //Alert(StrToTime("2005.11.30")); Exit;