supply demand formula from NINJACATOR

#21
Last edited:

oilman5

Well-Known Member
#22
Have you seen my other post on supplydemand basics with links to videos from Alfonso Moreno?-Kevin
.....................................
yes . this is the key.Pl make a team to solve -individual may haywire in it.
Regards
 

johnnypareek

Well-Known Member
#23
Will it help ?????


HTML:
SetChartOptions(0,chartShowArrows|chartShowDates);
bk=ParamColor( "Bk col",colorDarkGrey); 
SetChartBkColor(bk);
SetBarFillColor(IIf(C>O,colorBrightGreen,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C,"  | Sup-Res_N-T style |\nPrice",47,64,0,0,0,0);

sr=ParamToggle("Plot Supp/Res lines","No|Yes" ,1);
Per=Param("Sensitivity",1,0.5,5,0.5);
g=Param("No.of Lines",3,1,5,1);
x=Cum(1);
Pk1=PeakBars(H,per,1)== 0;
Tk1=TroughBars(L,per,1)== 0;

px1=LastValue(ValueWhen(pk1,x,1));
px2=LastValue(ValueWhen(Pk1,x,2));
px3=LastValue(ValueWhen(Pk1,x,3));
px4=LastValue(ValueWhen(pk1,x,4));
px5=LastValue(ValueWhen(Pk1,x,5));

tx1=LastValue(ValueWhen(Tk1,x,1));
tx2=LastValue(ValueWhen(Tk1,x,2));
tx3=LastValue(ValueWhen(Tk1,x,3));
tx4=LastValue(ValueWhen(Tk1,x,4));
tx5=LastValue(ValueWhen(Tk1,x,5));

XT1 =LastValue(ValueWhen(pk1,H,1));XT1c =LastValue(ValueWhen(pk1,Max(C,O),1));
XT2 =LastValue(ValueWhen(Pk1,H,2));XT2c =LastValue(ValueWhen(pk1,Max(C,O),2));
XT3 =LastValue(ValueWhen(Pk1,H,3));XT3c =LastValue(ValueWhen(pk1,Max(C,O),3));
XT4 =LastValue(ValueWhen(pk1,H,4));XT4c =LastValue(ValueWhen(pk1,Max(C,O),4));
XT5 =LastValue(ValueWhen(Pk1,H,5));XT5c =LastValue(ValueWhen(pk1,Max(C,O),5));

YT1 =LastValue(ValueWhen(tk1,L,1));YT1c =LastValue(ValueWhen(tk1,Min(O,C),1));
YT2 =LastValue(ValueWhen(tk1,L,2));YT2c =LastValue(ValueWhen(tk1,Min(O,C),2));
YT3 =LastValue(ValueWhen(tk1,L,3));YT3c =LastValue(ValueWhen(tk1,Min(O,C),3));
YT4 =LastValue(ValueWhen(tk1,L,4));YT4c =LastValue(ValueWhen(tk1,Min(O,C),4));
YT5 =LastValue(ValueWhen(tk1,L,5));YT5c =LastValue(ValueWhen(tk1,Min(O,C),5));

pk1=IIf(x>px1 AND g>=1 AND sr,XT1,Null);pk1c=IIf(x>px1 AND g>=1 AND sr,XT1c,Null);
Col1=IIf( LastValue(C)>pk1, ColorRGB(14,14,100), ColorRGB(180,20,20) );
Plot(pk1,"",31,1);PlotOHLC(0,pk1,pk1c,0,"",Col1,styleCloud|styleNoLabel,Null, Null, Null, -1);
pk2=IIf(x>px2 AND g>=2 AND sr,XT2,Null);pk2c=IIf(x>px2 AND g>=2 AND sr,XT2c,Null);
Col2=IIf( LastValue(C)>pk2, ColorRGB(24,24,120), ColorRGB(180,40,40) );
Plot(pk2,"",31,1);PlotOHLC(0,pk2,pk2c,0,"",Col2,styleCloud|styleNoLabel,Null, Null, Null, -2);
pk3=IIf(x>px3 AND g>=3 AND sr,XT3,Null);pk3c=IIf(x>px3 AND g>=3 AND sr,XT3c,Null);
Col3=IIf( LastValue(C)>pk3, ColorRGB(34,34,140),ColorRGB(180,60,60));
Plot(pk3,"",31, 1);PlotOHLC(0,pk3,pk3c,0,"",Col3,styleCloud|styleNoLabel,Null, Null, Null, -3);
pk4=IIf(x>px4 AND g>=4 AND sr,XT4,Null);pk4c=IIf(x>px4 AND g>=4 AND sr,XT4c,Null);
Col4=IIf( LastValue(C)>pk4, ColorRGB(44,44,160), ColorRGB(180,80,80));
Plot(pk4,"",31,1);PlotOHLC(0,pk4,pk4c,0,"",Col4,styleCloud|styleNoLabel,Null, Null, Null, -4);
pk5=IIf(x>px5 AND g>=5 AND sr,XT5,Null);pk5c=IIf(x>px5 AND g>=5 AND sr,XT5c,Null);
Col5=IIf( LastValue(C)>pk5, ColorRGB(54,54,180), ColorRGB(180,100,100));
Plot(pk5,"",31,1);PlotOHLC(0,pk5,pk5c,0,"",Col5,styleCloud|styleNoLabel,Null, Null, Null, -5);
tl1=IIf(x>tx1 AND g>=1 AND sr,YT1,Null);tl1c=IIf(x>tx1 AND g>=1 AND sr,YT1c,Null);
Col1=IIf( LastValue(C)>tl1, ColorRGB(14,14,100), ColorRGB(180,20,20)  );
Plot(tl1,"",1,1);PlotOHLC(0,tl1,tl1c,0,"",Col1,styleCloud|styleNoLabel,Null, Null, Null, -1);
tl2=IIf(x>tx2 AND g>=2 AND sr,YT2,Null);tl2c=IIf(x>tx2 AND g>=2 AND sr,YT2c,Null);
Col2=IIf( LastValue(C)>YT2, ColorRGB(24,24,120), ColorRGB(180,40,40));
Plot(tl2,"",1,1);PlotOHLC(0,tl2,tl2c,0,"",Col2,styleCloud|styleNoLabel,Null, Null, Null, -2);
tl3=IIf(x>tx3 AND g>=3 AND sr,YT3,Null);tl3c=IIf(x>tx3 AND g>=3 AND sr,YT3c,Null);
Col3=IIf( LastValue(C)>YT3, ColorRGB(34,34,140), ColorRGB(180,60,60) );
Plot(tl3,"",1,1);PlotOHLC(0,tl3,tl3c,0,"",Col3,styleCloud|styleNoLabel,Null, Null, Null, -3);
tl4=IIf(x>tx4 AND g>=4 AND sr,YT4,Null);tl4c=IIf(x>tx4 AND g>=4 AND sr,YT4c,Null);
Col4=IIf( LastValue(C)>YT4, ColorRGB(44,44,160), ColorRGB(180,80,80) );
Plot(tl4,"",1,1);PlotOHLC(0,tl4,tl4c,0,"",Col4,styleCloud|styleNoLabel,Null, Null, Null, -4);
tl5=IIf(x>tx5 AND g>=5 AND sr,YT5,Null);tl5c=IIf(x>tx5 AND g>=5 AND sr,YT5c,Null);
Col5=IIf( LastValue(C)>YT5, ColorRGB(54,54,180), ColorRGB(180,100,100));
Plot(tl5,"",1,1);PlotOHLC(0,tl5,tl5c,0,"",Col5,styleCloud|styleNoLabel,Null, Null, Null, -5);

GfxSetOverlayMode(1);
GfxSetTextColor(10); 
GfxSelectFont("Old English Text MT", 12, 300, False, False, 0); 
GfxTextOut("  Casoni ", Status("pxwidth")-60 , Status("pxheight")-20 );
 
#24
Hello everyone.
Sorry for keeping you waiting, here the formula

HTML:
SetChartOptions(0,chartShowArrows|chartShowDates);
bk=ParamColor( "Bk col",colorDarkGrey); 
SetChartBkColor(bk);
SetBarFillColor(IIf(C>O,colorBrightGreen,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C,"  | Sup-Res_N-T style |\nPrice",47,64,0,0,0,0);

sr=ParamToggle("Plot Supp/Res lines","No|Yes" ,1);
Per=Param("Sensitivity",1,0.5,5,0.5);
g=Param("No.of Lines",3,1,5,1);
x=Cum(1);
Pk1=PeakBars(H,per,1)== 0;
Tk1=TroughBars(L,per,1)== 0;

px1=LastValue(ValueWhen(pk1,x,1));
px2=LastValue(ValueWhen(Pk1,x,2));
px3=LastValue(ValueWhen(Pk1,x,3));
px4=LastValue(ValueWhen(pk1,x,4));
px5=LastValue(ValueWhen(Pk1,x,5));

tx1=LastValue(ValueWhen(Tk1,x,1));
tx2=LastValue(ValueWhen(Tk1,x,2));
tx3=LastValue(ValueWhen(Tk1,x,3));
tx4=LastValue(ValueWhen(Tk1,x,4));
tx5=LastValue(ValueWhen(Tk1,x,5));

XT1 =LastValue(ValueWhen(pk1,H,1));XT1c =LastValue(ValueWhen(pk1,Max(C,O),1));
XT2 =LastValue(ValueWhen(Pk1,H,2));XT2c =LastValue(ValueWhen(pk1,Max(C,O),2));
XT3 =LastValue(ValueWhen(Pk1,H,3));XT3c =LastValue(ValueWhen(pk1,Max(C,O),3));
XT4 =LastValue(ValueWhen(pk1,H,4));XT4c =LastValue(ValueWhen(pk1,Max(C,O),4));
XT5 =LastValue(ValueWhen(Pk1,H,5));XT5c =LastValue(ValueWhen(pk1,Max(C,O),5));

YT1 =LastValue(ValueWhen(tk1,L,1));YT1c =LastValue(ValueWhen(tk1,Min(O,C),1));
YT2 =LastValue(ValueWhen(tk1,L,2));YT2c =LastValue(ValueWhen(tk1,Min(O,C),2));
YT3 =LastValue(ValueWhen(tk1,L,3));YT3c =LastValue(ValueWhen(tk1,Min(O,C),3));
YT4 =LastValue(ValueWhen(tk1,L,4));YT4c =LastValue(ValueWhen(tk1,Min(O,C),4));
YT5 =LastValue(ValueWhen(tk1,L,5));YT5c =LastValue(ValueWhen(tk1,Min(O,C),5));

pk1=IIf(x>px1 AND g>=1 AND sr,XT1,Null);pk1c=IIf(x>px1 AND g>=1 AND sr,XT1c,Null);
Col1=IIf( LastValue(C)>pk1, ColorRGB(14,14,100), ColorRGB(180,20,20) );
Plot(pk1,"",31,1);PlotOHLC(0,pk1,pk1c,0,"",Col1,styleCloud|styleNoLabel,Null, Null, Null, -1);
pk2=IIf(x>px2 AND g>=2 AND sr,XT2,Null);pk2c=IIf(x>px2 AND g>=2 AND sr,XT2c,Null);
Col2=IIf( LastValue(C)>pk2, ColorRGB(24,24,120), ColorRGB(180,40,40) );
Plot(pk2,"",31,1);PlotOHLC(0,pk2,pk2c,0,"",Col2,styleCloud|styleNoLabel,Null, Null, Null, -2);
pk3=IIf(x>px3 AND g>=3 AND sr,XT3,Null);pk3c=IIf(x>px3 AND g>=3 AND sr,XT3c,Null);
Col3=IIf( LastValue(C)>pk3, ColorRGB(34,34,140),ColorRGB(180,60,60));
Plot(pk3,"",31, 1);PlotOHLC(0,pk3,pk3c,0,"",Col3,styleCloud|styleNoLabel,Null, Null, Null, -3);
pk4=IIf(x>px4 AND g>=4 AND sr,XT4,Null);pk4c=IIf(x>px4 AND g>=4 AND sr,XT4c,Null);
Col4=IIf( LastValue(C)>pk4, ColorRGB(44,44,160), ColorRGB(180,80,80));
Plot(pk4,"",31,1);PlotOHLC(0,pk4,pk4c,0,"",Col4,styleCloud|styleNoLabel,Null, Null, Null, -4);
pk5=IIf(x>px5 AND g>=5 AND sr,XT5,Null);pk5c=IIf(x>px5 AND g>=5 AND sr,XT5c,Null);
Col5=IIf( LastValue(C)>pk5, ColorRGB(54,54,180), ColorRGB(180,100,100));
Plot(pk5,"",31,1);PlotOHLC(0,pk5,pk5c,0,"",Col5,styleCloud|styleNoLabel,Null, Null, Null, -5);
tl1=IIf(x>tx1 AND g>=1 AND sr,YT1,Null);tl1c=IIf(x>tx1 AND g>=1 AND sr,YT1c,Null);
Col1=IIf( LastValue(C)>tl1, ColorRGB(14,14,100), ColorRGB(180,20,20)  );
Plot(tl1,"",1,1);PlotOHLC(0,tl1,tl1c,0,"",Col1,styleCloud|styleNoLabel,Null, Null, Null, -1);
tl2=IIf(x>tx2 AND g>=2 AND sr,YT2,Null);tl2c=IIf(x>tx2 AND g>=2 AND sr,YT2c,Null);
Col2=IIf( LastValue(C)>YT2, ColorRGB(24,24,120), ColorRGB(180,40,40));
Plot(tl2,"",1,1);PlotOHLC(0,tl2,tl2c,0,"",Col2,styleCloud|styleNoLabel,Null, Null, Null, -2);
tl3=IIf(x>tx3 AND g>=3 AND sr,YT3,Null);tl3c=IIf(x>tx3 AND g>=3 AND sr,YT3c,Null);
Col3=IIf( LastValue(C)>YT3, ColorRGB(34,34,140), ColorRGB(180,60,60) );
Plot(tl3,"",1,1);PlotOHLC(0,tl3,tl3c,0,"",Col3,styleCloud|styleNoLabel,Null, Null, Null, -3);
tl4=IIf(x>tx4 AND g>=4 AND sr,YT4,Null);tl4c=IIf(x>tx4 AND g>=4 AND sr,YT4c,Null);
Col4=IIf( LastValue(C)>YT4, ColorRGB(44,44,160), ColorRGB(180,80,80) );
Plot(tl4,"",1,1);PlotOHLC(0,tl4,tl4c,0,"",Col4,styleCloud|styleNoLabel,Null, Null, Null, -4);
tl5=IIf(x>tx5 AND g>=5 AND sr,YT5,Null);tl5c=IIf(x>tx5 AND g>=5 AND sr,YT5c,Null);
Col5=IIf( LastValue(C)>YT5, ColorRGB(54,54,180), ColorRGB(180,100,100));
Plot(tl5,"",1,1);PlotOHLC(0,tl5,tl5c,0,"",Col5,styleCloud|styleNoLabel,Null, Null, Null, -5);

GfxSetOverlayMode(1);
GfxSetTextColor(10); 
GfxSelectFont("Old English Text MT", 12, 300, False, False, 0); 
GfxTextOut("  Casoni ", Status("pxwidth")-60 , Status("pxheight")-20 );
Thank you

Thanks for the code

one feedback . . . when open/close is swing High or Low ,i.e. no tails at S/R
a thin line is plotted can add code to make it thick

Code:
Plot(IIf(AlmostEqual(pk1,pk1c),pk1,Null),"",31,styleThick,0,0,0,0,3);
I find the S/R bands plotted by cloud obstructing the PA so changed the code to plot lines instead of cloud

Code:
SetChartOptions(0,chartShowArrows|chartShowDates);
bk=ParamColor( "Bk col",colorDarkGrey); 
SetChartBkColor(bk);
SetBarFillColor(IIf(C>O,colorBrightGreen,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C,"  | Sup-Res_N-T style |\nPrice",47,64,0,0,0,0);

sr=ParamToggle("Plot Supp/Res lines","No|Yes" ,1);
Per=Param("Sensitivity",1,0.2,5,0.1);
g=Param("No.of Lines",3,1,5,1);
x=Cum(1);
Pk1=PeakBars(H,per,1)== 0;
Tk1=TroughBars(L,per,1)== 0;

px1=LastValue(ValueWhen(Pk1,x,1));		px2=LastValue(ValueWhen(Pk1,x,2));		px3=LastValue(ValueWhen(Pk1,x,3));		px4=LastValue(ValueWhen(Pk1,x,4));		px5=LastValue(ValueWhen(Pk1,x,5));	
tx1=LastValue(ValueWhen(Tk1,x,1));		tx2=LastValue(ValueWhen(Tk1,x,2));		tx3=LastValue(ValueWhen(Tk1,x,3));		tx4=LastValue(ValueWhen(Tk1,x,4));		tx5=LastValue(ValueWhen(Tk1,x,5));	
XT1 =LastValue(ValueWhen(pk1,H,1));	XT2 =LastValue(ValueWhen(Pk1,H,2));	XT3 =LastValue(ValueWhen(Pk1,H,3));	XT4 =LastValue(ValueWhen(pk1,H,4));	XT5 =LastValue(ValueWhen(Pk1,H,5));
YT1 =LastValue(ValueWhen(tk1,L,1));	YT2 =LastValue(ValueWhen(tk1,L,2));	YT3 =LastValue(ValueWhen(tk1,L,3));	YT4 =LastValue(ValueWhen(tk1,L,4));	YT5 =LastValue(ValueWhen(tk1,L,5));
pk1=IIf(x>px1 AND g>=1 AND sr,XT1,Null);		Col1=IIf( LastValue(C)>pk1, ColorRGB(14,14,100), ColorRGB(180,20,20));
pk2=IIf(x>px2 AND g>=2 AND sr,XT2,Null);		Col2=IIf( LastValue(C)>pk2, ColorRGB(24,24,120), ColorRGB(180,40,40));
pk3=IIf(x>px3 AND g>=3 AND sr,XT3,Null);		Col3=IIf( LastValue(C)>pk3, ColorRGB(34,34,140),ColorRGB(180,60,60));
pk4=IIf(x>px4 AND g>=4 AND sr,XT4,Null);		Col4=IIf( LastValue(C)>pk4, ColorRGB(44,44,160), ColorRGB(180,80,80));
pk5=IIf(x>px5 AND g>=5 AND sr,XT5,Null);		Col5=IIf( LastValue(C)>pk5, ColorRGB(54,54,180), ColorRGB(180,100,100));

Plot(pk1,"",Col1,styleThick,Null, Null, Null, -1,3);
Plot(pk2,"",Col2,styleThick,Null, Null, Null, -2,3);
Plot(pk3,"",Col3,styleThick,Null, Null, Null, -3,3);
Plot(pk4,"",Col4,styleThick,Null, Null, Null, -4,3);
Plot(pk5,"",Col5,styleThick,Null, Null, Null, -5,3);

tl1=IIf(x>tx1 AND g>=1 AND sr,YT1,Null);		Col1=IIf( LastValue(C)>tl1, ColorRGB(14,14,100), ColorRGB(180,20,20));
tl2=IIf(x>tx2 AND g>=2 AND sr,YT2,Null);		Col2=IIf( LastValue(C)>YT2, ColorRGB(24,24,120), ColorRGB(180,40,40));
tl3=IIf(x>tx3 AND g>=3 AND sr,YT3,Null);		Col3=IIf( LastValue(C)>YT3, ColorRGB(34,34,140), ColorRGB(180,60,60));
tl4=IIf(x>tx4 AND g>=4 AND sr,YT4,Null);		Col4=IIf( LastValue(C)>YT4, ColorRGB(44,44,160), ColorRGB(180,80,80));
tl5=IIf(x>tx5 AND g>=5 AND sr,YT5,Null);		Col5=IIf( LastValue(C)>YT5, ColorRGB(54,54,180), ColorRGB(180,100,100));

Plot(tl1,"",Col1,styleThick,Null, Null, Null, -1,3);
Plot(tl2,"",Col2,styleThick,Null, Null, Null, -2,3);
Plot(tl3,"",Col3,styleThick,Null, Null, Null, -3,3);
Plot(tl4,"",Col4,styleThick,Null, Null, Null, -4,3);
Plot(tl5,"",Col5,styleThick,Null, Null, Null, -5,3);

GfxSetOverlayMode(1);
GfxSetTextColor(10); 
GfxSelectFont("Old English Text MT", 12, 300, False, False, 0); 
GfxTextOut("  Casoni ", Status("pxwidth")-60 , Status("pxheight")-20 );

:) Happy
 
Last edited:
#25
Hi johnny

The code you posted above it seems same as casonis code.
Have you tried to make any improvement?
Just asking.
to me it is not clear
SENSITIVITY IS KEY.
If I keep sen =1,it plots lowest demand levels clearly.If sen is increased it gets only higher levels

Here are two charts
first is by the code you showed above
second is by casoni original code
Both show L&T chart on 5 min
For some reason,the chart given by code posted by you,of course with casoni label logo,shows a bit more clarity.
I cant understand why it is so.


is it zooming impact? coding change if any? or some mistake on my part?
first


second
 
Last edited:
#26
hi HAPPY

Supply demand bands are vital requirement.
they need to proviode a hide/show parameter.
when you feel band is hiding price etc you can just hide bands and then come back.

AS I say SD ZONeS are not simple plot cloud stuff. there is much more & beyond.
and one more thing
while trading on 4hour or daily or weekly timeframes the tails or wicks OF CANDLES just are enough to plot SD ZONES.

Hope you will be able to see the point soon.]
regards
ford
 
#27
Here is an even shorter and little bit more elegant version.
There are endless possibilities.
nice code . . . trash

Same modification for getting lines instead of cloud . . .

Yes truly elegant can be seen from the easy with which modification can be implemented . . . without much effort

Cheers

Code:
SetBarFillColor(IIf(C>O,colorBrightGreen,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C,"  | Sup-Res_N-T style |\nPrice",47,64,0,0,0,0);



// by trash

SDswitch    = ParamToggle( "Supply/Demand Zones", "OFF|ON", 1 );
NumZones    = Param( "Number of Zones", 5, 1, 30, 1 );
Sensitivity = Param( "Sensitivity", 0.5, 0.1, 10, 0.1 );

style1      = ParamStyle( "Style 1", styleNoLabel | styleNoRescale ) | styleCloud;
style2      = ParamStyle( "Style 2", styleNoLabel | styleNoRescale );

Colorline   = ParamColor( "Color Borders", colorBlack );

selectedC   = SelectedValue( C );
selectedBI  = SelectedValue( BarIndex() );
MinVal      = Min( O, C );
MaxVal      = Max( O, C );

for ( i = 1; i <= NumZones; i++ )
{
    x1      = selectedBI - SelectedValue( PeakBars( H, Sensitivity, i ) );

    y1      = SelectedValue( Peak( H, Sensitivity, i ) );
    Line1   = LineArray( x1[i] + 1, y1[i], selectedBI, y1[i], 1 );

    y2      = SelectedValue( ValueWhen( H == y1, MaxVal ) );
    Line2   = LineArray( x1[i] + 1, y2[i], selectedBI, y2[i], 1 );

    //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

    x2      = selectedBI - SelectedValue( TroughBars( L, Sensitivity, i ) );

    y3      = SelectedValue( Trough( L, Sensitivity, i ) );
    Line3   = LineArray( x2[i] + 1, y3[i], selectedBI, y3[i], 1 );

    y4      = SelectedValue( ValueWhen( L == y3, MinVal ) );
    Line4   = LineArray( x2[i] + 1, y4[i], selectedBI, y4[i], 1 );

    //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

    i_1     = 20 * i;
    i_2     = 25 + ( i - 1 ) * 10;
    Rcolor  = ColorRGB( 180, i_1, i_1 ); // ParamColor( "Supply Color", colorBrown  );
    Scolor  = ColorRGB( i_2, i_2, 80 + i_1 ); // ParamColor( "Demand Color", colorGreen  );
//    RColor  = IIf( selectedC > y1, Scolor, Rcolor );
//    SColor  = IIf( selectedC > y4, Scolor, Rcolor );

    if ( SDSwitch )
    {
        zorder      = -i - 9;

//        PlotOHLC( Line1, Line1, Line2, Line2, "", Rcolor, style1, 0, 1, 0, zorder );
          Plot( Line1, "", Rcolor, style2, 0, 1, 0, zorder,3 );
//        Plot( Line2, "", Colorline, style2, 0, 1, 0, zorder + 1 );

//        PlotOHLC( Line3, Line3, Line4, Line4, "", Scolor, style1, 0, 1, 0, zorder );
          Plot( Line3, "", Scolor, style2, 0, 1, 0, zorder,3 );
//        Plot( Line4, "", Colorline, style2, 0, 1, 0, zorder + 1 );

    }
}

:) Happy
 
#28
Hi friends

Intraday traders
can use sensitivity of 0.50 setting in parameters

maximum sensitivity 1 can be used.


As you increase sensitivity beyond 2 you cant see lower supply demand levels as needed by intraday traders.

so play with sensitivity setting get idea what suits you best for your style.
cheers
 

mastermind007

Well-Known Member
#29
Hi
It is your choice. if you think it no problem you canm post your half work & forum experts will take it forwards.
Hello Ford

Thank you for the suggestion. Here is my code.

I was actually driving it in a completely different direction (maybe parallel track) to what casoni and trash have shared.

Mine is based on Periodic peaks and troughs without using Zig and it will calculate peak accurately using calendar dates. It will fallback to default number of days only when the data is missing. As long as you have the accurate data, Yearly peak identified by this AFL will always match what NSE lists in its bhav copies

Although I started with exploration bit in it, I've never finished it ...

Code:
_SECTION_BEGIN("SUPPLY DEMAND"); // HH HL SYSTEM?? using a LOOP and StrExtract
       /// by MASTERMIND007 TRADERJI  // http://www.traderji.com/amibroker/88984-supply-demand-formula-ninjacator-3.html#post843840
	SetChartOptions(1,chartHideQuoteMarker | chartShowArrows|chartShowDates,0,0);

	Plot( C, "Close", colorBlack, styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

	// Next 5 lines control number of peaks and troughs plotted.
	// Values in both are paired with one another and
	// entire list must be in reverse order.
	// This will ensure that plotting text will remain correct
	PeriodNumDaysList = "260,130,65,22,11,6,3";
	PeriodNameList = "Yearly,Half-Yearly,Quarterly,Monthly,BiWeekly,Weekly,Daily";
	IntervalList = "inYearly,inMonthly,inMonthly,inMonthly,inWeekly,inWeekly,inDaily";
	IntervalDiffValue  = "-1,-6,-3,-1,-2,-1,-1";

	lc = 1 + StrCount(PeriodNumDaysList, ",");
	Dates = DateTime();
	TimeFrameSet(inDaily);

	tt = "";
	sName = "";
	pCap = "";
	pCapVal = "";
	trCap = "";
	trCapVal = "";

	for (i = 0; i < lc; i++)
	{
		prdDef = StrToNum(StrExtract(PeriodNumDaysList, i));
		sName = StrExtract(PeriodNameList, i);
		intrvl = StrExtract(IntervalList, i);
		diffVal = StrToNum(StrExtract(IntervalDiffValue, i));

		pastDate = selectedDate = SelectedValue(Dates);
		if (intrvl == "inYearly")
			pastDate = DateTimeAdd(selectedDate, diffVal, inYearly);
		else if (intrvl == "inMonthly")
			pastDate = DateTimeAdd(selectedDate, diffVal, inMonthly);
		else if (intrvl == "inWeekly")
			pastDate = DateTimeAdd(selectedDate, diffVal, inWeekly);
		else if (intrvl == "inDaily")
			pastDate = DateTimeAdd(selectedDate, diffVal, inDaily);

		// Use BarGaps ??
		prdAct = BarsSince((Ref(Dates,-1) < pastDate) AND (Dates >= pastDate));

		if (SelectedValue(IsNull(prdAct)))
		{
			pk = HHV(H, prdDef);
			tr = LLV(L, prdDef);
		} else
		{
			pk = HHV(H, prdAct);
			tr = LLV(L, prdAct);
		}

		tr2 = LLV(L, prdDef);

		// LineArray uses default integral value for periods
		la1 = LineArray(SelectedValue(BarIndex()) - prdDef - 2,  SelectedValue(pk), SelectedValue(BarIndex()), SelectedValue(pk));
		la2 = LineArray(SelectedValue(BarIndex()) - prdDef - 2,  SelectedValue(tr), SelectedValue(BarIndex()), SelectedValue(tr));

		Plot(la1, sName + " High", colorBlue, styleNoLabel | styleNoTitle | styleThick);
		Plot(la2, sName + " Low", colorRed,   styleNoLabel | styleNoTitle | styleThick);

		if ((i != 0) AND SelectedValue(pkPrev) == SelectedValue(pk))
		{
			pCap = pCap + "; " + StrLeft(sName,1);
		}  else
		{
			pCap = pCap + "," + StrLeft(sName,1);
			pCapVal = pCapVal + "," + pk;
		}

		if ((i != 0) AND SelectedValue(trPrev) == SelectedValue(tr))
		{
			trCap = trCap + "; " + StrLeft(sName,1);
		}  else
		{
			trCap = trCap + "," + StrLeft(sName,1);
			trCapVal = trCapVal + "," + tr;
		}

		pkPrev = pk;
		trPrev = tr;
	}
	TimeFrameRestore();

	PeakCaptionCount = 1 + StrCount(pCapVal, ",");
	lvb = Status("lastvisiblebar");

	for (j = 0; j < PeakCaptionCount; j++)
	{
		PlotText(StrExtract(pCapVal, j)  + "-" + StrExtract(pCap, j), lvb - 15, StrToNum(StrExtract(pCapVal, j)), colorWhite, colorDarkBlue);
	}

	TroughCaptionCount = 1 + StrCount(trCapVal, ",");
	for (k = 0; k < TroughCaptionCount; k++)
	{
		PlotText(StrExtract(trCapVal, k) + "-" + StrExtract(trCap, k), lvb - 15, StrToNum(StrExtract(trCapVal, k)), colorWhite, colorDarkRed);
	}

	Filter = 1;
	AddTextColumn( FullName(), "Name");
	AddColumn( Close, "Close" );

	_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}} Vol " + WriteVal( V, 1.0 )
	, O, H, L, C, SelectedValue( ROC( C, 1 ))) );

	//#include "C:\Program Files\AmiBroker\Formulas\Basic Charts\VAP.afl"
_SECTION_END();
 
Last edited:

casoni

Well-Known Member
#30
very interesting mastermind007
thanks for sharing :thumb:
 

Similar threads