/*[[ Name := Hans123MQ3_v1 Author := Copyright © 2005, Craig Dargan Notes := Adaptation of the Hans123 Breakout system from Moneytec Forums. Lots := 1.00 Stop Loss := 0 Take Profit := 0 Trailing Stop := 0 ]]*/ // Determine if Terminal is ready to trade If Bars<200 or FreeMargin<1000 or IsIndirect(Symbol) or Year<2005 then Exit; // Declare Variables for Input Define: ChartTimeZone(0),PipsForEntry(5); Define: IsDST(0),TSMethod(0); Define: ATRFactor(1.5),RangeFactor(30),Slippage(3); // Declare internal Variables var: BeginSession1(0),BeginSession2(0),AllOrderCloseTime(0); var: EndSession1(0),EndSession2(0); var: step(0),BreakEvenStop(0),CETTimeZone(0); var: BeginBar1(0),BeginBar2(0); var: EndBar1(0),EndBar2(0); var: TradeBarRange(0),InitialStopLoss(0),MyTakeProfit(0); var: PriceHigh1(0),PriceHigh2(0),PriceLow1(0),PriceLow2(0); var: FirstSessionTrade(False),SecondSessionTrade(False); var: testfile(0); // Set BreakEvenStop, InitialStopLoss, and MyTakeProfit values Switch Symbol { Case "EURUSD": BreakEvenStop=30; InitialStopLoss=50; MyTakeProfit=80; Case "GBPUSD": BreakEvenStop=40; InitialStopLoss=70; MyTakeProfit=120; Case "USDCHF": BreakEvenStop=30; InitialStopLoss=50; MyTakeProfit=80; Case "AUDUSD": BreakEvenStop=30; InitialStopLoss=50; MyTakeProfit=80; Case "USDCAD": BreakEvenStop=30; InitialStopLoss=50; MyTakeProfit=80; Default: BreakEvenStop=30; InitialStopLoss=50; MyTakeProfit=80; }; // Determine Session Begin and End times and Order Closing Time If IsDST=1 then { CETTimeZone=2; } Else { CETTimeZone=1; }; If(6-CETTimeZone+ChartTimeZone)<0 then { BeginSession1=24+(6-CETTimeZone+ChartTimeZone); } Else { If (6-CETTimeZone+ChartTimeZone)>23 then { BeginSession1=(6-CETTimeZone+ChartTimeZone)-24; } Else { BeginSession1=6-CETTimeZone+ChartTimeZone; }; }; If(10-CETTimeZone+ChartTimeZone)<0 then { EndSession1=24+(10-CETTimeZone+ChartTimeZone); BeginSession2=24+(10-CETTimeZone+ChartTimeZone); } Else { If (10-CETTimeZone+ChartTimeZone)>23 then { EndSession1=(10-CETTimeZone+ChartTimeZone)-24; BeginSession2=(10-CETTimeZone+ChartTimeZone)-24; } Else { EndSession1=10-CETTimeZone+ChartTimeZone; BeginSession2=10-CETTimeZone+ChartTimeZone; }; }; If(14-CETTimeZone+ChartTimeZone)<0 then { EndSession2=24+(14-CETTimeZone+ChartTimeZone); } Else { If (14-CETTimeZone+ChartTimeZone)>23 then { EndSession2=(14-CETTimeZone+ChartTimeZone)-24; } Else { EndSession2=14-CETTimeZone+ChartTimeZone; }; }; If (24-CETTimeZone+ChartTimeZone)>=24 then { AllOrderCloseTime=ChartTimeZone-CETTimeZone; } Else { AllOrderCloseTime=24-CETTimeZone+ChartTimeZone; }; /*testfile=FileOpen("Hans123",","); FileSeek(testfile,0,SEEK_END); FileWrite(testfile,CETTimeZone,ChartTimeZone,BeginSession1,EndSession1,BeginSession2,EndSession2,AllOrderCloseTime); FileClose(testfile); */ // Close all open trades at Midnight CET, or at 2300 CET on Friday If DayOfWeek=6 then { If Hour=AllOrderCloseTime-2 and Minute=59 then { For step=1 to TotalTrades { If OrderValue(step,VAL_TYPE)=OP_BUY then { CloseOrder(OrderValue(step,VAL_TICKET),OrderValue(step,VAL_LOTS),Bid,Slippage,Green); }; If OrderValue(step,VAL_TYPE)=OP_SELL then { CloseOrder(OrderValue(step,VAL_TICKET),OrderValue(step,VAL_LOTS),Ask,Slippage,Green); }; If OrderValue(step,VAL_TYPE)=OP_BUYSTOP then { DeleteOrder(OrderValue(step,VAL_TICKET),Red); }; If OrderValue(step,VAL_TYPE)=OP_SELLSTOP then { DeleteOrder(OrderValue(step,VAL_TICKET),Red); }; }; FirstSessionTrade=False; SecondSessionTrade=False; }; } Else { If Hour=AllOrderCloseTime-1 and Minute=59 then { For step=1 to TotalTrades { If OrderValue(step,VAL_TYPE)=OP_BUY then { CloseOrder(OrderValue(step,VAL_TICKET),OrderValue(step,VAL_LOTS),Bid,Slippage,Green); }; If OrderValue(step,VAL_TYPE)=OP_SELL then { CloseOrder(OrderValue(step,VAL_TICKET),OrderValue(step,VAL_LOTS),Ask,Slippage,Green); }; If OrderValue(step,VAL_TYPE)=OP_BUYSTOP then { DeleteOrder(OrderValue(step,VAL_TICKET),Red); }; If OrderValue(step,VAL_TYPE)=OP_SELLSTOP then { DeleteOrder(OrderValue(step,VAL_TICKET),Red); }; }; FirstSessionTrade=False; SecondSessionTrade=False; }; }; // Manage Open Orders For step=1 to TotalTrades { Switch TSMethod { Case 2: If OrderValue(step,VAL_TYPE)=OP_BUY then { If OrderValue(step,VAL_STOPLOSS)5*Point then { ModifyOrder(OrderValue(step,VAL_TICKET),OrderValue(step,VAL_OPENPRICE),iSAR(0.02,0.2,0),OrderValue(step,VAL_TAKEPROFIT),Red); }; } Else { If OrderValue(step,VAL_TYPE)=OP_SELL then { If OrderValue(step,VAL_STOPLOSS)>iSAR(0.02,0.2,0) and iSAR(0.02,0.2,0)-Ask>5*Point then { ModifyOrder(OrderValue(step,VAL_TICKET),OrderValue(step,VAL_OPENPRICE),iSAR(0.02,0.2,0),OrderValue(step,VAL_TAKEPROFIT),Red); }; }; }; Case 1: If OrderValue(step,VAL_TYPE)=OP_BUY then { If OrderValue(step,VAL_STOPLOSS)<(Bid-ATRFactor*iATR(14,0)) and (Bid-ATRFactor*iATR(14,0))>(Bid-5*Point) then { ModifyOrder(OrderValue(step,VAL_TICKET),OrderValue(step,VAL_OPENPRICE),(Bid-ATRFactor*iATR(14,0)),OrderValue(step,VAL_TAKEPROFIT),Red); }; } Else { If OrderValue(step,VAL_TYPE)=OP_SELL then { If OrderValue(step,VAL_STOPLOSS)>(Ask+ATRFactor*iATR(14,0)) and (Ask+ATRFactor*iATR(14,0))>(Ask+5*Point) then { ModifyOrder(OrderValue(step,VAL_TICKET),OrderValue(step,VAL_OPENPRICE),(Ask+ATRFactor*iATR(14,0)),OrderValue(step,VAL_TAKEPROFIT),Red); }; }; }; Default: If OrderValue(step,VAL_TYPE)=OP_BUY then { If Bid-OrderValue(step,VAL_OPENPRICE)>=BreakEvenStop*Point then { ModifyOrder(OrderValue(step,VAL_TICKET),OrderValue(step,VAL_OPENPRICE),OrderValue(step,VAL_OPENPRICE),OrderValue(step,VAL_TAKEPROFIT),Red); }; } Else { If OrderValue(step,VAL_TYPE)=OP_SELL then { If OrderValue(step,VAL_OPENPRICE)-Ask>=BreakEvenStop*Point then { ModifyOrder(OrderValue(step,VAL_TICKET),OrderValue(step,VAL_OPENPRICE),OrderValue(step,VAL_OPENPRICE),OrderValue(step,VAL_TAKEPROFIT),Red); }; }; }; }; }; // Set Trade Levels, and open trades TradeBarRange=14400/(Time[1]-Time[2]); If Hour=EndSession1 and not FirstSessionTrade then { PriceHigh1=High[Highest(MODE_HIGH,TradeBarRange,TradeBarRange)]; PriceLow1=Low[Lowest(MODE_LOW,TradeBarRange,TradeBarRange)]; SetOrder(OP_BUYSTOP,lots,PriceHigh1+5*Point,Slippage,PriceHigh1+(5-InitialStopLoss)*Point,PriceHigh1+(5+MyTakeProfit)*Point,Red); SetOrder(OP_SELLSTOP,lots,PriceLow1-5*Point,Slippage,PriceLow1-(5-InitialStopLoss)*Point,PriceLow1-(5+MyTakeProfit)*Point,Red); FirstSessionTrade=True; }; If Hour=EndSession2 not SecondSessionTrade then { PriceHigh2=High[Highest(MODE_HIGH,TradeBarRange,TradeBarRange)]; PriceLow2=Low[Lowest(MODE_LOW,TradeBarRange,TradeBarRange)]; SetOrder(OP_BUYSTOP,lots,PriceHigh2+5*Point,Slippage,PriceHigh2+(5-InitialStopLoss)*Point,PriceHigh2+(5+MyTakeProfit)*Point,Red); SetOrder(OP_SELLSTOP,lots,PriceLow2-5*Point,Slippage,PriceLow2-(5-InitialStopLoss)*Point,PriceLow2-(5+MyTakeProfit)*Point,Red); SecondSessionTrade=True; };