/*[[ Name := TSD Author := Copyright © 2005 Bob O'Brien / Barcode Link := Notes := Based on Alexander Elder's Triple Screen system. Lots := 1.00 Stop Loss := 0 Take Profit := 100 Trailing Stop := 30 ]]*/ ///////////////////////////////////////////////////// // 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: ASC1(0),ASCSig(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 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 ++; }; GlobalName = "Gb1_Wk_"+Symbol+"_Direction"; Direction=GetGlobalVariable(GlobalName); ASC1=icustom("ASCTrend1",MODE_FIRST,1); ASCSig=0; If ASC1=l[1] then { ASCSig=1; }; If ASC1=h[1] then { ASCSig=-1; }; // 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. Comment("ver 0.1 TSD - ASC for MT3", "\n", "\n","Higher TimeFrame = ",Direction, "\n", "\n","Current Direction = ",ASCSig, "\n", "\n","Trades this Symbol(",Symbol(),") = ",TradesThisSymbol, "\n", "\n","New Bar Time is ",TimeToStr(newbar), "\n", "\n","Current High[1] = ",High[1], "\n","Current High[2] = ",High[2], "\n","Current Low[1] = ",Low[1], "\n","Current Low[2] = ",Low[2], "\n", "\n","Current Ask Price + 16 pips = ",Ask+(16*Point), "\n","Current Bid Price - 16 pips = ",Bid-(16*Point)); ///////////////////////////////////////////////// // 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); 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 ///////////////////////////////////////////////// ASC1=icustom("ASCTrend1",MODE_FIRST,1); ASCSig=0; If ASC1=l[1] then { ASCSig=1; }; If ASC1=h[1] then { ASCSig=-1; }; If Direction = 1 and ASCSig=-1 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 ASCSig=1 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; }; }; }; }; };