/*[[ Name := CCI_For_Gazuz2 Author := Original by Davidm and tidy up by Scorpion. Link := Enable Alerts := Yes Lots := 1.00 Stop Loss := 60 Take Profit := 999 Trailing Stop := 40 ]]*/ Defines : slippage(4),risk(20),mm(1),CCI_Period(50); Variable : Sell_Cross_Point(0.0000),Buy_Cross_Point(0.0000); Variable : SignalStrength(0); Variable : cnt(0),i(0); Variable : CurrentCCI(0),AboveCurrent(0),BelowCurrent(0),AbovePrevious(0),BelowPrevious(0); CurrentCCI=iCCI(CCI_Period,0); AboveCurrent = (CurrentCCI > (Buy_Cross_Point)); AbovePrevious = (iCCI(CCI_Period,1) > (Sell_Cross_Point)); BelowCurrent = (CurrentCCI < (Sell_Cross_Point)); BelowPrevious = (iCCI(CCI_Period,1) < (Buy_Cross_Point)); if abs(CurrentCCI)<=200 then { SignalStrength=100-(abs(CurrentCCI)/2); } else { SignalStrength=0; }; Comment("Signal's Strength: ",SignalStrength,"%"); For cnt=1 to totaltrades { If Ord(cnt,VAL_SYMBOL)=Symbol and Ord(cnt,VAL_TYPE)=OP_BUY Then { If (AbovePrevious) and (BelowCurrent) Then { CloseOrder(OrderValue(cnt,VAL_TICKET), OrderValue(cnt,VAL_LOTS), OrderValue(cnt,VAL_CLOSEPRICE), 0, White); Alert("CCI Expert Closed Buy Trade",".",Symbol); Exit; }; }; If Ord(cnt,VAL_SYMBOL)=Symbol and OrderValue(cnt,VAL_TYPE)=OP_SELL Then { If (BelowPrevious) and (AboveCurrent) Then { CloseOrder(Ord(cnt,VAL_TICKET), Ord(cnt,VAL_LOTS), Ord(cnt,VAL_CLOSEPRICE), 0, Gold); Alert("CCI Expert Closed Sell Trade",".",Symbol); Exit; }; }; }; If TotalTrades < 1 Then { If (AbovePrevious) and (BelowCurrent) Then { SetOrder(OP_SELL, Lots, bid, slippage, bid+StopLoss*Point, bid-TakeProfit*Point, Gold); Alert("CCI Expert Opened a Sell Trade",".",Symbol); Exit; }; If (BelowPrevious) and (AboveCurrent) Then { SetOrder(OP_BUY, Lots, ask, slippage, ask-StopLoss*Point, ask+TakeProfit*Point, white); Alert("CCI Expert Opened a Buy Trade",".",Symbol); Exit; }; }; For i=1 to TotalTrades { If TrailingStop<5 Then { print("Invalid trailing stop"); Exit; }; If Ord(i,VAL_SYMBOL)=Symbol and Ord(i,VAL_TYPE)=OP_BUY Then { If (Bid-Ord(i,VAL_OPENPRICE))>(TrailingStop*Point) Then { If Ord(i,VAL_STOPLOSS)<(Bid-TrailingStop*Point) Then { ModifyOrder(Ord(i,VAL_TICKET), Ord(i,VAL_OPENPRICE), Bid-TrailingStop*Point, Ord(i,VAL_TAKEPROFIT), White); }; }; }; If Ord(i,VAL_SYMBOL)=Symbol and Ord(i,VAL_TYPE)=OP_SELL Then { If (Ord(i,VAL_OPENPRICE)-Ask)>(TrailingStop*Point) Then { If Ord(i,VAL_STOPLOSS)>(Ask+TrailingStop*Point) Or Ord(i,VAL_STOPLOSS)=0 Then { ModifyOrder(Ord(i,VAL_TICKET), Ord(i,VAL_OPENPRICE), Ask+TrailingStop*Point, Ord(i,VAL_TAKEPROFIT), Gold); Exit; }; }; }; }; //------------- t_David