supply demand formula from NINJACATOR

trash

Well-Known Member
#41
Update 1.1 of my Supply Demand AFl of page 2
with additional parameters.

Code:
// by trash, vers.1.1

SDswitch    = ParamToggle( "Supply/Demand Zones", "OFF|ON", 1 );
SDmode      = ParamList( "Supply/Demand Mode", "Small|Large|Extra Large", 0 );
NumZones    = Param( "Number of Zones", 5, 1, 30, 1 );
Sensitivity = Param( "Sensitivity", 0.4, 0.1, 10, 0.1 );

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

ColorDem    = ParamColor( "Blend Color - Demand Zones", colorBlueGrey );
ColFacDem   = Param( "Blend Color Factor - Demand Zones", 0.45, 0, 2, 0.01 );
ColorSup    = ParamColor( "Blend Color - Supply Zones", colorDarkRed );
ColFacSup   = Param( "Blend Color Factor - Supply Zones", 0.65, 0, 2, 0.01 );
Colorline   = ParamColor( "Color - Zone Borders", colorBlack );

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

if( SDmode == "Small")
{
    ValSup  = MaxVal;
    ValDem  = MinVal;
}
else if( SDmode == "Large" )
{
    ValSup  = MinVal;
    ValDem  = MaxVal;
}
else
{
    ValSup  = L;
    ValDem  = H;
}

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

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

    y2      = SelectedValue( ValueWhen( H == y1, ValSup ) );
    Line2   = LineArray( x1 + 1, y2, selectedBI, y2, 1 );

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

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

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

    y4      = SelectedValue( ValueWhen( L == y3, ValDem ) );
    Line4   = LineArray( x2 + 1, y4, selectedBI, y4, 1 );

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

    i_1     = 20 * i;
    i_2     = 25 + ( i - 1 ) * 10;
    Rcolor  = ColorBlend( ColorSup, ColorRGB( 180, i_1, i_1 ), ColFacSup ); // ParamColor( "Supply Color", colorBrown  );
    Scolor  = ColorBlend( ColorDem, ColorRGB( i_2, i_2, 80 + i_1 ), ColFacDem ); // 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 );

    }
}
 

casoni

Well-Known Member
#42
Yes, it shows blank to those who use it and don't thank but instead only demand. Figure it out yourself. I know what's the reason.
:lol: :lol: :)
 

casoni

Well-Known Member
#43
Update 1.1 of my Supply Demand AFl of page 2
with additional parameters.

Hello trash ,
:thumb:
Superb ..
thank you :)
 
#44
Hi casoni

Thanks for the update.
Just one doubt
please explain

WHAT IS THE ADVANTAGE OF selected value based plot of s d zones?
just we click a bit away the picture changes.
Do you think once a supply demand zone formed,will it change?
Of course the lowerside sd zones will appear as price goes into nearby areas.

To me it looks the fixed zones are better-I only hope to find some sound logic to dislike them.

what are the experts views?
Please give me a convincing logic to agree with changing sd zones based on mouse clicks.
thanks in advance
ford
 

trash

Well-Known Member
#45
SelectedValue is the same as LastValue only with the addition that you can also view historical data behaviour. If no bar is selected then SelectedValue == LastValue!

There is no "this or that is better" whatsoever. Both (LastValue and SelectedValue) behave the same in real-time (at last value) with new data arriving. It is pretty easy to understand.


PS: I'm not Casoni.
try these

 
Last edited:

mastermind007

Well-Known Member
#48
Hi casoni

Thanks for the update.
Just one doubt
please explain

WHAT IS THE ADVANTAGE OF selected value based plot of s d zones?
just we click a bit away the picture changes.
Do you think once a supply demand zone formed,will it change?
Of course the lowerside sd zones will appear as price goes into nearby areas.

....
Mine is not an experts view, but this is how I use it. For important AFLs, I keep two versions, one with last value and one with selected value.

AFL that uses LastValue remains confined only to the right hand end of chart. Perfect and Great when you are using the chart during actual live trade but of no use if you are trying to learn a new strategy or backtest an AFL.

You can use SelectedValue AFL in all the circumstances including live trading Day but the only risk is that if you accidentally click at wrong place and do not correct yourself, you could misread AFL which was otherwise Valid.
 

