Simple Coding Help - No Promise.

Hope this helps:
C-like:
_SECTION_BEGIN( "Highest/Lowest Close in Daily" );
     if( Interval( 0 ) < inDaily )
     {
         HighestC = Null;
         LowestC = Null;
         fvb = Status( "FirstVisibleBar" );
         lvb = Min( Status( "LastVisibleBar" ), BarCount - 1 );    
         NewDay = Day() != Ref( Day(), -1 );
       
         //for( i = 1; i <= BarCount - 1; i++ )
         for( i = fvb; i < lvb; i++ ) // If using as an Indicator, otherwise, if want to explore, then use for-loop for all bars i.e. i = 1; i <= BarCount - 1; i++
         {
             HighestC[ i ] = HighestC[ i - 1 ];
             LowestC[ i ] = LowestC[ i - 1 ];
             if( NewDay[ i ] )
             {
                 HighC = C[ i ];
                 LowC = C[ i ];
                 j = i + 1;
                 while( NOT NewDay[ j ] AND j < BarCount - 1 )
                 {
                     if( C[ j ] > HighC ) HighC = C[ j ];
                     if( C[ j ] < LowC ) LowC = C[ j ];
                     j++;
                 }            
                 HighestC[ i ] = LastValue( HighC );
                 LowestC[ i ] = LastValue( LowC );
             }
         }
   
         Plot( C, "", colorWhite, styleCandle );
       
         HighestC = IIf( NOT NewDay, HighestC, Null );
         Plot( HighestC, "", colorGreen );
         Plot( HighestC, "", colorGreen, styleLine, Null, Null, -1 );
         Plot( HighestC, "", colorGreen, styleLine, Null, Null, 1 );    
       
         LowestC = IIf( NOT NewDay, LowestC, Null );
         Plot( LowestC, "", colorBrown );
         Plot( LowestC, "", colorBrown, styleLine, Null, Null, -1 );
         Plot( LowestC, "", colorBrown, styleLine, Null, Null, 1 );    
     }
     else
     {
         Title = "";
         GfxSetCoordsMode( 0 );
         SetChartBkColor( colorRose );
         Text = "Set the time-frame less than Daily";
         x = Status( "PxChartWidth" ) / 2 - GfxGetTextWidth( Text );
         y = Status( "PxChartHeight" ) / 2;    
         GfxSetBkColor( colorRose );
         GfxSelectFont( "Courier New", 20, 700 );
         GfxTextOut( Text, x, y );
     }
_SECTION_END();
//Coded by @Loss_Lover for https://www.traderji.com/community/threads/simple-coding-help-no-promise.90119/post-1347633
 
Last edited:
How can I check if the current candle's volume is greater than moving average of last 20 candles volume or not ?
I need to check it by looping and not by array form.
Please help me.

I tried to use this code but it is giving an error. This is just portion of the code and its giving error in IF condition

