/*[[ Name := Peak and Valley thingy Author := Jesse Breaker Link := http://www.metaquotes.net/ Lots := 0 Stop Loss := 45 Take Profit := 0 Trailing Stop := 0 ]]*/ Define : Debug(0); Var: NumberOfBars(0),ValleyBar(0),PeakBar(0),BarDiff(0),cnt(0),Peak(0),Valley(0),vTIME(0),PeakTime(0),ValleyTime(0); //************************************************************************************************* // System Checks. //************************************************************************************************* //Wait 20 seconds before runnning script again. If CurTime - LastTradeTime < 20 Then Exit; If Peak == 0 and Valley == 0 then { If ( (High[2] < High[1]) and (High[1] < High[0]) ) and vTime != T[0] then { Peak = 0; Valley = 1; ValleyTime = T[2]; vTime = T[0]; SetText(t[2],L[2]+5*Point,"V",Magenta); //Print("BarTime ",TimeToSTR(T[2])); }; If ( (Low[2] > Low[1]) and (Low[1] > Low[0]) ) and vTime != T[0] then { Valley = 0; Peak = 1; PeakTime = T[2]; vTime = T[0]; SetText(t[2],H[2]+5*Point,"P",Magenta); //Print("BarTime ",TimeToSTR(T[2])); }; }; If Peak != 0 and Valley == 0 then { If ( (High[2] < High[1]) and (High[1] < High[0]) ) and vTime != T[0] then { Peak = 0; ValleyTime = T[2]; vTime = T[0]; For cnt = 1 to bars { If T[cnt] == PeakTime then { BarDiff=cnt; // -2 because ValleyTime = T[2] cnt=bars; }; }; ValleyBar=Lowest(mode_low,BarDiff,1+BarDiff); Valley = 1; SetText(t[ValleyBar],L[ValleyBar]-5*Point,"V",Magenta); If Debug == 1 then { SetText(t[2],H[2]+5*Point,"S",Magenta); SetText(t[0],H[0]+5*Point,"C",Magenta); }; //Print("Current ",TimeToStr(T[0])," ValleyBar ",ValleyBar," BarDiff ",BarDiff, "VT ",TimeToStr(ValleyTime)," PT ",TimeToStr(PeakTime)); }; }; If Peak == 0 and Valley != 0 then { If ( (Low[2] > Low[1]) and (Low[1] > Low[0]) ) and vTime != T[0] then { Valley = 0; PeakTime = T[2]; vTime = T[0]; For cnt = 1 to bars { If T[cnt] == ValleyTime then { BarDiff=cnt; // -2 because PeakTime = T[2] cnt=bars; }; }; PeakBar=Highest(MODE_HIGH,BarDiff,1+BarDiff); //Print("BarTime ",TimeToSTR(T[3])); Peak=High[PeakBar]; Peak = 1; SetText(t[PeakBar],H[PeakBar]+5*Point,"P",Magenta); If Debug == 1 then { SetText(t[2],L[2]+5*Point,"S",Magenta); SetText(t[0],L[0]+5*Point,"C",Magenta); }; //Print("Current ",TimeToStr(T[0])," PeakBar ",PeakBar," BarDiff ",BarDiff, "VT ",TimeToStr(ValleyTime)," PT ",TimeToStr(PeakTime)); }; };