/*[[ Name := Pivot Point Breakout Author := Jason Lustig - jlust286(at)stiglu(dot)com Link := http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/ //************************************************************************************************* // DESCRIPTION //************************************************************************************************* - Pivot Point Breakout System will buy or sell at breakout of pivot point near London open. - Define TP, SL, and TS. - Note: The default variables assumes your platform is in GMT and London is not on BST (British Summer Time or Daylight Savings Time). If your platform is not GMT or London is on BST then you will need to change the start time at London open and close a couple hours after USA close. Take into account Daylight Savings Time when needed. Also realize backtest does not take daylight savings into account. Visit http://aboutforex.com/timezones.html for a forex timezone chart. Lots := 1.00 Stop Loss := 60 Take Profit := 120 Trailing Stop := 60 ]]*/ define: Buffer(20); //How many pips past pivot before trade entry? define: BeginTradingAtHour(8); //At what hour do you want to begin trading? define: CloseTradesAtHour(23); //At what hour do you want to close all trades? define: mm(1); //MM options see commented section below about MM define: Risk(10); //What percent of account to use? var: Ilo(0); var: b(0); var: d(0); var: z(0); var: cnt(0); var: Slip(5); //How much slippage do you want to allow? var: CloseAll(False); var: TargetHigh(0); var: TargetLow(0); var: BuySet("Waiting"); var: SellSet("Waiting"); var: yesterday_open(0); var: yesterday_high(0); var: yesterday_low(0); var: yesterday_close(0); var: P(0),R0.5(0),R1(0),R1.5(0),R2(0),R2.5(0),R3(0),S0.5(0),S1(0),S1.5(0),S2(0),S2.5(0),S3(0); //************************************************************************************************* // System Checks. //************************************************************************************************* COMMENT ("Buy Straddle: ",TargetHigh," - ",BuySet, "\n","Sell Straddle: ",TargetLow," - ",SellSet, "\n","High= ",yesterday_high,"\nLow= ",yesterday_low,"\nClose= ",yesterday_close,"\n R3.0= ",R3,"\n R2.5= ",R2.5,"\n R2.0= ",R2,"\n R1.5= ",R1.5,"\n R1.0= ",R1,"\n R0.5= ",R0.5,"\nPivot= ",P,"\n S0.5= ",S0.5,"\n S1.0= ",S1,"\n S1.5= ",S1.5,"\n S2.0= ",S2,"\n S2.5= ",S2.5,"\n S3.0= ",S3); //Sorry, only works with H1 timeframe. If Period <> 60 then Alert("Pivot Point Straddle System only works on H1 timeframe.") Exit; //Wait 11 seconds before runnning script again. If CurTime=0 then d=open[b-BeginTradingAtHour]; If d>=P and d=R0.5 and d=R1 and d=R1.5 and dS0.5 then { TargetHigh=P+Buffer*Point; TargetLow=S0.5-Buffer*Point; }; If d<=S0.5 and d>S1 then { TargetHigh=S0.5+Buffer*Point; TargetLow=S1-Buffer*Point; }; If d<=S1 and d>S1.5 then { TargetHigh=S1+Buffer*Point; TargetLow=S1.5-Buffer*Point; }; If d<=S1.5 and d>S2 then { TargetHigh=S1.5+Buffer*Point; TargetLow=S2-Buffer*Point; }; //************************************************************************************************* // Order Control. //************************************************************************************************* //If not "Waiting" then set targethigh/low to 0. If BuySet!="Waiting" then TargetHigh=0; If SellSet!="Waiting" then TargetLow=0; //Reset tags for beginning of new trading day. If TotalTrades=0 and b=BeginTradingAtHour and CloseAll=True then { BuySet="Waiting"; SellSet="Waiting"; CloseAll=False; }; //Close trade at end of trading day whether profit or loss. If b>=CloseTradesAtHour or b0 then { For cnt=1 to TotalTrades Begin If OrderValue(cnt,VAL_SYMBOL)=Symbol then CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,50,WhiteSmoke); End; } Exit; }; //Verify trade was indeed triggered and not requoted. If TotalTrades=1 then { If BuySet="Pending" then { BuySet="Triggered"; SellSet="Off"; Exit; }; If SellSet="Pending" then { BuySet="Off"; SellSet="Triggered"; Exit; }; }; /*====================== MONEY MANAGEMENT / COMPOUNDING =========================================== Changing the value of mm will give you several money management options mm = -1 : Fractional lots/ balance X the risk factor.(use for Mini accts) mm = 0 : Single Lots. mm = 1 : Full lots/ balance X the risk factor up to 100 lot orders.(use for Regular accounts) *************************************************************************************************** RISK FACTOR: risk can be anything from 1 up. Factor of 5 adds a lot for every $20,000.00 ($2000-MINI) added to the balance. Factor of 10 adds a lot with every $10.000.00 ($1000-MINI) added to the balance. The higher the risk, the easier it is to blow your margin.. ***************************************************************************************************/ Ilo=Lots; If mm<0 then { Ilo=Ceil(Balance*Risk/10000)/10-0.1; If Ilo<0.1 then Ilo=0.1; }; If mm>0 then { Ilo=Ceil(Balance*Risk/10000)/10-1; If Ilo>1 then Ilo=Ceil(Ilo); If Ilo<1 then Ilo=1; }; If Ilo>100 then Ilo=100; //************************************************************************************************* // Initailze. //************************************************************************************************* If TotalTrades<1 then { If FreeMargin<1000 then Exit; If Ask>=TargetHigh and TargetHigh>0 and BuySet!="Triggered" and BuySet!="Off" then { SetOrder(OP_BUY,Ilo,Ask,Slip,Ask-StopLoss*Point,Ask+TakeProfit*Point,Yellow); BuySet="Pending"; Exit; }; If Bid<=TargetLow and SellSet!="Triggered" and SellSet!="Off" then { SetOrder(OP_SELL,Ilo,Bid,Slip,Bid+StopLoss*Point,Bid-TakeProfit*Point,Red); SellSet="Pending"; Exit; }; }; //************************************************************************************************* // Trailing Stops //************************************************************************************************* For cnt=1 to TotalTrades { If TotalTrades<1 then Exit; If TrailingStop=0 then Exit; If OrderValue(cnt,VAL_TYPE)=OP_BUY and OrderValue(cnt,VAL_SYMBOL)=Symbol then { If (Bid-OrderValue(cnt,VAL_OPENPRICE))>(TrailingStop*Point) then { If OrderValue(cnt,VAL_STOPLOSS)<(Bid-TrailingStop*Point) then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),Bid-TrailingStop*Point,OrderValue(cnt,VAL_TAKEPROFIT),Blue); Exit; }; }; }; If OrderValue(cnt,VAL_TYPE)=OP_SELL and OrderValue(cnt,VAL_SYMBOL)=Symbol then { If (Ord(cnt,VAL_OPENPRICE)-Ask)>(TrailingStop*Point) then { If OrderValue(cnt,VAL_STOPLOSS)>(Ask+TrailingStop*Point) then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),Ask+TrailingStop*Point,OrderValue(cnt,VAL_TAKEPROFIT),Red); Exit; }; }; }; }; Exit; /************************************************************************************************** // Bug fixes, upgrades and changes. //************************************************************************************************* v101 - Decided to see if it was more profitable if I didn't use the next pivot as take profit and it was. Now you define the TP, SL, and TS. Fixed mm so it more closely uses the percent of account you define as Risk variable. ie: if mm is 1 and risk is 10% it will trade 2 lots after account balance is over $20,000. (Not 3 lots as it did previously) ie: if mm is -1 and risk is 10% it will trade 1.1 lots after account balance is over$11,000. (Not 1.2 lots as it did previously) //************************************************************************************************* // END //*************************************************************************************************