supply demand formula from NINJACATOR

COJ

New Member
#61
Hello All,

I just joined this forum seeing this thread. Excellent team work. :clapping:

Thanks to all :thumb:

I am very much interested in supply-demand based trading. I will try to learn as much as possible from here.

Though I have a technical background I am not a programmer, so please bear with me if I ask any apparently not so wise question :p

Thanks to all again :cheers:
 

COJ

New Member
#62
What about using the AFL in daily time-frame for Supply/Demand of Day, Week and Month?

I was experimenting changing the time-frame but got confused about the proper way.

Should I use TimeFrameGetPrice ? It works only with base of seconds so I have to calculate and proceed accordingly.

or

Can I use inDaily, inWeekly etc. as parameters ? and how ?

Thanks :)
 

trash

Well-Known Member
#63
What about using the AFL in daily time-frame for Supply/Demand of Day, Week and Month?

I was experimenting changing the time-frame but got confused about the proper way.

Should I use TimeFrameGetPrice ? It works only with base of seconds so I have to calculate and proceed accordingly.

or

Can I use inDaily, inWeekly etc. as parameters ? and how ?

Thanks :)
As it is written in the description of version 1.4 the MTF range is defined in between 1 min and 1 day. So EOD is not implemented in 1.4 but only intra-day as it is just an example. And the input parameter clearly mentions minutes within braces.

And TimeFrameGetPrice works with any TF and it is already included in vers 1.4. You just have to change the range. You have to define it. So I don't know what you mean by "base of seconds only".


This is my very last AFL in regards to this topic. I won't do any more.

Version 1.5


- added MTF support for EOD TFs


Code:
// by trash, vers.1.5

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 )
    {
        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 );
MTFswitch   = ParamList( "Multi TF Support", "OFF|Intra-day|EOD", 0 );
intratmfrm  = Param( "Input Intra-day TF of S/D Zones (minutes)", 60, 1, 1440, 1 ) * 60;
EODmode     = ParamList( "Choose EOD TF of S/D Zones", "Daily|Weekly|Monthly", 0 );
SDmode      = ParamList( "Supply/Demand Mode", "Small|Large|Extra Large", 0 );
Sensitivity = Param( "Sensitivity (%)", 0.4, 0.1, 10, 0.1 );
NumZones    = Param( "Number of S/D Zones", 10, 2, 60, 2 ) / 2;

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.65, 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 );


switch( EODmode )
{
    case "Weekly":  eodtmfrm = inWeekly;  break;
    case "Monthly": eodtmfrm = inMonthly; break;
    default:        eodtmfrm = inDaily;   break;
}

expandmode  = expandFirst;
shift       = 0;

switch ( MTFswitch )
{
    case "Intra-day":
    Close_  = TimeFrameGetPrice( "C", intratmfrm, shift, expandmode );
    Open_   = TimeFrameGetPrice( "O", intratmfrm, shift, expandmode );
    High_   = TimeFrameGetPrice( "H", intratmfrm, shift, expandmode );
    Low_    = TimeFrameGetPrice( "L", intratmfrm, shift, expandmode );
    break;

    case "EOD":
    Close_  = TimeFrameGetPrice( "C", eodtmfrm, shift, expandmode );
    Open_   = TimeFrameGetPrice( "O", eodtmfrm, shift, expandmode );
    High_   = TimeFrameGetPrice( "H", eodtmfrm, shift, expandmode );
    Low_    = TimeFrameGetPrice( "L", eodtmfrm, shift, expandmode );
    break;

    default:
    Close_  = C;
    Open_   = O;
    High_   = H;
    Low_    = L;
    break;
}


bi          = BarIndex();
selectedBI  = SelectedValue( bi );
selectedC   = SelectedValue( Close_ );
MinVal      = Min( Open_, Close_ );
MaxVal      = Max( Open_, Close_ );


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


switch( SDmode )
{
    case "Large":
    ValSup  = MinVal;
    ValDem  = MaxVal;
    break;

    case "Extra Large":
    ValSup  = Low_;
    ValDem  = High_;
    break;

    default:
    ValSup  = MaxVal;
    ValDem  = MinVal;
    break;
}


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

    y1      = SelectedValue( Peak( High_, Sensitivity, i ) );
    y2      = ValueWhen( bi == x1, High_ - Valsup );

    Line1   = LineArray( x1 + 1, y1, selectedBI, y1, 1 );
    Line2   = Line1 - y2;

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

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

    y3      = SelectedValue( Trough( Low_, Sensitivity, i ) );
    y4      = ValueWhen( bi == x2, ValDem - Low_ );

    Line3   = LineArray( x2 + 1, y3, selectedBI, y3, 1 );
    Line4   = Line3 + y4;

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

    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 > Line1, Scolor_, Rcolor_ );
    SColor  = IIf( selectedC > Line4, Scolor_, Rcolor_ );

    if ( SDSwitch )
    {
        zorder  = -i - 9;
        zorder2 = zorder + 1;

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

        PlotOHLC( Line3, Line3, Line4, Line4, "", Scolor, style1, 0, 1, 0, zorder );
        Plot( Line3, "", Colorline, style2, 0, 1, 0, zorder2 );
        Plot( Line4, "", Colorline, style2, 0, 1, 0, zorder2 );
    }
}
 