for(i = 1;i < BarCount; i++)
{
if(Volume > 3* ma(volume,20)

I am not getting any errors if I check this code for errors. But when I scan the code for finding real stocks I am getting error that - condition in IF statement has to be numeric or Boolean type. You can not use array here.

After this error, just to check I changed the code to if(Volume > 100000) and then its working perfectly fine.
Kindly assist me what changes I need to make if I want to find candles which has volume greater than 3 times of moving average of of last 20 candles volume.
Hope this helps:
C-like:
// It is ideal to use a separate pane to display Volume; this is for demonstration only
// Arrays are several times faster than Looping (https://www.amibroker.com/guide/h_understandafl.html)
// Looping must be avoided if not deadly needed by the strategy
_SECTION_BEGIN( "Identifying Bars where Vol is greater than its 20 S.M.A." );
     SetChartOptions( 0, chartShowDates | chartShowArrows );
   
     AvgPer = Param( "Volume Average Period", 20, 1, 100, 1 );
     VolSubPaneHgtPrcnt = Param( "Percentage of Vol sub-pane height", 25, 1, 100, 1 );
     VolSubPaneMin = LowestVisibleValue( V );
     VolSubPaneMax =  HighestVisibleValue( V ) * 100 / VolSubPaneHgtPrcnt;
   
     // Using Array form
     //AvgVol = MA( V, AvgPer );
   
     // Using Loop
     _SumVol = 0;
     for( i = 0; i < BarCount; i++ )
     {
         _SumVol += V[ i ];
         if( i >= AvgPer ) _SumVol -= V[ i - AvgPer ];
         if( i >= AvgPer - 1 ) SumVol[ i ] = _SumVol;
     }    
     AvgVol = SumVol / AvgPer;    
   
     Plot( C, "Close", colorDefault, styleBar | styleThick );
     Plot( V, "Volume", colorGrey50, styleHistogram | styleOwnScale | styleNoLabel, VolSubPaneMin, VolSubPaneMax, 0, 0, 2 );
     Plot( AvgVol, "Avg. Vol", colorLightOrange, styleLine | styleOwnScale | styleNoLabel, VolSubPaneMin, VolSubPaneMax, 0, 0, 2 );
   
     PlotShapes( IIf( V >= AvgVol, shapeSmallCircle, shapeNone ), colorSkyblue, 0, Status( "AxisMinY" ) );
_SECTION_END();
// Coded by @Loss_Lover for https://www.traderji.com/community/threads/simple-coding-help-no-promise.90119/post-1348633
Edited (reason forgot to mention earlier): The looping technique was generously shared by a Genius Programmer - https://forum.amibroker.com/t/looping-in-amibroker/2334/8.
 
Last edited:
Any 1 have AnchoredVWAP coding PLS MAKE AFL

study("Anchored VWAP",overlay=true)
Year = input(2017, minval = 1, maxval = 2099, type=integer, title='Year')
Month = input(10, minval = 1, maxval = 12, type=integer, title='Month')
Day = input(10, minval = 1, maxval = 31, type=integer, title='Day')
Hour = input(12, minval = 0, maxval = 23, type=integer, title='Hour')
Minute = input(0, minval = 0, maxval = 59, type=integer, title='Minute')
DebugMode = input(false, type=bool, title='Debug Mode')
start = security(tickerid, '1', time)
impulse_func = iff(timestamp(Year,Month,Day,Hour,Minute) == time, 1, 0)
newSession = iff(change(start), 1, 0)
startSession = newSession * impulse_func
vwapsum = iff(startSession, ohlc4*volume, vwapsum[1]+ohlc4*volume)
volumesum = iff(startSession, volume, volumesum[1]+volume)
myvwap = vwapsum/volumesum
plot(myvwap, linewidth=3, transp=0, title='AVWAP')
plot(DebugMode ? hour : na)
plot(DebugMode ? minute : na)




https://www.tradingview.com/script/...E0OEZvvNYit1zwVY2HOIhjo9lAwc9wpwzAzOBDIiggnFE
Hope this helps:
C-like:
_SECTION_BEGIN( "VWAP" );
     SetChartOptions( 0, chartShowDates );
     DispTyp = ParamToggle( "VWAP Display Type", "Anchored|Moving", 0 );

     Price = ( H + L ) / 2;     
    
     if( DispTyp )
     {
         Value = Volume * Price;
         NewDay = Day() != Ref( Day(), -1 );
         BarsFromTodayBegin = 1 + BarsSince( NewDay );     
    
         TotalValue = Sum( Value, BarsFromTodayBegin );
         TotalVolume = Sum( V, BarsFromTodayBegin );
         VWAP = TotalValue / TotalVolume;
    
         Plot( IIf( NOT NewDay, VWAP, Null ), "VWAP", colorLightOrange, styleStaircase | styleThick, Null, Null, 0, 0 );
     }
     else
     {
         bi = BarIndex();
         BiBegin = BeginValue( bi ); // First Double-click on any bar (https://www.amibroker.com/guide/afl/beginvalue.html)
         BiEnd = EndValue( bi );      // Second Double-click on any bar after the first selecteed bar (https://www.amibroker.com/guide/afl/endvalue.html)
        
         fvb = Status( "FirstVisibleBar" );
         lvb = Min( Status( "LastVisibleBar" ), BarCount - 1 );
        
         if( BiBegin != 0 AND BiEnd != BarCount - 1 AND BiBegin >= fvb AND BiEnd <= lvb )
         {
             ValInRang = IIf( BiBegin <= bi AND bi <= BiEnd, V * Price, Null );
             TotalValue = Cum( ValInRang );
        
             VolInRng = IIf( BiBegin <= bi AND bi <= BiEnd, V, Null );
             TotalVol = Cum( VolInRng );
        
             AVWAP = TotalValue / TotalVol;
        
             Plot( IIf( BiBegin <= bi AND bi <= BiEnd, AVWAP, Null ), "AVWAP", colorLightOrange, styleStaircase | styleThick, Null, Null, 0, 0 );
         }
        
         RequestMouseMoveRefresh();
     }
    
     Plot( C, "C", colorDefault, styleBar, Null, Null, 0, 0, 2 );
_SECTION_END();
// Coded by @Loss_Lover for https://www.traderji.com/community/threads/simple-coding-help-no-promise.90119/post-1348117
 

RadhuK

Well-Known Member
sir i want to use it as a indicator...pl edit afl for it...im getting syntax errors when i try to edit.
Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1));
StartBar = ValueWhen(TimeNum() == 091500, BarIndex());
TodayVolume = Sum(V,Bars_so_far_today);
IIf (BarIndex() >= StartBar, VWAP = Sum (C * V, Bars_so_far_today ) / TodayVolume,0);
SmoothVWAP = ema(VWAP,20) ;
Plot(SmoothVWAP,"VWAP", coloryellow, stylethick);
 
