/*[[ 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. Lots := 1.00 Stop Loss := 0 Take Profit := 999 Trailing Stop := 10 ]]*/ ///////////////////////////////////////////////////// // Defines ///////////////////////////////////////////////////// Defines: Slippage(5); // Slippage Defines: WilliamsP(24),WilliamsL(-75),WilliamsH(-25); Defines: MM(0),Leverage(1),MarginChoke(50); ///////////////////////////////////////////////////// // Variables ///////////////////////////////////////////////////// var: PriceOpen(0),Buy_Tp(0),Sell_Tp(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); ///////////////////////////////////////////////// // 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. switch Symbol { case "USDCHF": StartMinute1 = 0; EndMinute1 = 1; StartMinute2 = 8; EndMinute2 = 9; StartMinute3 = 16; EndMinute3 = 17; StartMinute4 = 24; EndMinute4 = 25; StartMinute5 = 32; EndMinute5 = 33; StartMinute6 = 40; EndMinute6 = 41; StartMinute7 = 48; EndMinute7 = 49; break; case "GBPUSD": StartMinute1 = 2; EndMinute1 = 3; StartMinute2 = 10; EndMinute2 = 11; StartMinute3 = 18; EndMinute3 = 19; StartMinute4 = 26; EndMinute4 = 27; StartMinute5 = 34; EndMinute5 = 35; StartMinute6 = 42; EndMinute6 = 43; StartMinute7 = 50; EndMinute7 = 51; break; case "USDJPY": StartMinute1 = 4; EndMinute1 = 5; StartMinute2 = 12; EndMinute2 = 13; StartMinute3 = 20; EndMinute3 = 21; StartMinute4 = 28; EndMinute4 = 29; StartMinute5 = 36; EndMinute5 = 37; StartMinute6 = 44; EndMinute6 = 45; StartMinute7 = 52; EndMinute7 = 53; break; case "EURUSD": StartMinute1 = 6; EndMinute1 = 7; StartMinute2 = 14; EndMinute2 = 15; StartMinute3 = 22; EndMinute3 = 23; StartMinute4 = 30; EndMinute4 = 31; StartMinute5 = 38; EndMinute5 = 39; StartMinute6 = 46; EndMinute6 = 47; StartMinute7 = 54; EndMinute7 = 59; break; }; If (Minute >= StartMinute1 and Minute <= EndMinute1) or (Minute >= StartMinute2 and Minute <= EndMinute2) or (Minute >= StartMinute3 and Minute <= EndMinute3) or (Minute >= StartMinute4 and Minute <= EndMinute4) or (Minute >= StartMinute5 and Minute <= EndMinute5) or (Minute >= StartMinute6 and Minute <= EndMinute6) or (Minute >= StartMinute7 and Minute <= EndMinute7) Then { DummyField = 0; // dummy statement because MT will not allow me to use a continue statement } Else 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 < -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 + 5 * Point) Then // Check If buy price is a least 5 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 + 5 * 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 - 5 * Point) Then // Check If buy price is a least 5 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 - 5 * 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 + 5 * 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 + 5 * 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 - 5 * 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 - 5 * 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; }; }; }; }; };