Support resistance based on today'S open version 2

#1
hello this is my first version http://www.traderji.com/amibroker/101726-support-resistance-based-todays-open-amibroker-afl.html

That range of trading gives handsome return.so i make some tweak with the help of kplswing with some fancy message board

thanks to the author of http://www.wisestocktrader.com/indicatorpasties/287-neeru-kala-target and http://gsaisriram.blogspot.in/2014/12/sectionbegintrend-blaster-v4_11.html


Condition 1:if price opens below support support 1 , Buy @ support 2 ( make sure price does nt break support 2) , if breaks very weak


Condition 2: if price opens above resistance 1 , Short at OR near resistance 2( Make sure price does nt break resistance 2) , if breaks very bullish

Condition 3: Some times price may form support @ support 1 AND raise upto resistance1 , if breaks then resistance 2

Condition 4: some time s price wont Cross resistance 1 , from there we can Short for first target support 1 , then support 2.

screen shot




Amibroker AFL

Code:
_SECTION_BEGIN("megatrader");
SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace=Param("GraphXSpace",0,0,100,1);
    dec = (Param("Decimals",2,0,7,1)/10)+1;
SetChartBkColor(ParamColor("Outer Panel", colorBlack));
SetChartBkGradientFill(ParamColor("Upper Chart", colorDarkGrey), ParamColor("Lower Chart", colorDarkGrey));

Title = EncodeColor(55)+  Title = Name() + "     " + EncodeColor(32) + Date() +
"      " + EncodeColor(5) + "{{INTERVAL}}  " +
    EncodeColor(55)+ "     Open = "+ EncodeColor(52)+ WriteVal(O,dec) +
    EncodeColor(55)+ "     High = "+ EncodeColor(5) + WriteVal(H,dec) +
    EncodeColor(55)+ "      Low = "+ EncodeColor(32)+ WriteVal(L,dec) +
    EncodeColor(55)+ "    Close = "+ EncodeColor(7)+ WriteVal(C,dec)+
    EncodeColor(55)+ "    Volume = "+ EncodeColor(11)+ WriteVal(V,1);
///////////////////////
colorHighliter = IIf(C >= O, ColorRGB(0, 128, 0), ColorRGB(128, 0, 0));
DemandPoint = (Ref(L, -1) < Ref(L, -2)) & (L < Ref(L, -1)) & (L < Ref(L, 1)) & (Ref(L, 1) < Ref(L, 2));

//Supply Point
//colorSupplyPoint = ParamColor("Supply Line", ColorRGB(255, 128, 0));
SupplyPoint = (Ref(H, -1) > Ref(H, -2)) & (H > Ref(H, -1)) & (H > Ref(H, 1)) & (Ref(H, 1) > Ref(H, 2));

CountTrendBars = 0;
CurrentBar = BarCount - 1;
dx0 = dx1 = dy0 = dy1 = 0;
sx0 = sx1 = sy0 = sy1 = 0;
//Price
SetBarFillColor(colorHighliter);
Plot(C, "Close", IIf(colorHighliter == ColorRGB(128, 0, 128), ColorRGB(255, 0, 255), IIf(colorHighliter == ColorRGB(128, 128, 0), ColorRGB(255, 255, 0), IIf(C > O, ColorRGB(0, 255, 0), IIf(C < O, ColorRGB(255, 0, 0), ColorRGB(255, 255, 255))))), styleCandle, Null, Null, 0, 0, 1);

Plot(EMA(Close,100),"",colorWhite,styleLine );


/*-------------traderji------------------*-------------traderji------------------*/
_SECTION_BEGIN("traderji");
no =  Optimize("TSL",Param("Risk of Trades",20, 1, 20 ,1),1, 20 ,1);
multiplier1 =  Optimize("Multiplier1",Param("Exit Levels",5, 1, 10 ,1),1, 10 ,1);
multiplier2 =  Optimize("Multiplier2",Param("Reversal Points",22, 1, 55 ,1),1, 55 ,1);
atsmode =ParamToggle("For Trader","No|Yes",0);
//////////////
function TBR(no)
{
dres=HHV(H,no);
dsup=LLV(L,no);
davd=IIf(C>Ref(dres,-1),1,IIf(C<Ref(dsup,-1),-1,0));

davn=ValueWhen(davd!=0,davd,1);
Tacl1=IIf(davn==1,dsup,dres);
return Tacl1;
}



