/*[[ Name := FibExpert Author := Copyright © 2005, iExpertAdvisor, LLC Link := http://www.iExpertAdvisor.com Lots := 1.00 Stop Loss := 0 Take Profit := 0 Trailing Stop := 0 ]]*/ define: LookBack(200), // The historical number of bars to use for analysis RetracementWindow(5), // The number of points the price must come within, also used // for stoploss and takeprofit RetracementFactor(2.0), // A multiple of the RetracementWindow that the price must bounce // or pierce Slippage(3); // The amount of slippage alowwed in the price define: gFlag62(0), // Global flag used to indicate trade setup gFlag50(0), // Global flag used to indicate trade setup gFlag38(0); // Global flag used to indicate trade setup vars: iHH(0), // The index of the Highest high in the lookback period HighestHigh(0), // The price of the Highest high in the lookback period iLL(0), // The index of the LowestLow low in the lookback period LowestLow(0); // The price of the LowestLow low in the lookback period vars: fibLevel62(0.0), // The Finonacci 62% retracement level fibLevel50(0.0), // The Finonacci 50% retracement level fibLevel38(0.0); // The Finonacci 38% retracement level // Need enough bars on chart to make accurate calculation if( Bars < LookBack )then { exit; }; // Only allow one open trade at a time, exit if a trade is already opened if( TotalTrades > 0 ) then { exit; }; // 1. The Market Setup // Market Setup: The currency pair has made a new high (or low). // Find the Highhset High in the Lookback Period iHH = Highest( MODE_HIGH, LookBack, LookBack ); HighestHigh = High[iHH]; iLL = Lowest( MODE_LOW, LookBack, LookBack ); LowestLow = Low[iLL]; // If the market has reached a new high, recalculate the fib levels if( Bid > HighestHigh ) then { fibLevel62 = ((HighestHigh - LowestLow)*0.618) + LowestLow; fibLevel50 = ((HighestHigh - LowestLow)*0.500) + LowestLow; fibLevel38 = ((HighestHigh - LowestLow)*0.382) + LowestLow; }; // 2. The Trade Setup // Trade Setup: After the new high, the currency pair has begun // to retrace towards a Fibonacci retracement level. (This level // may or may not align with retracement levels of other time frames.) gFlag38=0; gFlag50=0; gFlag62=0; if( Bid - (RetracementWindow*Point) <= fibLevel62 ) then { gFlag62=1; }; if( Bid - (RetracementWindow*Point) <= fibLevel50 ) then { gFlag50=1; }; if( Bid - (RetracementWindow*Point) <= fibLevel38 ) then { gFlag38=1; }; // 4. The Trade Trigger // Trade Trigger: The currency pair has reached the retracement // level and has confirmed that the price as either (i) pierced the // level, or (ii) bounced off the level. // Pierced the 62 Level if( (gFlag62 == 1 ) & (Close > fibLevel62+(RetracementFactor*RetracementWindow*Point)) & (Ask < HighestHigh) ) then { // BUY 62 gFlag38=0; gFlag50=0; gFlag62=0; setOrder(OP_BUY, Lots, Ask, Slippage, fibLevel62-(RetracementWindow*Point), HighestHigh, BLUE ); }; // Bounced off the 62 Level if( (gFlag62 == 1 ) & (Close < fibLevel62+(RetracementFactor*RetracementWindow*Point)) & (Bid > fibLevel50) ) then { // SELL 62 gFlag38=0; gFlag50=0; gFlag62=0; setOrder(OP_SELL, Lots, Bid, Slippage, fibLevel62+(RetracementWindow*Point), fibLevel50, RED ); }; // Pierced the 50 Level if( (gFlag50 == 1 ) & (Close > fibLevel62+(RetracementFactor*RetracementWindow*Point)) & (Ask < fibLevel62) ) then { // BUY 50 gFlag38=0; gFlag50=0; gFlag62=0; setOrder(OP_BUY, Lots, Ask, Slippage, fibLevel50-(RetracementWindow*Point), fibLevel62, BLUE ); exit; }; // Bounced off the 50 Level if( (gFlag50 == 1 ) & (Close < fibLevel62+(RetracementFactor*RetracementWindow*Point)) & (Bid > fibLevel38) ) then { // SELL 50 gFlag38=0; gFlag50=0; gFlag62=0; setOrder(OP_SELL, Lots, Bid, Slippage, fibLevel50+(RetracementWindow*Point), fibLevel38, RED ); exit; }; // Pierced the 38 Level if( (gFlag38 == 1 ) & (Close > fibLevel62+(RetracementFactor*RetracementWindow*Point)) & (Ask < LowestLow) ) then { // BUY 38 gFlag38=0; gFlag50=0; gFlag62=0; setOrder(OP_BUY, Lots, Ask, Slippage, fibLevel38-(RetracementWindow*Point), LowestLow, BLUE ); exit; }; // Bounced off the 38 Level if( (gFlag38 == 1 ) & (Close < fibLevel62+(RetracementFactor*RetracementWindow*Point)) & (Bid > fibLevel50) ) then { // SELL 38 gFlag38=0; gFlag50=0; gFlag62=0; setOrder(OP_SELL, Lots, Bid, Slippage, fibLevel38+(RetracementWindow*Point), fibLevel50, RED ); exit; }; // END