/*[[ Name := Daily Trading Author := Copyright © 2005, afahmic Notes := Inspired by autofx's SimpleEagle expert. := This is a modified version to run on 15minute chart for increased accuracy := it still trades according to the daily values, but has the precision of the := 15minute chart for the purpose of backtesting. := results differ dramatically from version that runs on daily chart := Attach to M15 chart, to almost all pairs (except EURGBP/EURCHF due to their low volatility), Lots := 1 Stop Loss := 15 Take Profit := 150 Trailing Stop := 30 ]]*/ Defines: Leverage(10), EntryPips(50), DirPips(25), TailPips(25), MoneyManagement(0), EnableTS(0); Var: LotSize(10000), Slippage(5), LotMax(50), MinSpread(12), MultiPairs(1), MinMargin(50), LotMM(1), CurrentPairTrades(0), SellColor("Red"), BuyColor("Yellow"), cnt(0); var: v1(0),v2(0),v3(0),v4(0),v5(0),v6(0),v7(0),v8(0),v9(0),v10(0),hi(0),lo(0),opn(0),cls(0),allow(0); If Period != 15 Then Exit; If TimeYear(Time[0]) < 2004 then Exit; // INTERBANKFX LOT COMPOUNDING ========================== If MoneyManagement <> 0 then { LotMM = (FreeMargin*Leverage/LotSize); If LotMM < 2 then { LotMM = Lots; } If LotMM = 2 then { LotMM = 2; } If LotMM > 2 and LotMM < 10 then { LotMM = Ceil(FreeMargin*Leverage/LotSize)-1; } If LotMM >= 10 and LotMM < 15 then { LotMM = 10; } If LotMM >= 15 and LotMM < 20 then { LotMM = 15; } If LotMM >= 20 and LotMM < 25 then { LotMM = 20; } If LotMM >= 25 and LotMM < 30 then { LotMM = 25; } If LotMM >= 30 and LotMM < 35 then { LotMM = 30; } If LotMM >= 35 and LotMM < 40 then { LotMM = 35; } If LotMM >= 40 and LotMM < 45 then { LotMM = 40; } If LotMM >= 45 and LotMM < LotMax then { LotMM = 45; } If LotMM >= LotMax then { LotMM = LotMax; } } Else { LotMM = Lots; } // calculations for 15min charts // based on previous 15min bar instead of current, just to avoid any weirdnesses with the backtesting engine. v1 = Mod(Time[0],86400)/900; // number of 15minute periods elapsed since midnight // NOTE: This are effectively the DAILY values lo = Low[Lowest(MODE_LOW,v1,v1)]; cls = Close[0]; opn = Open[v1]; hi = High[Highest(MODE_HIGH,v1,v1)]; If(Mod(Time[0],86400) = 0) Then { allow = 1; // this stops it from making more than one trade per day. } //Print("v1: ", v1, " hi: ", hi, " lo: ", lo, " cls: ", cls, " opn: ", opn); // // MULTIPAIRS OPTION ==================================== CurrentPairTrades = 0; If MultiPairs = 1 then { For cnt = 1 to TotalTrades { If Ord(cnt, VAL_SYMBOL) = Symbol then { CurrentPairTrades = CurrentPairTrades+1; } } } Else { CurrentPairTrades = TotalTrades; } // MODIFY ORDER ========================================= If EnableTS = 1 then { If CurrentPairTrades > 0 then { For cnt = 1 to TotalTrades { If Ord(cnt, VAL_SYMBOL) = Symbol then { If Ord(cnt, VAL_TYPE) = OP_SELL and Ord(cnt, VAL_STOPLOSS) > Bid+(EntryPips+DirPips)*Point then //Bid+TrailingStop*Point then { ModifyOrder(Ord(cnt, VAL_TICKET),Ord(cnt, VAL_OPENPRICE), // Bid+TrailingStop*Point,Ord(cnt,VAL_TAKEPROFIT),SellColor); Bid+(EntryPips+DirPips)*Point,Bid-TakeProfit*Point,SellColor); } If Ord(cnt, VAL_TYPE) = OP_BUY and Ord(cnt, VAL_STOPLOSS) < Ask-(EntryPips+DirPips)*Point then //Ask-TrailingStop*Point then { ModifyOrder(Ord(cnt, VAL_TICKET),Ord(cnt, VAL_OPENPRICE), // Ask-TrailingStop*Point,Ord(cnt,VAL_TAKEPROFIT),BuyColor); Ask-(EntryPips+DirPips)*Point,Ask+TakeProfit*Point,BuyColor); } } } } } // CLOSE ORDER ========================================== If CurrentPairTrades > 0 then { // calculate the number of periods since 00:00 //If (Mod(Time[0],86400) = 0) Then //{ // it'll be between 0 and 95 //} For cnt = 1 to TotalTrades { If Ord(cnt, VAL_SYMBOL) = Symbol then { If Ord(cnt, VAL_TYPE) = OP_SELL then { If (cls-lo >= EntryPips*Point and opn-lo >= TailPips*Point and cls-opn >= DirPips*Point and cls-opn <= EntryPips*Point) or Hour = 23 then { CloseOrder(Ord(cnt, VAL_TICKET),Ord(cnt, VAL_LOTS),Ord(cnt, VAL_CLOSEPRICE),Slippage,Red); If MultiPairs = 1 then CurrentPairTrades = CurrentPairTrades-1; } } If Ord(cnt, VAL_TYPE) = OP_BUY then { If (hi-Ask >= EntryPips*Point and hi-opn >= TailPips*Point and opn-Ask >= DirPips*Point and opn-Ask <= EntryPips*Point) or Hour = 23 then { CloseOrder(Ord(cnt, VAL_TICKET),Ord(cnt, VAL_LOTS),Ord(cnt, VAL_CLOSEPRICE),Slippage,Yellow); If MultiPairs = 1 then CurrentPairTrades = CurrentPairTrades-1; } } } } } // SET ORDER ============================================ If (CurrentPairTrades < 1 and Ask-Bid <= MinSpread*Point and FreeMargin >= MinMargin and Hour < 18 and DirPips > 0 and allow = 1) then { If (hi-Ask >= EntryPips*Point and hi-opn >= TailPips*Point and opn-Ask >= DirPips*Point and opn-Ask <= EntryPips*Point) then { //Print("Sell: ",cls); SetOrder(OP_SELL,LotMM,Bid,Slippage,Bid+(EntryPips+DirPips)*Point,Bid-TakeProfit*Point,Red); //SetOrder(OP_SELL,LotMM,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,Red); allow = 0; Exit; } If (Ask-lo >= EntryPips*Point and opn-lo >= TailPips*Point and Ask-opn >= DirPips*Point and Ask-opn <= EntryPips*Point) then { //Print("Buy: ",Close[0]); SetOrder(OP_BUY,LotMM,Ask,Slippage,Ask-(EntryPips+DirPips)*Point,Ask+TakeProfit*Point,Yellow); //SetOrder(OP_BUY,LotMM,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,Yellow); allow = 0; Exit; } };