/*[[ Name := PIVOT SUPPORT/RESISTANCE ENTRY Author := FAB4X Link := Notes := RUN ON A 1HR Lots := 1.00 Stop Loss := 0 Take Profit := 0 Trailing Stop := 0 ]]*/ ///////////////////////////////////////////////////// // Defines ///////////////////////////////////////////////////// Defines: Slippage(5); // Slippage Defines: TradesPerCurrency(1); // Number of lots to trade DEFINES: Start_Time(0),End_Time(20),StopYear(2005),StopMonth(1); ///////////////////////////////////////////////////// // Variables ///////////////////////////////////////////////////// var: OpenSell(0); // Sell Trades Counter var: OpenBuy(0); // Buy Trades Counter var: PriceOpen(0); // Price Open var: I(0),cnt(0),vTime(0); // Misc Counter var: Mode(0); // Squirl the Mode variable for multiple use VAR: Pivot(0),MYPIVOTB(0),MYPIVOTS(0); var: yesterday_open(0); var: yesterday_high(0); var: yesterday_low(0); var: yesterday_close(0),b(0),d(0); VAR: S0.5(0),R0.5(0),S1(0),R1(0); ///////////////////////////////////////////////// // Main Script Conditions ///////////////////////////////////////////////// If Curtime - LastTradeTime < 5 then Exit; If FreeMargin < 500 then Exit; If Period <> 60 then Alert("PIVOT System only works on H1 timeframe.") Exit; if year < StopYear then exit; if month < StopMonth and year <> 2005 then exit; //If (DayOfWeek <2 or DayOfWeek >6 or hour < Start_Time or hour > End_Time) then exit; ///////////////////////////////////////////////////// // Calculations / Setting Values ///////////////////////////////////////////////////// OpenSell = 0; OpenBuy = 0; for I = 1 to TotalTrades { Mode = ord(I, VAL_TYPE); if ord(I, VAL_SYMBOL) == Symbol then { //Calculates how many Sell we have for the current Symbol if Mode == OP_SELL then { OpenSell++; }; //Calculates how many Buy we have for the current Symbol if Mode == OP_BUY then { OpenBuy++; }; }; }; ///////////////////////////////////////////////// // CUSTOM INDICATORS ///////////////////////////////////////////////// yesterday_high=Max(High[1+b],(Max(High[2+b],(Max(High[3+b],(Max(High[4+b],(Max(High[5+b],(Max(High[6+b],(Max(High[7+b],(Max(High[8+b],(Max(High[9+b],(Max(High[10+b],(Max(High[11+b],(Max(High[12+b],(Max(High[13+b],(Max(High[14+b],(Max(High[15+b],(Max(High[16+b],(Max(High[17+b],(Max(High[18+b],(Max(High[19+b],(Max(High[20+b],(Max(High[21+b],(Max(High[22+b],(Max(High[23+b],High[24+b]))))))))))))))))))))))))))))))))))))))))))))))))); yesterday_low=Min(Low[1+b],(Min(Low[2+b],(Min(Low[3+b],(Min(Low[4+b],(Min(Low[5+b],(Min(Low[6+b],(Min(Low[7+b],(Min(Low[8+b],(Min(Low[9+b],(Min(Low[10+b],(Min(Low[11+b],(Min(Low[12+b],(Min(Low[13+b],(Min(Low[14+b],(Min(Low[15+b],(Min(Low[16+b],(Min(Low[17+b],(Min(Low[18+b],(Min(Low[19+b],(Min(Low[20+b],(Min(Low[21+b],(Min(Low[22+b],(Min(Low[23+b],Low[24+b]))))))))))))))))))))))))))))))))))))))))))))))))); yesterday_close=close[1+b]; Pivot = ( yesterday_high + yesterday_close + yesterday_low )/ 3 ; //MYPIVOTB = Pivot+bps*point; //MYPIVOTS = Pivot-sps*point; R1 =(2*PIVOT)-yesterday_low; S1 =(2*PIVOT)-yesterday_high; R0.5=(PIVOT+R1)/2; S0.5=(PIVOT+S1)/2; ///////////////////////////////////////////////// // Comment on the chart ///////////////////////////////////////////////// ///////////////////////////////////////////////// // Long/Short Entry and Re-entry Trades ///////////////////////////////////////////////// If OpenBuy < TradesPerCurrency then { if vTime != Time[0] then { If open < pivot and hour == Start_Time then { Alert(Symbol, " BUY ALERT. Buy at ", PRICEASK , " Price below Pivot Line."); comment(" TREND NOW IS LONG - BUY - "); SetOrder(OP_BUY,lots,ASK,Slippage,S1,R0.5,blue); vTime = Time[0]; Exit; }; }; }; If OpenSell < TradesPerCurrency then { if vTime != Time[0] then { If open > pivot and hour == Start_Time then { Alert(Symbol, " SELL ALERT. Sell at ", PRICEBID , "Price above Pivot Line."); comment(" TREND NOW IS SHORT - SELL " ); SetOrder(OP_SELL,lots,BID,Slippage,R1,S0.5,RED); vTime = Time[0]; Exit; }; }; }; ///////////////////////////////////////////////// // Trade Management ///////////////////////////////////////////////// for I = 1 to TotalTrades { Mode = ord(I, VAL_TYPE); if ord(I, VAL_SYMBOL) == Symbol then { If OpenBuy > 0 then { //If Primary target is met, close half play and move stop to 0 for other lot. if hour == End_Time then { Alert("Primary Target met. BID = " + Bid + ". Closing order at market for " + Symbol + " on " + Period + " Period."); CloseOrder(ord(I, VAL_TICKET), ord(I, VAL_LOTS), Bid, Slippage, Orange); Exit; }; }; If OpenSell > 0 then { //If Primary target is met, close half play and move stop to 0 for other lot. if hour == End_Time then { Alert("Primary Target met. Ask = " + Ask + ". Closing order at market for " + Symbol + " on " + Period + " Period."); CloseOrder(ord(I, VAL_TICKET), ord(I, VAL_LOTS), Ask, Slippage, Orange); Exit; }; // Psar Stop }; }; }; ////////////////////////////////////////////////////////// /////////////////////////Trailing Stop Code ///////////////////// ////////////////////////////////////////////////////////// If TotalTrades > 0 then { for cnt = 1 to TotalTrades Begin If Ord(cnt,VAL_TYPE)=OP_BUY then { /////////////////// If Ord(cnt,VAL_SYMBOL)= Symbol then { If Ord(cnt,VAL_OPENPRICE) + TrailingStop*Point < Bid Then { If Ord(cnt,VAL_STOPLOSS)<(Bid-TrailingStop*Point) then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE), Bid-TrailingStop*Point,Ord(cnt,VAL_TAKEPROFIT),Red); Exit; }; }; If Ord(cnt,VAL_TAKEPROFIT) = 0 Then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE), Ord(cnt,VAL_OPENPRICE)-StopLoss*Point,Ord(cnt,VAL_OPENPRICE)+TakeProfit*Point,Red); Exit; }; }; };// End of BUY If Ord(cnt,VAL_TYPE)=OP_SELL then { /////////////////// If Ord(cnt,VAL_SYMBOL)= Symbol then { If Ord(cnt,VAL_OPENPRICE) - TrailingStop*Point > Ask Then { If Ord(cnt,VAL_STOPLOSS)>(Ask+TrailingStop*Point) then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE),Ask+TrailingStop*Point, Ord(cnt,VAL_TAKEPROFIT),White); Exit; }; }; If Ord(cnt,VAL_TAKEPROFIT) = 0 Then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE), Ord(cnt,VAL_OPENPRICE)+StopLoss*Point,Ord(cnt,VAL_OPENPRICE)-TakeProfit*Point,Red); Exit; }; }; };//End of Sell End; };