/*[[ Name := 6 bar HI_LO v5b Author := JDG / transport_david Link := http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/ Lots := 1.00 Stop Loss := 0 Take Profit := 0 Trailing Stop := 0 ]]*/ /*- Terms Of Use = "Use At Your Own Risk" -*/ Define: IAcceptTerms(1); // Default(0) = No , Any Other Value = Yes . If (IAcceptTerms==0) Then Exit; If (IAcceptTerms<>0) Then { ///////////////////////////////////////////////////// // Defines // // Adjust Your Risk ( Risk = % of Account Balance Per Trade ) // // Enter Your AllwTrdAbv_Eqty // ( AllwTrdAbv_Eqty = $ Amount Minimum Needed To Set Orders ) // // Enter Your ClsTrdBlw_Eqty // ( ClsTrdBlw_Eqty = If Equity Falls Below ClsTrdBlw_Eqty All Trades will be Closed/Deleted ) ///////////////////////////////////////////////////// Defines: MM(-1),Risk(25); Defines: AllwTrdAbv_Eqty(100),ClsTrdBlw_Eqty(75),LotMax(50),StopYear(2006); Defines: Slippage(3),pt(4),periodatristop(9),atrfactor(1.5),ProfitAtrPrds(9),FactorProf(0.5625); ///////////////////////////////////////////////////// // Variables ///////////////////////////////////////////////////// var: I(0),MAsell(0),MAbuy(0),istop(0),sellstop(0),buystop(0),openperiod(0),prevtime(0); var: high1(0),high2(0),high3(0),high4(0),low1(0),low2(0),low3(0),low4(0),LotMM(0); Var: TradesThisSymbol(0),spread(0),piptarget(0),sellpips(0),buypips(0),crumbsclose(0); ///////////////////////////////////////////////// // Initialisation ///////////////////////////////////////////////// If TimeYear(T) < StopYear then exit; ///////////////////////////////////////////////// // Close All Trades // Delete All Orders // If Equity Is Too Low ///////////////////////////////////////////////// If ((Equity)<(ClsTrdBlw_Eqty))Then { For i=1 to TotalTrades { If ord(i,VAL_TYPE)=OP_BUY Then { CloseOrder(ord(i,VAL_TICKET),ord(i,VAL_LOTS),ord(i,VAL_CLOSEPRICE),0,red); } If ord(i,VAL_TYPE)=OP_SELL Then { CloseOrder(ord(i,VAL_TICKET),ord(i,VAL_LOTS),ord(i,VAL_CLOSEPRICE),0,red); } If ord(i,VAL_TYPE)=OP_BUYSTOP Then { DeleteOrder(OrderValue(i,VAL_TICKET),Red); } If ord(i,VAL_TYPE)=OP_SELLSTOP Then { DeleteOrder(OrderValue(i,VAL_TICKET),Red); }; }; }; //- Check for trades this Symbol --------------------------------------------------------------------------- TradesThisSymbol = 0; For I = 1 to TotalTrades { If (ord(I, VAL_SYMBOL) == Symbol) then { If ((OrderValue(I,VAL_TYPE)==OP_SELL) OR (OrderValue(I,VAL_TYPE)==OP_BUY)) then { TradesThisSymbol ++; }; }; }; ///////////////////////////////////////////////// // Lot Management ///////////////////////////////////////////////// if MM == 0 then { LotMM = lots; }; if MM < 0 then { LotMM = (Round(Balance*Risk/10000))/10; If LotMM > LotMax then { LotMM = LotMax; } }; if MM > 0 then { LotMM = Round(Balance*Risk/10000)/10; If LotMM > 1 then { LotMM = Round(LotMM); } if LotMM < 1 then { LotMM = 1; } If LotMM > LotMax then { LotMM = LotMax; } }; //- Control of 1 Trade per Bar ----------------------------------------------------------------------------- If ((TradesThisSymbol>=1) and (prevtime<>T[0])) Then { openperiod=10;prevtime=T[0]; }; If ((TradesThisSymbol>=1) and (prevtime==T[0])) Then { openperiod=10;prevtime=T[0]; }; If ((TradesThisSymbol==0) and (prevtime<>T[0])) Then { openperiod=-10;prevtime=T[0]; }; //- Set Buy/Sell Price Variable Values --------------------------------------------------------------------- high1=max(h[1],h[2]); high2=max(h[3],h[4]); high3=max(h[5],h[6]); high4=max(high1,high2); buystop=max(high4,high3)-pt*Point; low1=min(l[1],l[2]); low2=min(l[3],l[4]); low3=min(l[5],l[6]); low4=min(low1,low2); sellstop=min(low4,low3)+pt*Point; //- set Variable Values ------------------------------------------------------------------------------------ spread = (Ask - Bid); piptarget = ((1 * Point) + ((iATR(ProfitAtrPrds,1) * FactorProf) - spread)); istop = (iatr(periodatristop,1)*atrfactor); //- Reset Close Trade Variables if no open trades ---------------------------------------------------------- If (TradesThisSymbol == 0) Then { sellpips = 0; buypips = 0; crumbsclose=0; }; //- Set Close Trade Variables ------------------------------------------------------------------------------ For i=1 to TotalTrades { If ((Ord(i,Val_Symbol)==Symbol) and (Ord(i,VAL_TYPE)==OP_SELL)) Then { sellpips = (Ord(i,VAL_OPENPRICE)-Ord(i,VAL_CLOSEPRICE)); }; If ((Ord(i,Val_Symbol)==Symbol) and (Ord(i,VAL_TYPE)==OP_BUY)) Then { buypips = (Ord(i,VAL_CLOSEPRICE)-Ord(i,VAL_OPENPRICE)); }; }; If (sellpips > crumbsclose) Then { crumbsclose=sellpips; }; If (buypips > crumbsclose) Then { crumbsclose=buypips; }; //- Apply Comments to chart -------------------------------------------------------------------------------- If MASell > 0 then {Comment("Trend = Down", "\n","Sell Trigger Price = ",buystop, "\n","ATR Offset = ",istop, "\n","piptarget = ",piptarget, "\n","sellpips = ",sellpips, "\n","buypips = ",buypips, "\n","crumbsclose = ",crumbsclose, "\n","openperiod = ",openperiod); }; If MASell < 0 then {Comment("Trend = Up", "\n","Buy Trigger Price = ",sellstop, "\n","ATR Offset = ",istop, "\n","piptarget = ",piptarget, "\n","sellpips = ",sellpips, "\n","buypips = ",buypips, "\n","crumbsclose = ",crumbsclose, "\n","openperiod = ",openperiod); }; ///////////////////////////////////////////////// // New Orders Management ///////////////////////////////////////////////// If (ima(12,mode_sma,1)>ima(6,MODE_EMA,1)) then { MASell = 10; MABuy = -10; }; If (ima(12,mode_sma,1)(AllwTrdAbv_Eqty)) Then { If (tradesthissymbol==0) then { if ((MABuy>0) and (ask<=sellstop) and (openperiod<0)) then { SetOrder(OP_BUY,LotMM,ask,Slippage,ask-istop,buystop,Cyan); prevtime=0; exit; }; if ((MASell>0) and (bid>=buystop) and (openperiod<0)) then { SetOrder(OP_SELL,LotMM,bid,Slippage,bid+istop,sellstop,Fuchsia); prevtime=0; exit; }; }; }; ///////////////////////////////////////////////// // Stop Loss & Take Profit Management ///////////////////////////////////////////////// //- StopLoss and ATR TrailingStop -------------------------------------------------------------------------- For i = 1 To TotalTrades { If ((Ord(i,VAL_SYMBOL)==Symbol) and (Ord(i,VAL_TYPE)==OP_BUY)) Then { If ((Ord(i,VAL_CLOSEPRICE)-istop)>Ord(i,VAL_STOPLOSS)) or (Ord(i,VAL_STOPLOSS)==0) Then { ModifyOrder(OrderValue(i,VAL_TICKET),OrderValue(i,VAL_OPENPRICE), (Ord(i,VAL_CLOSEPRICE)-istop),OrderValue(i,VAL_TAKEPROFIT),White); Print("ATR TS"); Exit; }; }; If ((Ord(i,VAL_SYMBOL)==Symbol) and (Ord(i,VAL_TYPE)==OP_SELL)) Then { If ((Ord(i,VAL_CLOSEPRICE)+istop) piptarget) Then { CloseOrder(OrderValue(i,VAL_TICKET),OrderValue(i,VAL_LOTS), OrderValue(i,VAL_CLOSEPRICE),0,SandyBrown); Print("ATR TP Closed Order"); Exit; }; }; If ((Ord(i,Val_Symbol)==Symbol) and (Ord(i,VAL_TYPE)==OP_BUY)) Then { If (crumbsclose > piptarget) Then { CloseOrder(OrderValue(i,VAL_TICKET),OrderValue(i,VAL_LOTS), OrderValue(i,VAL_CLOSEPRICE),0,SandyBrown); Print("ATR TP Closed Order"); Exit; }; }; }; //- End ---------------------------------------------------------------------------------------------------- };