trash

Well-Known Member
#49
but the only risk is that if you accidentally click at wrong place and do not correct yourself, you could misread AFL which was otherwise Valid.
Update 1.2 with audio/visual alert if SelectedValue is not equal to LastValue.

EDIT: update 1.3, changed blinking text function

Code:
// by trash, vers.1.3

RequestTimedRefresh( 1 );

procedure SayNotTooOften( text, Minperiod )
{   // by Tomasz Janeczko
    elapsed = GetPerformanceCounter() / 1000;
    Lastelapsed = Nz( StaticVarGet( "lastsaytime" ) );

    if ( elapsed - Lastelapsed > Minperiod )
    {
        StaticVarSet( "lastsaytime" , elapsed );
        Say( text );
    }
}

procedure gfxBlinkingMsg( Msg, x1, y1, x2, y2, TextColor, FontSize, FontName )
{
    // originally by Herman van den Bergen, edited by trash 
    global FontName;
    local BlinkState, textcolor, fontSize, msg;

    BlinkState = GetPerformanceCounter() - Nz( StaticVarGet( "~BlinkState" ) );

    if ( BlinkState / 1000 > 2 ) // every two seconds
    {
        StaticVarSet( "~BlinkState", GetPerformanceCounter( 1 ) ) ;
    }
    else
    {
        GfxSetBkMode( 1 );
        GfxSelectFont( FontName, FontSize, 700 );
        GfxSetTextColor( TextColor );
        GfxDrawText( Msg, x1, y1, x2, y2, 37 );
    }
}

SDswitch    = ParamToggle( "Supply/Demand Zones", "OFF|ON", 1 );
SDmode      = ParamList( "Supply/Demand Mode", "Small|Large|Extra Large", 0 );
NumZones    = Param( "Number of Zones", 5, 1, 30, 1 );
Sensitivity = Param( "Sensitivity", 0.4, 0.1, 10, 0.1 );

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

ColorDem    = ParamColor( "Blend Color - Demand Zones", colorBlueGrey );
ColFacDem   = Param( "Blend Color Factor - Demand Zones", 0.45, 0, 2, 0.01 );
ColorSup    = ParamColor( "Blend Color - Supply Zones", colorDarkRed );
ColFacSup   = Param( "Blend Color Factor - Supply Zones", 0.65, 0, 2, 0.01 );
Colorline   = ParamColor( "Color - Zone Borders", colorGrey50 );

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

if ( selectedC != LastValue( C ) )
{
    SayNotTooOften( "Viewing historical Supply Demand zones", 30 );
    pxcw    = Status( "pxchartwidth" );
    x1      = pxcw / 2;
    y1      = pxcw / 2;
    gfxBlinkingMsg( "Currently viewing historical Supply/Demand zones!", x1 - 300, y1, x1 + 300, y1 + 20, colorRed, 12, "Helvetica" );
}


if( SDmode == "Small")
{
    ValSup  = MaxVal;
    ValDem  = MinVal;
}
else if( SDmode == "Large" )
{
    ValSup  = MinVal;
    ValDem  = MaxVal;
}
else
{
    ValSup  = L;
    ValDem  = H;
}

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

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

    y2      = SelectedValue( ValueWhen( H == y1, ValSup ) );
    Line2   = LineArray( x1 + 1, y2, selectedBI, y2, 1 );

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

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

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

    y4      = SelectedValue( ValueWhen( L == y3, ValDem ) );
    Line4   = LineArray( x2 + 1, y4, selectedBI, y4, 1 );

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

    i_1     = 20 * i;
    i_2     = 25 + ( i - 1 ) * 10;
    Rcolor  = ColorBlend( ColorSup, ColorRGB( 180, i_1, i_1 ), ColFacSup ); // ParamColor( "Supply Color", colorBrown  );
    Scolor  = ColorBlend( ColorDem, ColorRGB( i_2, i_2, 80 + i_1 ), ColFacDem ); // 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 );

    }
}
 
Last edited:

casoni

Well-Known Member
#50
Update 1.2 with audio/visual alert if SelectedValue is not equal to LastValue.

// by trash, vers.1.2

Hello trash,

After a long time.., new concept / style of coding , has been posted on this form.

Thank you for improving our knowledge
 

Similar threads