supply demand formula from NINJACATOR

casoni

Well-Known Member
#11
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
 
Last edited:

trash

Well-Known Member
#14
Hi Casoni

This is first of this kind of formula in Amibroker.
Many thanks for your hard work and generous sharing.

Please post it on wisestocktrader

best regards
ford

It is not the first one. You just have to code it or add stylecloud line to existing codes. It is simple. I don't know why you make such a big deal out of a simple support/resistance or supply/demand AFL using stylecloud.

Here is an even shorter and little bit more elegant version.
There are endless possibilities.

Code:
// 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, "", Colorline, style2, 0, 1, 0, zorder + 1 );
        Plot( Line2, "", Colorline, style2, 0, 1, 0, zorder + 1 );

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

    }
}
 

oilman5

Well-Known Member
#15
Good initiative by all,original selling around 30000/- .just see omnitrader.com-similar moneyzone concept.But this one is better............can it be already checked in amibroker.
Similar can be made in Metastock?
This hidden i have seen with foreign-trainer
Success to programmer
 

KelvinHand

Well-Known Member
#16
It is not the first one. You just have to code it or add stylecloud line to existing codes. It is simple.

I don't know why you make such a big deal out of a simple support/resistance or supply/demand AFL using stylecloud.

No everybody is that skillful as you.
Sometime people need to draft out the idea first without tidy it up to see the code is workable.

If you put too much consideration in programming, such as draft and tidy up, you many end up unnecessary mistake and had to debug and slow down the process.
Once the code is workable, then you still can do tidy up.

Especially in looping, one you are not aware of it, landed up you got "out of range" issue, you may got nightmare to solve about it.


So should give a thumb up for casoni's effort.:thumb:
 
Last edited:

trash

Well-Known Member
#17
No everybody is that skillful as you.
Sometime people need to draft out the idea first without tidy it up to see the code is workable.

If you put too much consideration in programming, such as draft and tidy up, you many end up unnecessary mistake and had to debug and slow down the process.
Once the code is workable, then you still can do tidy up.

Especially in looping, one you are not aware of it, landed up you got "out of range" issue, you will got nightmare to solve it.


So should give a thumb up for casoni's effort.:thumb:

You misunderstood. It was not meant against Casoni!

I was referring to code leecher ford7k because in the past all the time he (if my memory serves me right) was saying that things like that can't be done in AB and always made a big deal out of it like it would be some kind of most sensational thing on planet earth. It is not.
 
Last edited:
#18
Hi trash
Thanks for your code on supply demand.It looks good by itself.Will test it .
Casonis code provides that thing like Ninjatrader sd which we guys are after.

I think you are misunderstanding my intentions.
Sorry if my post offended your sentiment etc,but my intention was not that.
If you had already posted your sd code here on traderji,I couldnot get to see it.
Of course in a family brothers do have minor differences but thy are together when a good cause comesup.
Have you seen my other post on supplydemand basics with links to videos from Alfonso Moreno?
take time have a look at it,please.


I am not here to create misunderstandings with you or anyone.
I am here to contribute,indirectly or directly,or be a spark for contributions by others.
An important thing is an important thing. What is big deal remains bigdeal.

-----------------------------------------------------------
AIM OF THE TRADER
The aim is to move into indepth coding of supply demand zones and get help from it in trading multiple timeframes etc.
When we trade a 5 minute or 15 min timeframe with sd zones of that small tf visible,but also sd zones of hourly and or 4 hourly sd zones visible,then and only then we stop trading against higher timeframe trends and thus learn patience & discipline soon.


Whatever anybody says,I stick to my view that casoni,s effort is very important to move into supply demand area of coding in Amibroker.

It is not so simple as plot OHLC cloud of some normal support resistance lines.
There are some very important guidelines behind supply demand coding in Amibroker.
Anyways ,I appreciate if you can post some lines on logically-technically-why your code is structurally better than the other code by casoni. I will try it myself.
Let us move on.
regards
ford
 
#19
HI thanks.
Here are SOME LINKS I found.
please confirm if this is what you meant.

http://www.omnitrader.com/Products/Plugins/moneyzone3.aspx





Good initiative by all,original selling around 30000/- .just see omnitrader.com-similar moneyzone concept.But this one is better............can it be already checked in amibroker.
Similar can be made in Metastock?
This hidden i have seen with foreign-trainer
Success to programmer
 

oilman5

Well-Known Member
#20
HI thanks.
Here are SOME LINKS I found.
please confirm if this is what you meant.

http://www.omnitrader.com/Products/Plugins/moneyzone3.aspx



..............................................................................
Yes.
1) 2 types of reversal is possible..........most imp Deep correction and again trend continuation
2) another is strong reversal itself from resistance.
Mentioned video/demand -supply is very sought after.
Regards
 

Similar threads