sir i want to use it as a indicator...pl edit afl for it...im getting syntax errors when i try to edit.
No sir please!

Are you referring to post # 5851? If yes, which AB version you are on? Share the error message for me to understand the kind of error you are facing.

P.S. I am on latest 6.30 without any error, the code should work fine 6.0 and above!

Edit: Try this -
C-like:
_SECTION_BEGIN( "Highest/Lowest Close in Daily" );
     if( Interval( 0 ) < inDaily )
     {
         HighestC = Null;
         LowestC = Null;
         fvb = Status( "FirstVisibleBar" );
         lvb = Min( Status( "LastVisibleBar" ), BarCount - 1 );   
         NewDay = Day() != Ref( Day(), -1 );
      
         //for( i = fvb; i < lvb; i++ ) // If using as an Indicator, otherwise, if want to explore, then use for-loop for all bars i.e. i = 1; i <= BarCount - 1; i++
         for( i = 1; i <= BarCount - 1; i++ )
         {
             HighestC[ i ] = HighestC[ i - 1 ];
             LowestC[ i ] = LowestC[ i - 1 ];
             if( NewDay[ i ] )
             {
                 HighC = C[ i ];
                 LowC = C[ i ];
                 j = i + 1;
                 while( NOT NewDay[ j ] AND j < BarCount - 1 )
                 {
                     if( C[ j ] > HighC ) HighC = C[ j ];
                     if( C[ j ] < LowC ) LowC = C[ j ];
                     j++;
                 }           
                 HighestC[ i ] = LastValue( HighC );
                 LowestC[ i ] = LastValue( LowC );
             }
         }
  
         Plot( C, "", colorWhite, styleCandle );
      
         HighestC = IIf( NOT NewDay, HighestC, Null );
         Plot( HighestC, "", colorGreen, styleNoLabel );
         Plot( HighestC, "", colorGreen, styleLine | styleNoLabel, Null, Null, -1 );
         Plot( HighestC, "", colorGreen, styleLine | styleNoLabel, Null, Null, 1 );   
      
         LowestC = IIf( NOT NewDay, LowestC, Null );
         Plot( LowestC, "", colorBrown, styleNoLabel );
         Plot( LowestC, "", colorBrown, styleLine | styleNoLabel, Null, Null, -1 );
         Plot( LowestC, "", colorBrown, styleLine | styleNoLabel, Null, Null, 1 );   
     }
     else
     {
         Title = "";
         GfxSetCoordsMode( 0 );
         SetChartBkColor( colorRose );
         Text = "Set the time-frame less than Daily";
         x = Status( "PxChartWidth" ) / 2 - GfxGetTextWidth( Text );
         y = Status( "PxChartHeight" ) / 2;   
         GfxSetBkColor( colorRose );
         GfxSelectFont( "Courier New", 20, 700 );
         GfxTextOut( Text, x, y );
     }
_SECTION_END();
//Coded by @Loss_Lover for https://www.traderji.com/community/threads/simple-coding-help-no-promise.90119/post-1347633
 
Last edited:

Similar threads