/*[[ Name := Author := Jesse Breaker Link := http://www.metaquotes.net/ Lots := 4 Stop Loss := 0 Take Profit := 0 Trailing Stop := 0 ]]*/ Define: FibLevel1(89),FibLevel2(144),FibLevel3(233); Var: FoundSymbol(0),CloseAllBuys(0),CloseAllSells(0),Place4Buys(0),Place4BuysCNT(0),Place4Sells(0),Place4SellsCNT(0),NewBar(0),Slippage(5),Ldirection(0),SMA55(0),SMA55Prev(0); //defaults are for eur/usd Var: Fib1Flag(0),Fib2Flag(0),Fib3Flag(0),FreeTradeFlag(0),ValidSell(0),ValidBuy(0),BTStop1(0),BTStop2(0),SL(0),vSL(0),cnt(0),PosFib1(0),PosFib2(0),PosFib3(0),NegFib1(0),NegFib2(0),NegFib3(0); var: OpenTradesThisSymbol(0),OpenSellsThisSymbol(0),OpenBuysThisSymbol(0),CloseAboveSMA(0),CloseBelowSMA(0); If CurTime - LastTradeTime < 15 Then Exit; Comment("\n","Day : ",Day," Hour : ",Hour," Min ",Minute," Seconds ", Seconds, "\n","Version 0.8 Vegas Fibs", "\n",Symbol," Close Above SMA =",CloseAboveSMA," Close Below SMA =",CloseBelowSMA, "\n","Low Frame Direction=",LDirection, "\n","BTStop1(Buy SL)=",BTStop1," BTStop2(Sell SL)=",BTStop2," vSL=",vSL, "\n","Valid Sell =",ValidSell," Valid Buy =",ValidBuy, "\n","PosFib1 = ",PosFib1," PosFib2 = ",PosFib2," PosFib3 = ",PosFib3, "\n","NegFib1 = ",NegFib1," NegFib2 = ",NegFib2," NegFib3 = ",NegFib3, "\n","Fib1Flag = ",Fib1Flag," Fib2Flag = ",Fib2Flag," Fib3Flag = ",Fib3Flag, "\n","Open Buys=",OpenBuysThisSymbol," Open Sells=",OpenSellsThisSymbol); OpenBuysThisSymbol=0; for cnt=1 to TotalTrades { If OrderValue(cnt,VAL_SYMBOL)=Symbol and OrderValue(cnt,VAL_TYPE) == OP_BUY then { OpenBuysThisSymbol++; }; }; If OpenBuysThisSymbol !=0 then { If High[0] >= PosFib1 and Fib1Flag == 0 then { Fib1Flag=1; CloseOrder(OrderValue(1,VAL_TICKET),1,Bid,5,Violet); exit; }; If High[0] >= PosFib2 and Fib2Flag == 0 then { Fib2Flag=1; CloseOrder(OrderValue(1,VAL_TICKET),1,Bid,5,Violet); exit; }; If High[0] >= PosFib3 and Fib3Flag == 0 then { Fib3Flag=1; CloseOrder(OrderValue(1,VAL_TICKET),1,Bid,5,Violet); exit; }; If Close[1] < SMA55 and LDirection == -1 then { CloseAllBuys=1; }; }; OpenSellsThisSymbol=0; for cnt=1 to TotalTrades { If OrderValue(cnt,VAL_SYMBOL)=Symbol and OrderValue(cnt,VAL_TYPE) == OP_SELL then { OpenSellsThisSymbol++; }; }; If OpenSellsThisSymbol !=0 then { If Low[0] <= NegFib1 and Fib1Flag == 0 then { Fib1Flag=1; CloseOrder(OrderValue(1,VAL_TICKET),1,Ask,5,Violet); exit; }; If Low[0] <= NegFib2 and Fib2Flag == 0 then { Fib2Flag=1; CloseOrder(OrderValue(1,VAL_TICKET),1,Ask,5,Violet); exit; }; If Low[0] <= NegFib3 and Fib3Flag == 0 then { Fib3Flag=1; CloseOrder(OrderValue(1,VAL_TICKET),1,Ask,5,Violet); exit; }; If Close[1] > SMA55 and LDirection == 1 then { CloseAllSells=1; }; }; If OpenSellsThisSymbol == 0 and OpenBuysThisSymbol == 0 then { Fib1Flag=0; Fib2Flag=0; Fib3Flag=0; }; If CloseAllBuys == 1 then { FoundSymbol=0; for cnt=1 to TotalTrades { If OrderValue(cnt,VAL_SYMBOL)=Symbol then { FoundSymbol=1; If OrderValue(cnt,VAL_TYPE)=OP_BUY then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,5,Violet); exit; }; }; } If FoundSymbol == 0 then { CloseAllBuys = 0; }; exit; }; If CloseAllSells == 1 then { FoundSymbol=0; for cnt=1 to TotalTrades { If OrderValue(cnt,VAL_SYMBOL)=Symbol then { FoundSymbol=1; If OrderValue(cnt,VAL_TYPE)=OP_SELL then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),ask,5,Violet); exit; }; }; } If FoundSymbol == 0 then { CloseAllSells = 0; }; exit; }; CloseAllBuys = 0; CloseAllSells = 0; If NewBar != t[0] Then { NewBar = t[0]; PosFib1=ima(55,MODE_SMA,1)+FibLevel1*Point; PosFib2=ima(55,MODE_SMA,1)+FibLevel2*Point; PosFib3=ima(55,MODE_SMA,1)+FibLevel3*Point; NegFib1=ima(55,MODE_SMA,1)-FibLevel1*Point; NegFib2=ima(55,MODE_SMA,1)-FibLevel2*Point; NegFib3=ima(55,MODE_SMA,1)-FibLevel3*Point; SMA55=ima(55,MODE_SMA,1); SMA55Prev=ima(55,MODE_SMA,2); BTStop1=icustom("BrainTrend2StopLine",MODE_FIRST,1); BTStop2=icustom("BrainTrend2StopLine",MODE_SECOND,1); LDirection=0; If BTStop1 != -1 and BTStop2 == -1 then { LDirection=1; }; If BTStop2 != -1 and BTStop1 == -1 then { LDirection=-1; }; vSL=0; If BTStop1 == -1 and (BTStop2 !=-1 or BTStop2 !=0) then { vSL=PosFib1; }; If BTStop2 == -1 and (BTStop1 !=-1 or BTStop1 !=0) then { vSL=NegFib1; }; LDirection=0; If BTStop1 != -1 and BTStop2 == -1 then { LDirection=1; }; If BTStop2 != -1 and BTStop1 == -1 then { LDirection=-1; }; CloseAboveSMA=0; CloseBelowSMA=0; If (Close[1] > SMA55 and Close[2] < SMA55Prev) then { CloseAboveSMA = 1; CloseBelowSMA = 0; }; If (Close[1] < SMA55 and Close[2] > SMA55Prev) then { CloseAboveSMA = 0; CloseBelowSMA = 1; }; ValidBuy=0; ValidSell=0; If CloseAboveSMA == 1 and LDirection == 1 then { ValidBuy = 1; }; If CloseBelowSMA == 1 and LDirection == -1 then { ValidSell = 1; }; If ValidSell == 1 then { OpenBuysThisSymbol=0; for cnt=1 to TotalTrades { If OrderValue(cnt,VAL_SYMBOL)=Symbol and OrderValue(cnt,VAL_TYPE) == OP_BUY then { OpenBuysThisSymbol++; }; }; If OpenBuysThisSymbol !=0 then { Fib1Flag=0; Fib2Flag=0; Fib3Flag=0; SetOrder(OP_SELL,Lots,ask,slippage,vSL,0,blue); CloseAllBuys = 1; exit; }; }; If ValidBuy == 1 then { OpenBuysThisSymbol=0; for cnt=1 to TotalTrades { If OrderValue(cnt,VAL_SYMBOL)=Symbol and OrderValue(cnt,VAL_TYPE) == OP_Sell then { OpenSellsThisSymbol++; }; }; If OpenSellsThisSymbol !=0 then { Fib1Flag=0; Fib2Flag=0; Fib3Flag=0; FreeTradeFlag=0; SetOrder(OP_BUY,Lots,ask,slippage,vSL,0,blue); CloseAllSells = 1; exit; }; }; OpenTradesThisSymbol=0; for cnt=1 to TotalTrades { If OrderValue(cnt,VAL_SYMBOL)=Symbol then { OpenTradesThisSymbol++; }; }; If OpenTradesThisSymbol == 0 then { If ValidBuy = 1 then { Fib1Flag=0; Fib2Flag=0; Fib3Flag=0; FreeTradeFlag=0; SetOrder(OP_BUY,Lots,ask,slippage,vSL,0,blue); exit; }; If ValidSell = 1 then { Fib1Flag=0; Fib2Flag=0; Fib3Flag=0; FreeTradeFlag=0; SetOrder(OP_SELL,Lots,ask,slippage,vSL,0,blue); exit; }; }; }; cnt=0; MoveObject("Plus Fib Lvl 3",OBJ_HLINE,time[cnt],PosFib3,time[cnt],PosFib3,YellowGreen,1,STYLE_DOT); MoveObject("Plus Fib Lvl 2",OBJ_HLINE,time[cnt],PosFib2,time[cnt],PosFib2,SkyBlue,1,STYLE_DOT); MoveObject("Plus Fib Lvl 1",OBJ_HLINE,time[cnt],PosFib1,time[cnt],PosFib1,YellowGreen,1,STYLE_DOT); MoveObject("Negative Fib Lvl 1",OBJ_HLINE,time[cnt],NegFib1,time[cnt],NegFib1,SkyBlue,1,STYLE_DOT); MoveObject("Negative Fib Lvl 2",OBJ_HLINE,time[cnt],NegFib2,time[cnt],NegFib2,YellowGreen,1,STYLE_DOT); MoveObject("Negative Fib Lvl 3",OBJ_HLINE,time[cnt],NegFib3,time[cnt],NegFib3,SkyBlue,1,STYLE_DOT); SetObjectText("Plus Fib Lvl 3"," Plus Fib Lvl 3 ","Arial",9,White); MoveObject("Plus Fib Lvl 3",OBJ_TEXT,time[0],PosFib3,time[0],PosFib3,White); SetObjectText("Plus Fib Lvl 2"," Plus Fib Lvl 2 ","Arial",9,White); MoveObject("Plus Fib Lvl 2",OBJ_TEXT,time[0],PosFib2,time[0],PosFib2,White); SetObjectText("Plus Fib Lvl 1"," Plus Fib Lvl 1 ","Arial",9,White); MoveObject("Plus Fib Lvl 1",OBJ_TEXT,time[0],PosFib1,time[0],PosFib1,White); SetObjectText("Negative Fib Lvl 1"," Negative Fib Lvl 1 ","Arial",9,White); MoveObject("Negative Fib Lvl 1",OBJ_TEXT,time[0],NegFib1,time[0],NegFib1,White); SetObjectText("Negative Fib Lvl 2"," Negative Fib Lvl 2 ","Arial",9,White); MoveObject("Negative Fib Lvl 2",OBJ_TEXT,time[0],NegFib2,time[0],NegFib2,White); SetObjectText("Negative Fib Lvl 3"," Negative Fib Lvl 3 ","Arial",9,White); MoveObject("Negative Fib Lvl 3",OBJ_TEXT,time[0],NegFib3,time[0],NegFib3,White);