/*[[ Name := BMX BreakOut3 Author := Copyright © 2005, Lifestatic Link := Use H1 charts Lots := 0.1 Stop Loss := 0 Take Profit := 0 Trailing Stop := 0 ]]*/ // Defines; Defines: ProfitExit(100); Defines: ProfitEntry(20); Defines: dFreeMargin(1500); Defines: Slippage(4); // Slippage Defines: StopYear(2005); Vars: i(0),cnt(0); Vars: BuyThisSymbol(0),SellThisSymbol(0); Vars: LowestBuy(0),HighestSell(0); Vars: BuyNewLevel(0),SellNewLevel(0); Vars: CloseAll(0),TimeClock(0),TimeMin(0); Vars: LargestMarginUsed(0),LargestFloatingLoss(0); Vars: CloseSwitch(0),CloseSellFirst(0),CloseBuyFirst(0); Vars: LowestFreeMargin(0),HighestBuy(0),LowestSell(0); Vars: Spread(0),ModOrd(0),PricePoint(0),ProfitNeeded(0); Vars: OrderBalance(0),PipsNeeded(0),PricePointS(0),PricePointB(0); Vars: ModBuys(0),ModSells(0),vSlippage(0); // Presets; if year < stopyear then exit; If Curtime - LastTradeTime < 10 then Exit; If Margin > LargestMarginUsed then LargestMarginUsed = Margin; If TotalProfit < LargestFloatingLoss then LargestFloatingLoss = TotalProfit; If LowestFreeMargin == 0 then LowestFreeMargin = FreeMargin; If FreeMargin < LowestFreeMargin then LowestFreeMargin = FreeMargin; Spread= Ask-Bid; vSlippage=Slippage*point; BuyThisSymbol = 0; SellThisSymbol = 0; for i = 1 to TotalTrades { if ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_BUY then BuyThisSymbol = BuyThisSymbol + 1; if ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_SELL then SellThisSymbol = SellThisSymbol + 1; }; Comment("Buy trades: ",BuyThisSymbol,","," Sell trades: ",SellThisSymbol, "\nLargest Margin Used: ",NumberToStr(LargestMarginUsed,2),","," Largest Floating Loss: ",NumberToStr(LargestFloatingLoss,2),","," Lowest Free Margin: ",NumberToStr(LowestFreeMargin,2), "\nBalance: ",NumberToStr(Balance,2),","," Equity: ",NumberToStr(Equity,2),","," TotalProfit: ",NumberToStr(TotalProfit,2), "\nHighestSell: ",HighestSell,","," LowestBuy: ",LowestBuy, "\nHighestBuy: ",HighestBuy,","," LowestSell: ",LowestSell,"ModBuys:",",",ModBuys,"ModSells:",",",ModSells); ModBuys=0; ModSells=0; for i = 1 to TotalTrades { if ((ord(i,VAL_SYMBOL) == Symbol) and (ord(i,VAL_TYPE) == OP_BUY) and (ord(i,VAL_STOPLOSS)>0)) OR ((ord(i,VAL_SYMBOL) == Symbol) and (ord(i,VAL_TYPE) == OP_BUY) and (ord(i,VAL_TAKEPROFIT)>0)) then ModBuys = ModBuys + 1; if ((ord(i,VAL_SYMBOL) == Symbol) and (ord(i,VAL_TYPE) == OP_SELL) and (ord(i,VAL_STOPLOSS)>0)) OR ((ord(i,VAL_SYMBOL) == Symbol) and (ord(i,VAL_TYPE) == OP_SELL) and (ord(i,VAL_TAKEPROFIT)>0)) then ModSells = ModSells + 1; }; ////////////////////////////////////////////////////////////// // Modify Order Routine /////////////////////////////////////////////////////////////// If BuyThisSymbol >=SellThisSymbol*3 OR SellThisSymbol >=BuyThisSymbol*3 And CloseAll==0 Then { If ((TotalProfit > -100) And (BuyThisSymbol>=(SellThisSymbol*3))) Or (ModOrd==1) Then { If SellThisSymbol 0 and PricePointS==0 And ModOrd==0 Then { If TotalProfit <0 Then { ProfitNeeded= ProfitExit + TotalProfit; }; If TotalProfit >0 Then { ProfitNeeded= ProfitExit-TotalProfit; }; ModOrd=1; OrderBalance= BuyThisSymbol-SellThisSymbol; PipsNeeded= (ProfitNeeded/OrderBalance)*Point; PricePointS= Ask+ PipsNeeded; }; If OrderValue(cnt,VAL_TYPE)==OP_SELL and OrderValue(cnt,VAL_STOPLOSS)==0 And ModSellsSellThisSymbol and ModOrd==1 Then { PricePointB=PricePointS+Spread; If ((OrderValue(cnt,VAL_TYPE)==OP_BUY) and (OrderValue(cnt,VAL_TAKEPROFIT)==0) And (OrderValue(cnt,VAL_PROFIT)> 15) And (Bid<((PricePointB-Spread)-vSlippage))) Then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE),Ord(cnt,VAL_STOPLOSS),PricePointB,Yellow); Exit; }; If SellThisSymbol==0 and TotalProfit>=ProfitExit Then ModOrd=0; CloseAll=1; Exit; If Bid>=PricePointB-Spread Then PricePointB=Bid+10*Point; Exit; If ModBuys=ModSells*3 then ModOrd=0; Exit; }; }; If ((TotalProfit > -100) And (SellThisSymbol>=(BuyThisSymbol*3))) OR (ModOrd==2) Then { If BuyThisSymbol 0 and PricePointB==0 And ModOrd==0 Then { If TotalProfit <0 Then { ProfitNeeded= ProfitExit + TotalProfit; }; If TotalProfit >0 Then { ProfitNeeded= ProfitExit-TotalProfit; }; ModOrd=2; OrderBalance= BuyThisSymbol-SellThisSymbol; PipsNeeded= (ProfitNeeded/OrderBalance)*Point; PricePointB= Bid- PipsNeeded; }; If OrderValue(cnt,VAL_TYPE)==OP_BUY and OrderValue(cnt,VAL_STOPLOSS)==0 Then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE),PricePointB,Ord(cnt,VAL_TAKEPROFIT),Yellow); Exit; }; If ModBuysBuyThisSymbol and ModOrd==2 Then { PricePointS=PricePointB-Spread; If ((OrderValue(cnt,Val_type)==OP_SELL) and (OrderValue(cnt,VAL_TAKEPROFIT)==0) And (OrderValue(cnt,VAL_PROFIT)>15)And (Ask>((PricePointS-Spread)-vSlippage))) Then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE),Ord(cnt,VAL_STOPLOSS),PricePointS,Yellow); Exit; }; If BuyThisSymbol==0 and TotalProfit>=ProfitExit Then ModOrd=0; CloseAll=1; Exit; If Ask<=PricePointS+Spread Then PricePointS=Ask-10*Point; Exit; If ModSells=ModBuys*3 then ModOrd=0; Exit; }; }; }; //end here if buy or sell isn't tripple in size of the opposite orders /////////////////////////// // Reset Close first Variables //////////////////////////// If CloseBuyFirst==1 or CloseSellFirst==1 Then { If BuyThisSymbol==0 Then { CloseBuyFirst=0; }; If SellThisSymbol==0 Then { CloseSellFirst=0; }; }; // If Profit is positive, close all open positions; If TotalProfit > ProfitExit and CloseSwitch==0 then { CloseAll = 1; TimeClock = Hour; //give time to close all orders TimeMin = Minute; CloseSwitch=1; If BuyThisSymbol>SellThisSymbol then { CloseSellFirst=1; }; If SellThisSymbol>BuyThisSymbol Then { CloseBuyFirst=1; }; }; If ((TotalTrades == 0) And ((Hour-TimeClock)>=1)) then { If TimeMin<=20 OR Minute >=TimeMin Then { CloseAll = 0; CloseSwitch=0; ModOrd=0; PricePointS=0; PricePointB=0; }; }; If CloseAll == 1 then { for i = 1 to TotalTrades { If ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_BUY And (CloseBuyFirst==1)OR ((CloseBuyFirst==0) And (CloseSellFirst==0)) then { If Bid-OrderValue(i,VAL_OPENPRICE)<0 Then { CloseOrder(Ord(i,VAL_TICKET),Ord(i,VAL_LOTS),Bid,Slippage,LawnGreen); Exit; }; If Bid-OrderValue(i,VAL_OPENPRICE)>0 Then { CloseOrder(Ord(i,VAL_TICKET),Ord(i,VAL_LOTS),Bid,Slippage,Gold); Exit; }; }; If ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_SELL And (CloseSellFirst==1)OR ((CloseBuyFirst==0) And (CloseSellFirst==0)) then { If OrderValue(i,VAL_OPENPRICE)-Ask <0 Then { CloseOrder(Ord(i,VAL_TICKET),Ord(i,VAL_LOTS),Ask,Slippage,HotPink); Exit; }; If OrderValue(i,VAL_OPENPRICE)-Ask >0 Then { CloseOrder(Ord(i,VAL_TICKET),Ord(i,VAL_LOTS),Ask,Slippage,Gold); Exit; }; }; }; }; If (CloseAll==0) Then //If closing switch set to 1 we don't want any more new orders. { // Open First Trades; If Close[1]>High[2] OR Close[1]0) OR (SellThisSymbol>0) Then { If BuyThisSymbol = 0 and FreeMargin > dFreeMargin then { SetOrder(OP_BUY,Lots,Ask,Slippage,0,0,Blue); Exit; }; If SellThisSymbol = 0 and FreeMargin > dFreeMargin then { SetOrder(OP_SELL,Lots,Bid,Slippage,0,0,Red); Exit; }; //////////////////////////////////////////////////////// // Determine Highest Buy and Lowest Sell; //////////////////////////////////////////////////////// LowestBuy = 10; HighestSell = 0; HighestBuy = 0; LowestSell = 10; For i = 1 to TotalTrades { If ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_BUY and ord(i,VAL_OPENPRICE) < LowestBuy then LowestBuy = ord(i,VAL_OPENPRICE); If ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_SELL and ord(i,VAL_OPENPRICE) > HighestSell then HighestSell = ord(i,VAL_OPENPRICE); If ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_BUY and ord(i,VAL_OPENPRICE) > HighestBuy then HighestBuy = ord(i,VAL_OPENPRICE); If ord(i,VAL_SYMBOL) == Symbol and ord(i,VAL_TYPE) == OP_SELL and ord(i,VAL_OPENPRICE) < LowestSell then LowestSell = ord(i,VAL_OPENPRICE); }; // BuyNewLevel, SellNewLevel; BuyNewLevel = 0; SellNewLevel = 0; For i = 1 to TotalTrades { If ((ord(i,VAL_SYMBOL)== Symbol) and (ord(i,VAL_TYPE) == OP_BUY) and (ord(i,VAL_OPENPRICE) == Ask)) then BuyNewLevel = 1; If ((ord(i,VAL_SYMBOL)== Symbol) and (ord(i,VAL_TYPE) == OP_SELL) and (ord(i,VAL_OPENPRICE) == Bid)) then SellNewLevel = 1; }; //////////////////////////////////////////////////////// // Open additional trades on a grid; //////////////////////////////////////////////////////// If Ask > LowestBuy and BuyNewLevel = 0 and TotalProfit < ProfitEntry then { If FreeMargin < dFreeMargin then exit; SetOrder(OP_BUY,Lots,Ask,Slippage,0,0,Blue); Exit; }; If Bid < HighestSell and SellNewLevel = 0 and TotalProfit < ProfitEntry then { If FreeMargin < dFreeMargin then exit; SetOrder(OP_SELL,Lots,Bid,Slippage,0,0,Red); Exit; }; }; }; Exit;