function HAI_F6(p,n,s,m)
{
return (PDI(p)>MDI(n)AND Signal(s)<MACD(m));
}

function HAI_F7(p,n,s,m)
{
return (MDI(n)>PDI(p)AND Signal(s)>MACD(m));
}



/////////////
EntrySignal =   HAI_F6(20,10,29,13);
ExitSignal =HAI_F7(20,10,29,13);
Color = IIf( EntrySignal, colorBlue, IIf( ExitSignal, colorRed, colorLightGrey ));


atsmode =ParamToggle("For Trader","No|Yes",0);
if (atsmode==0)
{


Tacl= TBR(no);
dB=H>Tacl;
dS=L<Tacl;
state=IIf(BarsSince(DB)<BarsSince(DS),1,0);
col=IIf(state == 1 ,51,IIf(state ==0,3,1));


TimeFrameSet(multiplier1*Interval());
wtsl= TBR(no);
WB=H>WTSL;
WS=L<WTSL;
TimeFrameRestore();
wtsl=TimeFrameExpand(wtsl,multiplier1*Interval(),expandFirst);
wb=TimeFrameExpand(WB,multiplier1*Interval(),expandFirst);
ws=TimeFrameExpand(WS,multiplier1*Interval(),expandFirst);


TimeFrameSet(multiplier2*Interval());
mtsl= TBR(no);
MB=H>MTSL;//Cross(H,mtsl);
MS=L<MTSL;//Cross(mtsl,L);
TimeFrameRestore();
mtsl=TimeFrameExpand(mtsl,multiplier2*Interval(),expandFirst);
mb=TimeFrameExpand(MB,multiplier2*Interval(),expandFirst);
ms=TimeFrameExpand(MS,multiplier2*Interval(),expandFirst);
CloseAtEnd = 0;
mktclose=152500;
Buy = IIf((Low > WTSL AND Low > MTSL), DB, ((WB AND Low > TacL AND Low > MTSL) OR (MB AND Low > TacL AND Low > WTSL)));
Sell=IIf(CloseAtEnd==False, (DS OR (DS AND WS) AND (Low > MTSL)), (DS OR (DS AND WS) AND (Low > MTSL)) OR TimeNum() > mktclose);
Short = IIf((High < WTSL AND High < MTSL), DS, (WS AND High < TacL AND High < MTSL) OR (MS AND High < TacL AND High < WTSL));
Cover=IIf(CloseAtEnd==False, (DB OR (DB AND WB) AND (High < MTSL)), (DB OR (DB AND WB) AND (High < MTSL)) OR TimeNum() > mktclose);
}


if (atsmode==1)
{
atscode =ParamToggle("I Have My ATS Code","Yes|No",0);
Tacl= TBR(no);
dB=C>Tacl;
dS=C<Tacl;
state=IIf(BarsSince(DB)<BarsSince(DS),1,0);
col=IIf(state == 1 ,51,IIf(state ==0,3,1));
//Plot(2,"",COL,styleArea|styleOwnScale|styleNoLabel,0,100);
Buy = Cover = DB;
Sell = Short = DS;

if (atscode==1)
{

}
}

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);

BarsSincebuy = BarsSince( Buy );
BarsSinceshort = BarsSince( Short );
LastSignal = IIf( BarsSincebuy < BarsSinceshort, 1, -1 );
SellPrice=ValueWhen(Short,C,1);
BuyPrice=ValueWhen(Buy,C,1);
entry = IIf( LastSignal == 1, BuyPrice, ShortPrice );
Long=Flip(Buy,Sell);
Shrt=Flip(Short,Cover);
Relax = NOT Long AND NOT Buy AND NOT shrt AND NOT Sell AND NOT Sell AND NOT Cover;
SellSL=ValueWhen(Short,TacL,1);
BuySL=ValueWhen(Buy,TacL,1);
BuyDifference= BuyPrice - BuySL;
SellDifference = SellSL - SellPrice;

