/*[[ Name := TSD Author := Copyright © 2005 Bob O'Brien / Barcode Link := Notes := Based on Alexander Elder's Triple Screen system. To be run only on a daily chart. New Order collision added. Lots := 1.00 Stop Loss := 0 Take Profit := 100 Trailing Stop := 60 ]]*/ ///////////////////////////////////////////////////// // Defines ///////////////////////////////////////////////////// Defines: Slippage(5); // Slippage Defines: StopYear(2005); Defines: MM(0),Leverage(1),AcctSize(10000); ///////////////////////////////////////////////////// // Variables ///////////////////////////////////////////////////// var: PriceOpen(0); // Price Open var: I(0); // Misc Counter Var: NewBar(0),First(True),LotMM(0),LotSize(10000),LotMax(50); Var: Direction(0), PosNeg(""), TradesThisSymbol(0); Var: ForcePos(0), ForceNeg(0), NewPrice(0), GlobalName(""); var: TimeSlice(0); ///////////////////////////////////////////////// // Initialisation ///////////////////////////////////////////////// if year < stopyear then exit; If Curtime - LastTradeTime < 10 then Exit; If FreeMargin < 500 then Exit; TradesThisSymbol = 0; For I = 1 to TotalTrades { if ord(I, VAL_SYMBOL) == Symbol then TradesThisSymbol ++; }; // Select a range of minutes in the day to start trading based on the currency pair. // This is to stop collisions occurring when 2 or more currencies set orders at the same time. TimeSlice = Mod(Minute,9); If (Symbol = "USDCHF" and TimeSlice != 0) or (Symbol = "GBPUSD" and TimeSlice != 1) or (Symbol = "AUDUSD" and TimeSlice != 2) or (Symbol = "EURUSD" and TimeSlice != 3) or (Symbol = "USDCAD" and TimeSlice != 4) or (Symbol = "EURGBP" and TimeSlice != 5) or (Symbol = "EURCHF" and TimeSlice != 6) or (Symbol = "GBPCHF" and TimeSlice != 7) or (Symbol = "NZDUSD" and TimeSlice != 8) then { Exit; } ///////////////////////////////////////////////// // Process the next bar details ///////////////////////////////////////////////// If NewBar != t[0] Then { NewBar = t[0]; // Global Variable has a 1 if Weekly MACH is rising and a -1 if Weekly MACD is falling. GlobalName = "Gb1_Wk_"+Symbol+"_Direction"; Direction=GetGlobalVariable(GlobalName); Print(Symbol," Global_Direction=",Direction); If TradesThisSymbol < 1 Then { ///////////////////////////////////////////////// // Lot Management ///////////////////////////////////////////////// If MM < 0 then { LotMM = Round(Balance*Leverage/10000)/10; If LotMM > LotMax then LotMM = LotMax; }; If MM = 0 then LotMM = lots; if MM > 0 then { LotMM = Round(Balance*Leverage/10000)/10; If LotMM > 1 then LotMM = ceil(LotMM); if LotMM < 1 then LotMM = 1; If LotMM > LotMax then LotMM = LotMax; }; ///////////////////////////////////////////////// // New Orders Management ///////////////////////////////////////////////// ForcePos = iForce(2,MODE_EMA,PRICE_CLOSE,1) > 0; ForceNeg = iForce(2,MODE_EMA,PRICE_CLOSE,1) < 0; 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, Low[1] - 1 * Point, PriceOpen + TakeProfit * Point, BLUE); Exit; } Else { NewPrice = Ask + 16 * Point; SetOrder(OP_BUYSTOP, LotMM, NewPrice, Slippage, Low[1] - 1 * Point, NewPrice + TakeProfit * Point, 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, High[1] + 1 * Point, PriceOpen - TakeProfit * Point, RED); Exit; } Else { NewPrice = Bid - 16 * Point; SetOrder(OP_SELLSTOP, LotMM, NewPrice, Slippage, High[1] + 1 * Point, NewPrice - TakeProfit * Point, RED); Exit; }; }; }; ///////////////////////////////////////////////// // Pending Order Management ///////////////////////////////////////////////// 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 then { DeleteOrder(OrderValue(i,VAL_TICKET),Red); Exit; }; }; if Ord(i,VAL_TYPE) = OP_SELLSTOP And OrderValue(i,VAL_SYMBOL) = Symbol Then { if Direction = 1 then { DeleteOrder(OrderValue(i,VAL_TICKET),Red); Exit; }; }; If Ord(i,VAL_TYPE) = OP_BUYSTOP And OrderValue(i,VAL_SYMBOL) = Symbol Then { If High[1] < High[2] Then { If High[1] > (Ask + 16 * Point) Then { ModifyOrder(Ord(i,VAL_TICKET), High[1] + 1 * Point, Low[1] - 1 * Point, Ord(i,VAL_TAKEPROFIT), White); Exit; } Else { ModifyOrder(Ord(i,VAL_TICKET), Ask + 16 * Point, Low[1] - 1 * Point, Ord(i,VAL_TAKEPROFIT), White); Exit; }; }; }; If Ord(i,VAL_TYPE) = OP_SELLSTOP And OrderValue(i,VAL_SYMBOL) = Symbol Then { If Low[1] > Low[2] Then { If Low[1] < (Bid - 16 * Point) Then { ModifyOrder(Ord(i,VAL_TICKET), Low[1] - 1 * Point, High[1] + 1 * Point, Ord(i,VAL_TAKEPROFIT), Gold); Exit; } Else { ModifyOrder(Ord(i,VAL_TICKET), Bid - 16 * Point, High[1] + 1 * Point, Ord(i,VAL_TAKEPROFIT), Gold); Exit; }; }; }; }; }; }; ///////////////////////////////////////////////// // Stop Loss Management ///////////////////////////////////////////////// If TradesThisSymbol > 0 Then { For i=1 to TotalTrades { If Ord(i,VAL_TYPE) = OP_BUY And OrderValue(i,VAL_SYMBOL) = Symbol Then { If (Ask-Ord(i,VAL_OPENPRICE)) > (TrailingStop * Point) Then { If Ord(i,VAL_STOPLOSS) < (Ask - TrailingStop * Point) Then { ModifyOrder(Ord(i,VAL_TICKET), Ord(i,VAL_OPENPRICE), Ask - TrailingStop * Point, Ask + TakeProfit * Point, White); Exit; }; }; }; If Ord(i,VAL_TYPE) = OP_SELL And OrderValue(i,VAL_SYMBOL) = Symbol Then { If (Ord(i,VAL_OPENPRICE) - Bid) > (TrailingStop * Point) Then { If Ord(i,VAL_STOPLOSS) > (Bid + TrailingStop * Point) Then { ModifyOrder(Ord(i,VAL_TICKET), Ord(i,VAL_OPENPRICE), Bid + TrailingStop * Point, Bid - TakeProfit * Point, Gold); Exit; }; }; }; }; };