[LegacyColorValue = true]; Inputs: Periods( 100 ), ExitNextDay( false ), GhostBoxExit( false ), BreakoutEntry (false ), VolumeEntry( false ), VolumeAvgLen( 10 ), VolumeFactor( 1.5 ) , BuyColor(Cyan),SellColor(Magenta), LongColor(Blue),ShortColor(Red), ExitLongColor(Green),ExitShortColor(Yellow); variables: BarsSinceDH( 0 ), BarsSinceDL( 0 ), CriticalLow( 0 ), TempD_Low( 0 ), SearchForLow ( false ), D_Low( 0 ), D_High( 0 ), BottomLineNum( 0 ), TopLineNum( 0 ), LeftSideNum( 0 ), RightSideNum( 0 ), CriticalHigh( 0 ), TempD_High( 0 ), DHighLowDiff( 0 ), MyStop( 0 ), MyTrigger( 0 ), DownTrend( 0 ) , MP(0), BuyPrice(0), SellPrice(0); Plot1(" ","Action",black,white); if MP = 1 then Plot1("LONG","Action",black,LongColor); if MP = -1 then Plot1("SHORT","Action",black,ShortColor); if MP <> 1 and BuyPrice <> 0 and high >= BuyPrice then begin MP = 1; Plot1("BUY","Action",black,BuyColor); end; if MP <> -1 and SellPrice <> 0 and low <= SellPrice then begin MP = -1; Plot1("SELL","Action",black,SellColor); end; BuyPrice = 0; SellPrice = 0; if CurrentBar > Periods then begin BarsSinceDH = BarsSinceDH + 1 ; BarsSinceDL = BarsSinceDL + 1 ; if Low[3] <= CriticalLow[4] and Low[3] <= Low[2] and Low[3] <= Low[1] and Low[3] < Low then begin TempD_Low = Low[3] ; BarsSinceDL = 3 ; end ; if SearchForLow and BarsSinceDL < 6 and BarsSinceDL <= BarsSinceDH then begin D_Low = Low[BarsSinceDL] ; D_High = TempD_High ; SearchForLow = false ; { BottomLineNum = TL_New( Date[BarsSinceDH],Time[BarsSinceDH], D_Low, Date[3], Time[3],D_Low ) ; TopLineNum = TL_New( Date[BarsSinceDH],Time[BarsSinceDH], D_High, Date[3], Time[3],D_High ) ; LeftSideNum = TL_New( Date[BarsSinceDH],Time[BarsSinceDH], D_High, Date[BarsSinceDH],Time[BarsSinceDH], D_Low ) ; RightSideNum = TL_New( Date[3], Time[3], D_High,Date[3], Time[3], D_Low ) ; } end ; if High[3] >= CriticalHigh[4] and High[3] >= High[2] and High[3] >= High[1] and High[3] > High then begin BarsSinceDH = 3 ; TempD_High = High[3] ; SearchForLow = true ; end ; CriticalHigh = Highest( High, Periods ) ; CriticalLow = Lowest( Low, BarsSinceDH ) ; end ; DHighLowDiff = D_High - D_Low ; if GhostBoxExit and DHighLowDiff > 0 and Close > D_High + DHighLowDiff then begin MyStop = ( IntPortion( ( Close - D_Low ) / DHighLowdiff ) - 1 ) * DHighLowDiff + D_Low ; MyTrigger = MyStop + DHighLowDiff ; end else begin MyStop = D_Low ; MyTrigger = D_High ; end ; if Close crosses under D_Low then DownTrend = 0 else if BreakoutEntry and Close crosses over D_High then DownTrend = 1 else if BreakoutEntry and DownTrend = 1 and BarsSinceDL = 3 then DownTrend = 2 ; if ( BreakoutEntry and DownTrend = 2 ) or BreakoutEntry = false then begin if VolumeEntry then begin if MP <> 1 and Close crosses over MyTrigger and Volume > Average( Volume, VolumeAvgLen ) * VolumeFactor then begin MP = 1; Plot1("BUY@ARKET","Action",black,BuyColor); {Buy next bar market ;} end; end else if MP <> 1 and Close < MyTrigger then begin BuyPrice = MyTrigger; {Buy next bar MyTrigger stop ;} end; if ExitNextDay then begin if MP <> -1 and Low[1] >= MyStop and Low < MyStop then begin MP = -1; Plot1("Sell@ARKET","Action",black,SellColor); {Sell next bar at market ;} end; end else SellPrice = MyStop; {Sell next bar at MyStop stop ;} end ;