tar1 = IIf(Buy OR Long AND NOT Relax AND NOT Sell AND NOT Cover, (BuyPrice + BuyDifference), (SellPrice - SellDifference));
tar2 = IIf(Buy OR Long AND NOT Relax AND NOT Sell AND NOT Cover, (BuyPrice + (2*BuyDifference)), (SellPrice - (2*SellDifference)));
tar3 = IIf(Buy OR Long AND NOT Relax AND NOT Sell AND NOT Cover, (BuyPrice + (4*BuyDifference)), (SellPrice - (4*SellDifference)));

buyach1 = IIf((Buy OR Long AND NOT Relax AND NOT Cover AND NOT Short AND NOT Shrt), H > tar1, 0);
buyach2 = IIf((Buy OR Long AND NOT Relax AND NOT Cover AND NOT Short AND NOT Shrt), H > tar2, 0);
buyach3 = IIf((Buy OR Long AND NOT Relax AND NOT Cover AND NOT Short AND NOT Shrt), H > tar3, 0);

sellach1 = IIf((Short OR Shrt AND NOT Relax AND NOT Sell AND NOT Buy AND NOT Long), L < tar1, 0);
sellach2 = IIf((Short OR Shrt AND NOT Relax AND NOT Sell AND NOT Buy AND NOT Long), L < tar2, 0);
sellach3 = IIf((Short OR Shrt AND NOT Relax AND NOT Sell AND NOT Buy AND NOT Long), L < tar3, 0);

Trend = ADX(14) > 25 AND NOT ADX(14) < Ref(ADX(14), -1);
Range = ADX(14) < 25 AND NOT ADX(14) > Ref(ADX(14), -1);


tsl = IIf(Buy OR Long OR Short OR Shrt AND NOT Relax, Tacl,Null);
tslcolor = IIf(Buy OR Long AND NOT Relax, colorDarkGreen, colorDarkRed);
Plot(tsl, "",tslcolor,4 + 8);





PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorBlue, 0, L, Offset=-25);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorBlue, 0,L, Offset=-35);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-30);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=25);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0,H, Offset=35);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-30);

if (atsmode==0)
{
PlotShapes(IIf(Sell, shapeStar, shapeNone),colorRed, 0, L, Offset=-15);
PlotShapes(IIf(Cover, shapeStar, shapeNone),colorBrightGreen, 0,L, Offset=-15);
PlotShapes(IIf(CloseAtEnd==True AND TimeNum() > mktclose AND NOT Relax, shapeStar, shapeNone),colorGold, 0,L, Offset=-15);
}

/*-------------traderji------------------*-------------traderji------------------*/

_SECTION_BEGIN("MB_Include");
// Message Board -----------------
GfxSelectFont( "Tahoma", 13, 100 );

GfxSetBkMode( 10 );

GfxSetTextColor
( ColorRGB(253, 254, 230));

if ( SelectedValue( LastSignal ) == 1 )
    {
        GfxSelectSolidBrush( colorDarkGreen );
    }
    else
    {
        GfxSelectSolidBrush( colorDarkRed );
        }


pxHeight = Status( "pxchartheight" ) ;

xx = Status( "pxchartwidth");

Left = 1100;

width = 310;

x = 5;

x2 = 310;

y = pxHeight;

GfxSelectPen( ColorRGB(224, 33, 204), 1); // border color

GfxRoundRect( x, y - 155, x2, y , 7, 7 ) ;
enquiryno = ParamStr( "Enquiry Number", "www.traderji.com" );



{
GfxTextOut
( ("Website: " + enquiryno),13,y-145);
}


