/*[[ Name := BMX BreakOut2 Author := Copyright © 2005, Lifestatic Link := Use H1 charts Lots := 0.10 Stop Loss := 0 Take Profit := 0 Trailing Stop := 0 ]]*/ // Defines; Defines: ProfitTarget(100); Defines: Slippage(4); // Slippage Defines: StopYear(2005); Defines: dMargin(1500); Vars: i(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: PipsNeeded(0),ProfitNeeded(0),OrderBalance(0); Vars: ComSwitch(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; 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; }; If ComSwitch==0 Then 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, "Pips Needed to hit Target:","..",PipsNeeded); /////////////////////////////////////////////// // Calculations for pips needed to hit profit target //////////////////////////////////////////////// ProfitNeeded= ProfitTarget - TotalProfit; OrderBalance= (abs(BuyThisSymbol-SellThisSymbol)); PipsNeeded= (abs(ProfitNeeded/OrderBalance)); //////////////// // Reset 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 > ProfitTarget 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; }; }; ///////////////////// // Reset Close Order Variable ////////////////////// If ((TotalTrades == 0) And ((Hour-TimeClock)>=1)) then { If TimeMin<=20 OR Minute >=TimeMin Then { CloseAll = 0; CloseSwitch=0; }; }; ///////////////////////////////////////// // Close All Orders Routine ////////////////////////////////////////// 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; }; }; }; }; ///////////////////////////////////// // Start up Routine ////////////////////////////////////// If (CloseAll==0) Then //If closing switch set to 1 we don't want any more new orders. { ComSwitch=0; If ((DayOfWeek==6) And (Hour>=14) And (BuyThisSymbol==0) and (SellThisSymbol==0)) Then { Comment("Trading has been halted for the weekend, y'all come back now ya hear! ;-)"); ComSwitch=1; Exit; }; //////////////// // Open First Trades; ///////////////// If Close[1]>High[2] OR Close[1]0) OR (SellThisSymbol>0) Then { If BuyThisSymbol = 0 and FreeMargin > dMargin then { SetOrder(OP_BUY,Lots,Ask,Slippage,0,0,Blue); Exit; }; If SellThisSymbol = 0 and FreeMargin > dMargin 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); }; ////////////////////////////////////// // Check to set new buy or sell level /////////////////////////////////////// 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 < 5 then { If FreeMargin < dMargin then exit; SetOrder(OP_BUY,Lots,Ask,Slippage,0,0,Blue); Exit; }; If Bid < HighestSell and SellNewLevel = 0 and TotalProfit < 5 then { If FreeMargin < dMargin then exit; SetOrder(OP_SELL,Lots,Bid,Slippage,0,0,Red); Exit; }; }; }; Exit;