/*[[ Name := TSD_Daily_Force_HardTrail_v2_tdavid_MT3 Author := Copyright © 2005 Bob O'Brien / Barcode Link := DavidHon@msn.com Notes := Based on Alexander Elder's Triple Screen system. To be run only on a daily chart. Lots := 1.00 Stop Loss := 0 Take Profit := 0 Trailing Stop := 0 ]]*/ ///////////////////////////////////////////////////// // Defines ///////////////////////////////////////////////////// Defines: Slippage(5),MM(-1),Leverage(7),AcctSize(10000),LotMax(100); ///////////////////////////////////////////////////// // Variables ///////////////////////////////////////////////////// Variables: PriceOpen(0),I(0),vTime(0),x(0),cnt(0),TrailAt(0),LotMM(0),StopAmnt(0); Variables: Direction(0), PosNeg(""), TradesThisSymbol(0),TrailPending(0); Variables: Force(0), ForcePos(0), ForceNeg(0), GlobalName(""); ///////////////////////////////////////////////// // Initialisation ///////////////////////////////////////////////// If Curtime - LastTradeTime < 10 then Exit; If Period!=1440 Then { Alert("Whoops , Wrong Time Frame ,", "\n","This Expert Runs On ,", "\n","The Daily Charts"); Exit; }; ///////////////////////////////////////////////// // Close All Trades // Delete All Orders // If Equity Is Too Low // Sure Hope This Part Works // No Time Limit ///////////////////////////////////////////////// If ((Equity)<(AcctSize*0.1))Then { For x=1 to TotalTrades { If ord(x,VAL_TYPE)=OP_BUY Then { CloseOrder(ord(x,VAL_TICKET),ord(x,VAL_LOTS),ord(x,VAL_CLOSEPRICE),0,red); } If ord(x,VAL_TYPE)=OP_SELL Then { CloseOrder(ord(x,VAL_TICKET),ord(x,VAL_LOTS),ord(x,VAL_CLOSEPRICE),0,red); } If ord(x,VAL_TYPE)=OP_BUYSTOP Then { DeleteOrder(OrderValue(x,VAL_TICKET),Red); } If ord(x,VAL_TYPE)=OP_SELLSTOP Then { DeleteOrder(OrderValue(x,VAL_TICKET),Red); }; }; }; TradesThisSymbol = 0; For I = 1 to TotalTrades { if ord(I, VAL_SYMBOL) == Symbol then TradesThisSymbol = TradesThisSymbol+1; }; ///////////////////////////////////////////////////// // Set Each Pairs Trailing Stop // Whatever You Like For The Pair // No Time Limit ///////////////////////////////////////////////////// Switch Symbol { case "USDCHF": TrailAt=48;TrailPending=53; case "GBPUSD": TrailAt=53;TrailPending=58; case "USDJPY": TrailAt=43;TrailPending=48; case "EURUSD": TrailAt=43;TrailPending=48; case "AUDUSD": TrailAt=60;TrailPending=65; case "USDCAD": TrailAt=60;TrailPending=65; case "EURGBP": TrailAt=60;TrailPending=65; case "EURCHF": TrailAt=60;TrailPending=65; case "EURJPY": TrailAt=60;TrailPending=65; case "GBPJPY": TrailAt=60;TrailPending=65; case "NZDUSD": TrailAt=60;TrailPending=65; case "GBPCHF": TrailAt=60;TrailPending=65; case "CHFJPY": TrailAt=60;TrailPending=65; case "AUDJPY": TrailAt=60;TrailPending=65; case "EURCAD": TrailAt=60;TrailPending=65; case "EURAUD": TrailAt=60;TrailPending=65; case "AUDCAD": TrailAt=60;TrailPending=65; case "AUDNZD": TrailAt=60;TrailPending=65; case "NZDJPY": TrailAt=60;TrailPending=65; Default: exit; }; ///////////////////////////////////////////////// // Process Global Direction // And Force Indicator Details // No Time Limit ///////////////////////////////////////////////// ForcePos = iForce(2,MODE_EMA,PRICE_CLOSE,1) > 0.0000; ForceNeg = iForce(2,MODE_EMA,PRICE_CLOSE,1) < 0.0000; Force = iForce(2,MODE_EMA,PRICE_CLOSE,1); StopAmnt = (H[1]-L[1])+(5*Point); // Global Variable has a 1 if Weekly Direction is rising and a -1 if Weekly Direction is falling. GlobalName = "TSD_Weekly_Direction "+Symbol+" Direction"; Direction=GetGlobalVariable(GlobalName); Comment("\n", "\n",Symbol, "\n", "\n","TSD_Weekly_Direction = ",Direction, "\n", "\n","Force [ 1 ] = ", Force, "\n", "\n","Trail Stop = ",TrailAt, "\n", "\n","Trail Pending = ",TrailPending, "\n", "\n","Stop Loss = ",StopAmnt); ///////////////////////////////////////////////// // Lot Management // No Time Limit ///////////////////////////////////////////////// if MM < 0 then { LotMM = floor(Balance*Leverage/10000)/10; If LotMM > LotMax then { LotMM = LotMax; } } else { LotMM = lots; }; if MM > 0 then { LotMM = floor(Balance*Leverage/10000)/10; If LotMM > 1 then { LotMM = floor(LotMM); } if LotMM < 1 then { LotMM = 1; } If LotMM > LotMax then { LotMM = LotMax; } }; ///////////////////////////////////////////////// // New Orders Management // If No Trades This Symbol // And Conditions Are Positive // Set An Order // No Time Limit ///////////////////////////////////////////////// If TradesThisSymbol < 1 Then { ///////////////////////////////////////////////// // If There Is Enough Equity // And Conditions Are Positive // Set An Order // No Time Limit ///////////////////////////////////////////////// If ((Equity)>(AcctSize*0.2))Then { If Direction = 1 and ForceNeg then { PriceOpen = High[1] + (1 * Point); // Buy 1 point above high of previous candle If PriceOpen >= (Ask + 16 * Point) Then // Check if buy price is a least 16 points > Ask { SetOrder(OP_BUYSTOP, LotMM, PriceOpen, Slippage, (Bid-StopAmnt), 0, BLUE); Exit; }; }; If Direction = -1 and ForcePos then { PriceOpen = Low[1] - (1 * Point); If PriceOpen <= (Bid - 16 * Point) Then // Check if buy price is a least 16 points < Bid { SetOrder(OP_SELLSTOP, LotMM, PriceOpen, Slippage, (Ask+StopAmnt), 0, RED); Exit; }; }; }; }; ///////////////////////////////////////////////// // Pending Order Management // // If Global Direction Is Wrong // Delete Order // No Time Limit // // If More Than 1 Order Per Symbol // Delete Extra Order // No Time Limit // // Modify Order Entry Price // Trailing At TrailPending ///////////////////////////////////////////////// If TradesThisSymbol > 0 Then { For I=1 to TotalTrades { if Ord(I,VAL_TYPE) = OP_BUYSTOP And OrderValue(I,VAL_SYMBOL) = Symbol Then { if (Direction = -1) or (TradesThisSymbol >= 2) then { DeleteOrder(OrderValue(I,VAL_TICKET),Red); Exit; }; If (Ord(I,VAL_OPENPRICE)-(Ask))>(TrailPending*Point) then { If (Ord(I,VAL_OPENPRICE))>((Ask)+TrailPending*Point) Then { ModifyOrder(Ord(I,VAL_TICKET), (Ask+(TrailPending*Point)), (Bid-StopAmnt), (Ord(I,VAL_TAKEPROFIT)+(TrailPending*Point)), Cyan); Exit; }; }; }; if Ord(I,VAL_TYPE) = OP_SELLSTOP And OrderValue(I,VAL_SYMBOL) = Symbol Then { if (Direction = 1) or (TradesThisSymbol >= 2) then { DeleteOrder(OrderValue(I,VAL_TICKET),Red); Exit; }; If ((Bid)-Ord(I,VAL_OPENPRICE))>(TrailPending*Point) then { If Ord(I,VAL_OPENPRICE)<(Bid)-TrailPending*Point) then { ModifyOrder(Ord(I,VAL_TICKET), (Bid-(TrailPending*Point)), ((Ask+StopAmnt)-(TrailPending*Point)), Ord(I,VAL_TAKEPROFIT), Cyan); Exit; }; }; }; }; }; ///////////////////////////////////////////////// // Trailing Stop Management // No Time Limit ///////////////////////////////////////////////// If TradesThisSymbol > 0 Then { For cnt=1 to TotalTrades { If Ord(cnt,Val_Symbol)=Symbol and Ord(cnt,VAL_TYPE)=OP_BUY then { If (Ord(cnt,VAL_CLOSEPRICE)-Ord(cnt,VAL_OPENPRICE))>(TrailAt*Point) then { If Ord(cnt,VAL_STOPLOSS)<(Ord(cnt,VAL_CLOSEPRICE)-TrailAt*Point) then { ModifyOrder(Ord(cnt,VAL_TICKET), Ord(cnt,VAL_OPENPRICE), (Ord(cnt,VAL_CLOSEPRICE)-TrailAt*Point), Ord(cnt,VAL_TAKEPROFIT), Cyan); Exit; }; }; }; If Ord(cnt,Val_Symbol)=Symbol and Ord(cnt,VAL_TYPE)=OP_SELL then { If (Ord(cnt,VAL_OPENPRICE)-Ord(cnt,VAL_CLOSEPRICE))>(TrailAt*Point) then { If Ord(cnt,VAL_STOPLOSS)>(Ord(cnt,VAL_CLOSEPRICE)+TrailAt*Point) or Ord(cnt,VAL_STOPLOSS)=0 then { ModifyOrder(Ord(cnt,VAL_TICKET), Ord(cnt,VAL_OPENPRICE), (Ord(cnt,VAL_CLOSEPRICE)+TrailAt*Point), Ord(cnt,VAL_TAKEPROFIT), Fuchsia); Exit; }; }; }; }; };