/*[[ Name := TSD Author := Copyright © 2005 Bob O'Brien aka Barcode Link := 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 := 100 Trailing Stop := 50 ]]*/ ///////////////////////////////////////////////////// // Defines ///////////////////////////////////////////////////// Defines: Slippage(5); // Slippage Defines: StopYear(2005); Defines: MM(0),Leverage(1),AcctSize(10000); ///////////////////////////////////////////////////// // Variables ///////////////////////////////////////////////////// var: PriceOpen(0); // Price Open var: I(0),TimeSlice(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: StartMinute1(0),EndMinute1(0),StartMinute2(0),EndMinute2(0),StartMinute3(0),EndMinute3(0); Var: StartMinute4(0),EndMinute4(0),StartMinute5(0),EndMinute5(0),StartMinute6(0),EndMinute6(0); var: StartMinute7(0),EndMinute7(0),DummyField(0),Dir(""); ///////////////////////////////////////////////// // 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,4); If (Symbol = "USDCHF" and TimeSlice != 0) or (Symbol = "GBPUSD" and TimeSlice != 1) or (Symbol = "USDJPY" and TimeSlice != 2) or (Symbol = "EURUSD" and TimeSlice != 3) 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 Direction = 1 then Dir = "Up"; If Direction = -1 then Dir = "Down"; Comment(Symbol," Direction=",Dir); 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 + 8 * Point) Then // Check if buy price is a least 8 points > Ask { SetOrder(OP_BUYSTOP, LotMM, PriceOpen, Slippage, Low[1] - 1 * Point, PriceOpen + TakeProfit * Point, BLUE); Exit; } Else { NewPrice = Ask + 8 * 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 - 8 * Point) Then // Check if buy price is a least 8 points < Bid { SetOrder(OP_SELLSTOP, LotMM, PriceOpen, Slippage, High[1] + 1 * Point, PriceOpen - TakeProfit * Point, RED); Exit; } Else { NewPrice = Bid - 8 * 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 + 8 * 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 + 8 * 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 - 8 * 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 - 8 * 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 (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, Bid + TakeProfit * Point, White); Exit; }; }; }; If Ord(i,VAL_TYPE) = OP_SELL And OrderValue(i,VAL_SYMBOL) = Symbol Then { If (Ord(i,VAL_OPENPRICE) - Ask) > (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, Gold); Exit; }; }; }; }; };