//+-------------------------------------------------------------------+ //| Made/Modified by Alejandro Galindo | //| | //| If this work/modification is helpful to you | //| send me a PayPal donation to ag@elcactus.com | //| any help is apreciated :) | //| Thanks. | //+-------------------------------------------------------------------+ /*[[ Name := Daily 5 Author := Copyright © 2005 Alejandro Galindo Lots := 1.00 Stop Loss := 35 Take Profit := 999 Trailing Stop := 25 ]]*/ Define: StartHour(0); Define: StartMinute(0); Define: EndHour(23); Define: EndMinute(55); Define: Pips(5); Define: mm(0); Define: risk(12); Define: BrokerOrdRes(11); var: cnt(0); var: lotsi(0); var: OpenTrades(0), FilledOrders(0); var: Slippage(5); var: BuyPrice(0), SellPrice(0); var: TimetoOpen(0), TimetoClose(0), tmp(0), i(0); var: Trades(2), Type("NONE"), Reverse(False); If TimeYear(time)<2005 then Exit; if Curtime - LastTradeTime < 15 then exit; if mm<>0 then lotsi=Ceil(Balance*risk/10000)/10 else lotsi=Lots; BuyPrice=High[1]+Pips*Point; if (BuyPrice-Ask)<(BrokerOrdRes*Point) then BuyPrice=Ask+BrokerOrdRes*Point; SellPrice=Low[1]-Pips*Point; if (Bid-SellPrice)<(BrokerOrdRes*Point) then SellPrice=Bid-BrokerOrdRes*Point; //Comment("Trades=",Trades," Reverse=",Reverse," (",Type,")"); OpenTrades=0; For cnt=1 to TotalTrades{ if OrderValue(cnt,VAL_SYMBOL)==Symbol then { OpenTrades++; If OrderValue(cnt,VAL_TYPE)==OP_SELL OR OrderValue(cnt,VAL_TYPE)==OP_BUY then { FilledOrders++; }; }; }; TimetoClose=StrToTime(TimeDay(time)+" "+EndHour+":"+EndMinute); //if (CurTime>=TimetoClose) then if (Hour==EndHour and Minute>=EndMinute) then { For cnt=1 to TotalTrades{ If OrderValue(cnt,VAL_SYMBOL)==Symbol then { Trades=2; Type="NONE"; Reverse=False; If OrderValue(cnt,VAL_TYPE) == OP_BUYSTOP OR OrderValue(cnt,VAL_TYPE) == OP_SELLSTOP then DeleteOrder(OrderValue(cnt,VAL_TICKET),Brown); If OrderValue(cnt,VAL_TYPE) == OP_BUY then CloseOrder(ord(cnt,VAL_TICKET),ord(cnt,VAL_LOTS),bid,Slippage,Blue); If OrderValue(cnt,VAL_TYPE) == OP_SELL then CloseOrder(ord(cnt,VAL_TICKET),ord(cnt,VAL_LOTS),ask,Slippage,red); Exit; }; }; }; TimetoOpen=StrToTime(TimeDay(time)+" "+StartHour+":"+StartMinute); //Print("TimetoOpen=",TimeToStr(TimetoOpen)," High[1]=",High[1]," Low[1]=",Low[1]," Trades=",GetGlobalVariable("Trades"+Symbol+Period)); //if (CurTime==TimetoOpen) then if (Hour==StartHour and Minute>=StartMinute) then { If OpenTrades<1 then { Trades=2; Type="NONE"; Reverse=True; SetOrder(OP_BUYSTOP,Lotsi,BuyPrice,Slippage,BuyPrice-StopLoss*Point,BuyPrice+TakeProfit*Point,blue); SetOrder(OP_SELLSTOP,Lotsi,SellPrice,Slippage,SellPrice+StopLoss*Point,SellPrice-TakeProfit*Point,Red); Exit; }; }; // if we only have one Stop order we place the another one to always have ready both sides //If OpenTrades==1 and GetGlobalVariable("Daily5Trades"+Symbol+Period)>1 then If OpenTrades==1 and Trades==2 then { if OrderValue(1,VAL_TYPE)==OP_SELLSTOP then { Trades=1; Type="SELL"; Reverse=True; SetOrder(OP_BUYSTOP,Lotsi,BuyPrice,Slippage,BuyPrice-StopLoss*Point,BuyPrice+TakeProfit*Point,blue); Exit; }; if OrderValue(1,VAL_TYPE)==OP_BUYSTOP then { Trades=1; Type="BUY"; Reverse=True; SetOrder(OP_SELLSTOP,Lotsi,SellPrice,Slippage,SellPrice+StopLoss*Point,SellPrice-TakeProfit*Point,Red); Exit; }; }; //If OpenTrades<1 and GetGlobalVariable("Daily5Trades"+Symbol+Period)==1 then If OpenTrades<1 and Trades==1 and Reverse then { if Type=="BUY") then { Trades=0; Type="NONE"; Reverse=False; SetOrder(OP_BUY,Lotsi,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,Blue); Exit; }; if Type=="SELL") then { Trades=0; Type="NONE"; Reverse=False; SetOrder(OP_SELL,Lotsi,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,Red); Exit; }; }; // if we have opened positions we take care of them for cnt=1 to TotalTrades { if OrderValue(cnt,VAL_SYMBOL) == Symbol then { if OrderValue(cnt,VAL_TYPE) == OP_BUY then { for i=1 to TotalTrades { if (OrderValue(i,VAL_SYMBOL)==Symbol) then { if OrderValue(i,VAL_TYPE)==OP_SELLSTOP OR OrderValue(i,VAL_TYPE)==OP_BUYSTOP then { Trades=1; Type="SELL"; Reverse=True; DeleteOrder(OrderValue(i,VAL_TICKET),brown); Exit; }; }; }; If TrailingStop>0 then { If (Bid-OrderValue(cnt,VAL_OPENPRICE))>(Point*TrailingStop) then { If OrderValue(cnt,VAL_STOPLOSS)<(Bid-Point*TrailingStop) then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),Bid-Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Yellow); Trades=0; Type="NONE"; Reverse=False; Exit; }; }; }; }; if OrderValue(cnt,VAL_TYPE) == OP_SELL then { for i=1 to TotalTrades { if (OrderValue(i,VAL_SYMBOL)==Symbol) then { if OrderValue(i,VAL_TYPE)==OP_SELLSTOP OR OrderValue(i,VAL_TYPE)==OP_BUYSTOP then { Trades=1; Type="BUY"; Reverse=True; DeleteOrder(OrderValue(i,VAL_TICKET),brown); Exit; }; }; }; If TrailingStop>0 then { If (OrderValue(cnt,VAL_OPENPRICE)-Ask)>(Point*TrailingStop) then { if OrderValue(cnt,VAL_STOPLOSS)>(Ask+Point*TrailingStop) then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),Ask+Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Purple); Trades=0; Type="NONE"; Reverse=False; Exit; }; }; }; }; }; }; Exit;