GfxTextOut
( ("" + WriteIf(trend, "Trending Market Condition " ,"")), 13, y-125);

GfxTextOut
( ("" + WriteIf(range, "Rangebound Market Condition " ,"")), 13, y-125);

GfxTextOut
( ("" + WriteIf(Buy, "Go Long At "+C+" - Stopout: " +Tacl,"")), 13, y-105);

GfxTextOut
( ("" + WriteIf (Short, "Go Short At "+C+" - Stopout: " +Tacl,"")), 13, y-105);

if (atsmode==0)
{
GfxTextOut
( ("" + WriteIf (Sell AND NOT Short, "Exit Long At "+C,"")), 13, y-105);

GfxTextOut
( ("" + WriteIf (Cover AND NOT Buy, "Exit Short At "+C,"")), 13, y-105);
}

GfxTextOut
( ("" + WriteIf (Long AND NOT Buy, "Buy At "+(BuyPrice)+" - Stopout: " + Tacl + "","")), 13, y-105);

GfxTextOut
( ("" + WriteIf (shrt AND NOT Short, "Short At "+(SellPrice)+" - Stopout: " + Tacl + "","")), 13, y-105);

GfxTextOut
( ("" + WriteIf (Relax, "RELAX!!!","")), 13, y-85);

GfxTextOut
( ("" + WriteIf (Long AND NOT Buy, "Current Profit/Loss: "+(C-BuyPrice)+" Points","")), 13, y-25);

GfxTextOut
( ("" + WriteIf (shrt AND NOT Short, "Current Profit/Loss: "+(SellPrice-C)+" Points","")), 13, y-25);

GfxTextOut
( ("" + WriteIf (Long OR Buy OR Shrt OR Short, "Target 1: "+tar1,"")), 13, y-85);

GfxTextOut
( ("" + WriteIf (Long OR Buy OR Shrt OR Short, "Target 2: "+tar2,"")), 13, y-65);

GfxTextOut
( ("" + WriteIf (Long OR Buy OR Shrt OR Short, "Target 3: "+tar3,"")), 13, y-45);

GfxTextOut
( ("" + WriteIf (buyach1, "Target 1: "+tar1+" :: Achiecheved","")), 13, y-85);

GfxTextOut
( ("" + WriteIf (sellach1, "Target 1: "+tar1+" :: Achiecheved","")), 13, y-85);

GfxTextOut
( ("" + WriteIf (buyach2, "Target 2: "+tar2+" :: Achiecheved","")), 13, y-65);

GfxTextOut
( ("" + WriteIf (sellach2, "Target 2: "+tar2+" :: Achiecheved","")), 13, y-65);

GfxTextOut
( ("" + WriteIf (buyach3, "Target 3: "+tar3+" :: Achiecheved","")), 13, y-45);

GfxTextOut
( ("" + WriteIf (sellach3, "Target 3: "+tar3+" :: Achiecheved","")), 13, y-45);
_SECTION_END();


/*-------------traderji------------------*-------------traderji------------------*/
(
WriteIf (Buy, "Action: Go Long At "+C+" - SL " + Tacl ,"")+
WriteIf (Short, "Action: Go Short At "+C+" - SL " + Tacl ,"")+
WriteIf(Long AND NOT Buy, "Action : Long Taken At "+(BuyPrice)+" - Trail SL @ " + Tacl + "","")+
WriteIf(shrt AND NOT Sell, "Action : Short Taken At "+(SellPrice)+" - Trail SL @ " + Tacl + "","")+
WriteIf (Sell AND NOT Short, "Exit Long At "+C,"")+
WriteIf (Cover AND NOT Buy, "Exit Short At "+C,"")+
WriteIf(NOT Long AND NOT Buy AND NOT shrt AND NOT Sell, "Action: Not In A Trade - RELAX!!!","")+"\n"+ 
WriteIf(Long AND NOT Buy, "Profit/Loss: "+(C-BuyPrice)+" Points","")+
WriteIf(shrt AND NOT Sell, "Profit/Loss: "+(SellPrice-C)+" Points","")+"\n"+
WriteIf(Long OR Buy OR Shrt OR Short, "Target 1: "+tar1,"")+"\n"+
WriteIf(Long OR Buy OR Shrt OR Short, "Target 2: "+tar2,"")+"\n"+
WriteIf(Long OR Buy OR Shrt OR Short, "Target 3: "+tar3,"")+"\n"+
WriteIf(buyach1, "Target 1 Done: "+tar1,"")+
WriteIf(sellach1, "Target 1 Done: "+tar1,"")+"\n"+
WriteIf(buyach2, "Target 2 Done: "+tar2,"")+
WriteIf(sellach2, "Target 2 Done: "+tar2,"")+"\n"+
WriteIf(buyach3, "Target 3 Done: "+tar3,"")+
WriteIf(sellach3, "Target 3 Done: "+tar3,""));
/*-------------traderji------------------*-------------traderji------------------*/