Last edited:

COJ

New Member
#64
As it is written in the description of version 1.4 the MTF range is defined in between 1 min and 1 day. So EOD is not implemented in 1.4 but only intra-day as it is just an example. And the input parameter clearly mentions minutes within braces.


sorry trash ... probably I was not clear enough :(

actually I was not trying to use the AFL on EOD charts .. I was trying to make necessary changes to it so that it can be used in EOD



And TimeFrameGetPrice works with any TF and it is already included in vers 1.4. You just have to change the range. You have to define it. So I don't know what you mean by "base of seconds only".

I was referring to the SYNTAX of TimeFrameGetPrice wherein "Interval" is bar interval in seconds only. So my query was whether I should calculate seconds for week, month etc or is there any other way to accomplish that ?

Being a layman I was trying to do the same using the "Param" instead of "ParamList" :mad:








for your excellent coding ability and for being so generous to us

Thanks a lot again
 

trash

Well-Known Member
#65
sorry trash ... probably I was not clear enough :(

actually I was not trying to use the AFL on EOD charts .. I was trying to make necessary changes to it so that it can be used in EOD
Your sentence is not clear as it can be understood this way or that way.

All versions 1.0 to 1.5 can be used in EOD or intraday!
The difference in 1.4 to prior ones is that it additionally includes viewing zones of higher intraday timeframe on lower set intraday chart timeframe i.e. zones of hourly timeframe viewed on 5 minute chart timeframe etc. Version 1.5 now includes viewing zones of daily/weekly/monthly timeframe on daily base timeframe (or intraday timeframe). And in version 1.4 and 1.5 higher TF support on lower TF can be turned off.


I was referring to the SYNTAX of TimeFrameGetPrice wherein "Interval" is bar interval in seconds only. So my query was whether I should calculate seconds for week, month etc or is there any other way to accomplish that ?

Being a layman I was trying to do the same using the "Param" instead of "ParamList" :mad:
Yes, you can use seconds values or use keywords like in1Minute or inDaily etc. 86400 (seconds) is equal to inDaily. As for daily and higher TF I use keywords as it is simpler than inputting high minute (or second) number.

As for seconds .. the AB help file already answers all your questions in regards to what's the seconds.

in1Minute = 60
in5Minute = 5 * 60
in15Minute = 15 * 60
inHourly = 3600
inDaily = 24 * 3600
inWeekly = 5 * 24 * 3600 + 1 = 432001
inMonthly = 25 * 24 * 3600 + 1 = 2160001
inQuarterly (new in 5.20)
inYearly (new in 5.20)


As for viewing daily/weekly/monthly on lower TF ... just look at version 1.5. It's already all there! What else do you wanna change/add? Just set to EOD and then choose daily, weekly or monthly. Why over-complicating it? And if set to EOD then it can be viewed on set intra-day chart time frame also!
 

COJ

New Member
#66
Your sentence is not clear as it can be understood this way or that way.

All versions 1.0 to 1.5 can be used in EOD or intraday!
The difference in 1.4 to prior ones is that it additionally includes viewing zones of higher intraday timeframe on lower set intraday chart timeframe i.e. zones of hourly timeframe viewed on 5 minute chart timeframe etc. Version 1.5 now includes viewing zones of daily/weekly/monthly timeframe on daily base timeframe (or intraday timeframe). And in version 1.4 and 1.5 higher TF support on lower TF can be turned off.

With reference to my earlier post,

What about using the AFL in daily time-frame for Supply/Demand of Day, Week and Month?
all that I wanted was to use the AFL (version 1.4) on daily time frame with multi time frame support for viewing weekly, monthly S/D zones.



As for viewing daily/weekly/monthly on lower TF ... just look at version 1.5. It's already all there! What else do you wanna change/add? Just set to EOD and then choose daily, weekly or monthly. Why over-complicating it? And if set to EOD then it can be viewed on set intra-day chart time frame also!

I don't want to change or over complicate anything of version 1.5.

It was all about version 1.4 :p
 

mastermind007

Well-Known Member
#67
Last edited:

amitrandive

Well-Known Member
#70
Please help me understand how to trade the demand supply zones in the thread


My questions are
1)How to take a trade using this AFL?
2) After how many bars does the demand/supply zone appears ?
3)After how many bars does the demand/supply zone zone change colour from red to blue or vice-versa ?

Thanks for help

Amit
 

Similar threads