//+-------------------------------------------------------------------+ //| Made/Modified by Alejandro Galindo | //| | //| If this work/modification is helpful to you | //| send me a PayPal donation to ag@elcactus.com | //| any help is apreciated :) | //| Thanks. | //+-------------------------------------------------------------------+ /*[[ Name := BreakOut 50/50 Author := Copyright © 2005 FAB4X Lots := 1.00 Stop Loss := 45 Take Profit := 75 Trailing Stop := 61 ]]*/ Define: TimeZoneofData(0); // NY 7,15; Define: StartHour(0); Define: StartMinute(0); Define: EndHour(23); Define: EndMinute(0); Define: FridayEndHour(21); Define: SecureProfit(50); Define: TrailSecureProfit(60); 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(50),sps(50); 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); 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; }; pre_hi=High[1]; pre_lo=Low[1]; myC=Close[1]; // *** calculate all the 10pip numbers *** hi_pass = pre_hi + 0.002 ; lo_pass = pre_lo - 0.002 ; mp = (((pre_hi - pre_lo) / 2) + pre_lo); erange = (pre_hi - pre_lo); // *** which entry range amount to use? *** // *** less than 160 range *** IF (erange <= 0.016) THEN (r3 = 0.004) ELSE (r3 = (erange * 0.25)) END; // *** set entry range *** er_hi = (pre_hi - r3); er_lo = (pre_lo + r3); erange2= (er_hi - er_lo)*10000; // *** print the numbers on the chart for reference *** //Comment("BUY @ ", er_hi,"\nSELL @ ", er_lo); // *** draw the lines on the chart *** // *** special case for ER if range < 80 *** // *** Prints an advisory message on the screen *** IF (erange <= 0.008) THEN { SetObjectText("LT80_txt","RANGE<80 ","Arial",10,White); MoveObject("LT80_txt",OBJ_TEXT,time[35],mp,time[35],mp,White); } BUYPRICE=myc+bps*point; SELLPRICE=myc-sps*point; // *** Draw lines *** //MoveObject("MP",OBJ_HLINE,time[25],mp,Time[25],mp,Yellow,linethickness,STYLE_DOT); MoveObject("BUYPRICE",OBJ_HLINE,time[25],BUYPRICE,Time[25],BUYPRICE,lime,1,STYLE_DASH); MoveObject("SELLPRICE",OBJ_HLINE,time[25],SELLPRICE,Time[25],SELLPRICE,red,1,STYLE_DASH); //MoveObject("Hi_Pass",OBJ_HLINE,time[25],hi_pass,time[25],hi_pass,lime,linethickness,STYLE_DOT); //MoveObject("Lo_Pass",OBJ_HLINE,time[25],lo_pass,Time[25],lo_pass,red,linethickness,STYLE_DOT); //MoveObject("Pre_Hi",OBJ_HLINE,time[25],pre_hi,Time[25],pre_hi,Yellow,linethickness,STYLE_DASH); //MoveObject("Pre_Lo",OBJ_HLINE,time[25],pre_lo,Time[25],pre_lo,Yellow,linethickness,STYLE_DASH); // *** label the lines *** //SetObjectText("MP_txt","MP ","Arial",8,White); //MoveObject("MP_txt",OBJ_TEXT,time[25],mp,time[25],mp,White); SetObjectText("BUYPRICE_txt","BUY HERE ","Arial",8,White); MoveObject("BUYPRICE_txt",OBJ_TEXT,time[25],BUYPRICE,time[25],BUYPRICE,White); SetObjectText("SELLPRICE_txt","SELL HERE ","Arial",8,White); MoveObject("SELLPRICE_txt",OBJ_TEXT,time[25],SELLPRICE,time[25],SELLPRICE,White); //SetObjectText("Hi_Pass_txt","HiPASS ","Arial",8,White); //MoveObject("Hi_Pass_txt",OBJ_TEXT,time[25],hi_Pass,time[25],hi_pass,White); //SetObjectText("Lo_Pass_txt","LoPASS ","Arial",8,White); //MoveObject("Lo_Pass_txt",OBJ_TEXT,time[25],lo_pass,time[25],lo_pass,White); //SetObjectText("Pre_Hi_txt","PreHI ","Arial",8,White); //MoveObject("Pre_Hi_txt",OBJ_TEXT,time[25],pre_hi,time[25],pre_hi,White); //SetObjectText("Pre_Lo_txt","PreLO ","Arial",8,White); //MoveObject("Pre_Lo_txt",OBJ_TEXT,time[25],pre_lo,time[25],pre_lo,White); Comment("BUY @ ", BUYPRICE,"\nSELL @ ", SELLPRICE,"\nErange ", erange2); 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] < buyprice) then { Trades=1; Type="NONE"; Reverse=True; SetOrder(OP_BUYSTOP,Lotsi,BuyPrice,Slippage,BuyPrice-StopLoss*Point,BuyPrice+TakeProfit*Point,blue); } if (c[1] > buyprice) then { Trades=1; Type="NONE"; Reverse=True; SetOrder(OP_BUYLIMIT,Lotsi,BuyPrice,Slippage,BuyPrice-StopLoss*Point,BuyPrice+TakeProfit*Point,blue); } if (c[1] > sellprice) then { Trades=1; Type="NONE"; Reverse=True; SetOrder(OP_SELLSTOP,Lotsi,SellPrice,Slippage,SellPrice+StopLoss*Point,SellPrice-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] < buyprice) then { Trades=1; Type="NONE"; Reverse=True; SetOrder(OP_BUYSTOP,Lotsi,BuyPrice,Slippage,BuyPrice-StopLoss*Point,BuyPrice+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] < sellprice) then { Trades=1; Type="NONE"; Reverse=True; SetOrder(OP_SELLLIMIT,Lotsi,SellPrice,Slippage,SellPrice+StopLoss*Point,SellPrice-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;