//////////////////////////////////////////////////////////
DayH1 = TimeFrameGetPrice("H", inDaily, -2); 

DayL1 = TimeFrameGetPrice("L", inDaily, -2); 
DayC1 = TimeFrameGetPrice("C", inDaily, -2); 

DayH = TimeFrameGetPrice("H", inDaily, -1); 

DayL = TimeFrameGetPrice("L", inDaily, -1); 

DayC = TimeFrameGetPrice("C", inDaily, -1); 

DayO = TimeFrameGetPrice("O", inDaily);// current day open

///for High1////
N1=(DayC+DayH)/2;
N3=(N1/3)*2;
N5=DayO/3;
H1=N3+N5;  H1I = LastValue (H1,1); // Resistance 1

///for LOW1////

O1 = (DayC+DayL)/2 ;
O3=(O1/3)*2;
L1=O3+N5; L1I = LastValue (L1,1); // Resistance 1

///FOR LOW2 & HIGH2///

H2=H1+(H1-L1); H2I = LastValue (H2,1); // Resistance 1
L2=L1-(H1-L1); L2I = LastValue (L2,1); // Resistance 1

N2=(DayC1+DayH1)/2;
N4=(N2/3)*2;
N5=DayO/3;
H3=N4+N5;


O2 = (DayC1+DayL1)/2 ;
O4=(O2/3)*2;
L3=(O4+DayO)*0.6; 

Plot(H1,"",colorRed,styleLine|styleDots|styleNoRescale);
Plot(H2,"",colorRed,styleLine|styleDots|styleNoRescale);
Plot(L1,"",colorGreen,styleLine|styleDots|styleNoRescale);
Plot(L2,"",colorGreen,styleLine|styleDots|styleNoRescale);
//Plot(H3,"",colorRed,styleLine|styleDots|styleNoRescale);
//Plot(L3,"",colorGreen,styleLine|styleDots|styleNoRescale);
numbars = LastValue(Cum(Status("barvisible")));
fraction= IIf(StrRight(Name(),3) == "", 3.2, 3.2);
hts = -33.5;

PlotText(" RESISTANCE 1 = " + WriteVal(H1,fraction), LastValue(BarIndex())-(numbars/Hts),H1I , colorRed);
PlotText(" RESISTANCE 2 = " + WriteVal(H2,fraction), LastValue(BarIndex())-(numbars/Hts),H2I, colorRed);
PlotText(" SUPPORT 1 = " + WriteVal(L1,fraction), LastValue(BarIndex())-(numbars/Hts),L1I, colorGreen);
PlotText(" SUPPORT 2 = " + WriteVal(L2,fraction), LastValue(BarIndex())-(numbars/Hts),L2I, colorGreen);

i make a drop ox attachment for calculating support and resistance for offline traders

Code:
https://www.dropbox.com/sh/mr2oa6h0oqk5utb/AADx5T2e3w2Jrc3sFqMthC6ma?dl=0
 
Last edited:

Similar threads