/*[[ 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 := 0.1 Stop Loss := 0 Take Profit := 100 Trailing Stop := 50 ]]*/ ///////////////////////////////////////////////////// // Defines ///////////////////////////////////////////////////// Defines: Slippage(5); // Slippage Defines: WilliamsP(24),WilliamsL(-75),WilliamsH(-25); Defines: MM(0),Leverage(1),MarginChoke(500); ///////////////////////////////////////////////////// // Variables ///////////////////////////////////////////////////// var: PriceOpen(0),Buy_Tp(0),Sell_Tp(0),TimeSlice(0); var: I(0),WilliamsBuy(0), WilliamsSell(0); 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 Curtime - LastTradeTime < 10 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 < -1 then { If FreeMargin < 5 then Exit; LotMM = Floor(Balance*Leverage/1000); If LotMM < 1 then LotMM = 1; LotMM = LotMM/100; If LotMM > LotMax then LotMM = LotMax; }; If MM = -1 then { If FreeMargin < 50 then Exit; LotMM = Floor(Balance*Leverage/10000); If LotMM < 1 then LotMM = 1; LotMM = LotMM/10; If LotMM > LotMax then LotMM = LotMax; }; If MM = 0 then { If FreeMargin < MarginChoke then Exit; LotMM = lots; }; If MM > 0 then { If FreeMargin < 500 then Exit; LotMM = Floor(Balance*Leverage/100000); If LotMM < 1 then LotMM = 1; If LotMM > LotMax then LotMM = LotMax; }; ///////////////////////////////////////////////// // New Orders Management ///////////////////////////////////////////////// WilliamsSell = iWPR(WilliamsP,1) > WilliamsL; WilliamsBuy = iWPR(WilliamsP,1) < WilliamsH; If Direction = 1 and WilliamsBuy 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 { If TakeProfit > 0 then Buy_Tp = PriceOpen + TakeProfit * Point else Buy_Tp = 0; SetOrder(OP_BUYSTOP, LotMM, PriceOpen, Slippage, Low[1] - 1 * Point, Buy_Tp, BLUE); Exit; } Else { NewPrice = Ask + 8 * Point; If TakeProfit > 0 then Buy_Tp = NewPrice + TakeProfit * Point else Buy_Tp = 0; SetOrder(OP_BUYSTOP, LotMM, NewPrice, Slippage, Low[1] - 1 * Point, Buy_Tp, BLUE); Exit; }; }; If Direction = -1 and WilliamsSell then { PriceOpen = Low[1] - 1 * Point; If PriceOpen < (Bid - 8 * Point) Then // Check If buy price is a least 8 points < Bid { If TakeProfit > 0 then Sell_Tp = PriceOpen - TakeProfit * Point else Sell_Tp = 0; SetOrder(OP_SELLSTOP, LotMM, PriceOpen, Slippage, High[1] + 1 * Point, Sell_Tp, RED); Exit; } Else { NewPrice = Bid - 8 * Point; If TakeProfit > 0 then Sell_Tp = NewPrice - TakeProfit * Point else Sell_Tp = 0; SetOrder(OP_SELLSTOP, LotMM, NewPrice, Slippage, High[1] + 1 * Point, Sell_Tp, 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_SYMBOL) = Symbol and Ord(i,VAL_TYPE) = OP_BUY and TrailingStop > 0 Then { If (Bid-Ord(i,VAL_OPENPRICE)) > (TrailingStop * Point) Then { If Ord(i,VAL_STOPLOSS) < (Bid - TrailingStop * Point) Then { If TakeProfit > 0 Then Buy_Tp = Bid + TakeProfit * Point else Buy_Tp = 0; ModIfyOrder(Ord(i,VAL_TICKET), Ord(i,VAL_OPENPRICE), Bid - TrailingStop * Point, Buy_Tp, White); Exit; }; }; }; If Ord(i,VAL_SYMBOL) = Symbol and Ord(i,VAL_TYPE) = OP_SELL and TrailingStop > 0 Then { If (Ord(i,VAL_OPENPRICE) - Ask) > (TrailingStop * Point) Then { If Ord(i,VAL_STOPLOSS) > (Ask + TrailingStop * Point) Then { If TakeProfit > 0 then Sell_Tp = Ask - TakeProfit * Point else Sell_Tp = 0; ModifyOrder(Ord(i,VAL_TICKET), Ord(i,VAL_OPENPRICE), Ask + TrailingStop * Point, Sell_Tp, Gold); Exit; }; }; }; }; };