User formula is wrong, was: Chart not showing bars properly

I am unable to see bars for few stocks, all of a sudden. Not sure how to fix this. This is mainly happening with stocks recently listed. I have seen this behavior in two stocks.


Data are fine. The formula that you are using is a problem.
Send the FORMULA.

Please follow this advice: How to ask a good question

The picture that you have sent suggest that you have wrong scaling.

Thanks, it was below section that was causing the problem, i changed the default value to 0 and after that the scaling went away.

_SECTION_BEGIN( "Clean Chart" );

// Create a checkbox parameter to toggle the moving average
ShowMA = ParamToggle("Show MA's", "No|Yes", 1);

// If the checkbox is checked, plot the moving average
if (ShowMA)
{
    Plot( MA( Close, 23 ), "EMA23", ColorRGB( 102, 153, 204 ) );
    Plot( MA( Close, 65 ), "EMA65", ColorRGB( 167, 166, 186 ) );
    Plot( MA( Close, 150 ), "150 DMA", ColorRGB( 218, 165, 32 ) );
}

_SECTION_END();

That is definitely NOT entire formula.
The screenshot you posted contains A LOT MORE things in Title, therefore you must have WAY MORE code in your formula. You have to send WHOLE thing.

Don't play games. If you want help - follow rules: How to ask a good question

The fragment you posted is NOT the root of the problem.

1 Like

Thanks Tomasz, i had no intention of hiding the code or playing games (posting the entire afl). Please tell me what is causing the issue

When i first posted the question, i did not know what caused the problem. You asked to post code, so i started looking for parts that may have caused it and what i had changed recently.

I reverted that part, which fixed the problem and so i posted only the part which fixed the problem for me.

// Chart mimics the marketsmith india settings

_SECTION_BEGIN( "Clean Chart" );

// Create a checkbox parameter to toggle the moving average
ShowMA = ParamToggle("Show MA's", "No|Yes", 0); // Changing default value to 1 has unnessary scaling on recently listed stocks, so keep it to 0

// If the checkbox is checked, plot the moving average
if (ShowMA)
{
    Plot( MA( Close, 23 ), "EMA23", ColorRGB( 102, 153, 204 ) );
    Plot( MA( Close, 65 ), "EMA65", ColorRGB( 167, 166, 186 ) );
    Plot( MA( Close, 150 ), "150 DMA", ColorRGB( 218, 165, 32 ) );
}

_SECTION_END();

_SECTION_BEGIN("ZoomRange");
/// code works for native EOD bars as well as daily bars created out of intraday data
/// @link https://forum.amibroker.com/t/chart-set-timeframe-from-1-1-2018-till-now/10534/2
/// @link https://www.amibroker.com/members/library/formula.php?id=1215
/// sample code by fxshrat@gmail.com

Version(6.20); // minimum AB version being required
zoom_activate = ParamToggle( "Activate Zoom", "OFF|ON", 1 ); // 1 means activated by default
Days= 232 ; // no of days as look back
end_date = ParamDate( "End Date", Now(1), 2);
zoom_trigger = ParamTrigger( "Zoom to Date Range", "CLICK HERE" ); // Zoom is activated only after clicking zoom_trigger

if ( zoom_activate ) {
	//SetBarsRequired( -2, -2 );
	BlankBars 		= 5; // Enter the number of Blank Bars you have defined under Preferences- Charting.
	NumberOfBars	= Days;
	BI 				= BarIndex();
	dt = DateTime();
	BeginBarIndex 	= ValueWhen( LastValue(BarIndex())- BarIndex() > NumberOfBars + BlankBars, BI );
	BeginDateTime 	= dt[LastValue( BeginBarIndex - BI[0] + 2 )];

	start_dt = DateTimeFormat("%Y-%m-%d", BeginDateTime);	
	Lookedup_end_dt = Lookup(dt, end_date, -1);
	end_dt = DateTimeFormat("%Y-%m-%d", Lookedup_end_dt);	
	if ( zoom_trigger ) {		
		AB = CreateObject( "Broker.Application" );
		AW = AB.ActiveWindow;
		AW.ZoomToRange( start_dt, end_dt );
	}
}
_SECTION_END();

_SECTION_BEGIN( "Pocket Pivot Breakout" );
BarSize = ROC(Close, 1) > 0.03;
GreenDay = Close > Open AND (((Close-Open)/Close)*100)>BarSize;
Gappc = 0.005;
Gap = GapUp() AND (Low - Ref(High, -1) ) > Gappc;

// Pivot volume calculation from volume.afl
// Calculating highest down volume day.
LookBack = Param( "LookBack", 10, 9, 15, 1 ); // Look back periods
RedCandle = Close < Open;
GreenCandle = Close > Open;
RedVolume =  IIf( RedCandle, Volume, 0 );
TopRedV = HHV( RedVolume, LookBack );

PPBar = IIf( Volume > TopRedV AND GreenCandle, True, False );

Arrows = PPBar * shapeUpArrow ;
PlotShapes(Arrows, ColorRGB( 255, 255, 255 ),0 ,IIf( GreenCandle, Low, High ));

_SECTION_END();

_SECTION_BEGIN( "Slingshot" );
// Testing slingshot in amibroker
// https://analyzingalpha.com/slingshot-trading-strategy
EMALen = Param( "Slingshot EMA Length", 4, 1, 10 );

//MA line calculation - high of EMALen
EMALine = EMA( High, EMALen );
Slingshot = Cross( Close, EMALine ) AND Ref( Close, -1 ) < Ref( EMALine, -1 ) AND Ref( Close, -2 ) < Ref( EMALine, -2 ) AND Ref( Close, -3 ) < Ref( EMALine, -3 );
BarColor = SetBarFillColor( iif( Slingshot, ColorRGB( 255, 255, 255 ), iif( Close > Open, colorbrightgreen, colorred ) ) );
Plot( C, "Price", IIf( C > O, colorbrightgreen, colorRed ), styleCandle );

_SECTION_END();

_SECTION_BEGIN( "Chart" );
// Pivot calculation
H1 = SelectedValue( TimeFrameGetPrice( "H", inDaily ) );
L1 = SelectedValue( TimeFrameGetPrice( "L", inDaily ) );
C1 = SelectedValue( TimeFrameGetPrice( "C", inDaily ) );

LB = ( H1 + L1 ) / 2;
PP = ( H1 + L1 + C1 ) / 3;
UB = ( PP - LB ) + PP;
S1 = ( 2 * PP ) - H1;
R1 = ( 2 * PP ) - L1;

// Price fall
LookBack = Param( "Fall Lookback", 15, 5, 20, 1 );
//Price = IIf( HHV( High, LookBack ) > HHV( Close, LookBack ), HHV( High, LookBack ), HHV( Close, LookBack ) );
Price = HHV( Close, LookBack );
Fall = ( Price - Close ) / Close * 100;


Plot( MA( Close, 10 ), "SMA10", colorGrey40 );
Plot( MA( Close, 21 ), "SMA21", colorGrey50 );
Plot( MA( Close, 50 ), "SMA50", colorGreen );
Plot( MA( Close, 200 ), "SMA200", colorRed );


/*Plotting Pivot lines*/
//
Plot( UB, "UB", colorBrown, styleLine | styleNoRescale | styleNoRescale, Null, Null, LastValue( BarCount - 1 ) );
Plot( PP, "PP", colorGold, styleLine | styleNoRescale | styleNoRescale, Null, Null, LastValue( BarCount - 1 ) );
Plot( LB, "LB", colorBrown, styleLine | styleNoRescale | styleNoRescale, Null, Null, LastValue( BarCount - 1 ) );
Plot( R1, "R1", colorGreen, styleLine | styleNoRescale, Null, Null, LastValue( BarCount - 1 ) );
Plot( S1, "S1", colorBlueGrey, styleLine | styleNoRescale, Null, Null, LastValue( BarCount - 1 ) );

_SECTION_END();

_SECTION_BEGIN( "High Volume Edges" );
HVECon = Highest( Volume );
HV1Con = HHV( Volume, 252 );

HVE = IIf( Volume >= HVECon , True, False ); // Highest volume ever
//HV1 = IIf( Volume >= HV1Con , True, False ); // Highest volume in one year
HV1 = IIf( Volume >= HV1Con AND HHV( Volume, 252 ) < Highest( Volume ), True, False ); // Highest volume in one year


// Buyable gap ups
Cond1 = GapUp();
Cond2 = Low - Ref( High, -1 ) > 0.75 * ATR( 40 );
Cond3 = Volume > 1.5 * MA( V, 50 );

BuyableGapUp = IIf( Cond1 AND Cond2 AND Cond3, True, False );

PlotHV1 = HV1 * shapeSmallCircle;
PlotHVE = HVE * shapeSmallSquare;
BGU = BuyableGapUp * shapeSmallUpTriangle;
ShapePos = -25;
PlotShapes( PlotHV1, colorBlue, 0, Low, ShapePos );
PlotShapes( PlotHVE, colorBlue, 0, Low, ShapePos - 10 );
PlotShapes( BGU, colorBlue, 0, Low, ShapePos - 20 );
_SECTION_END();


_SECTION_BEGIN( "UpDownRatio" );
VolDays = 30;
RedCandle = Close < Ref( Close, -1 );
RedVolume =  IIf( RedCandle, Volume, 0 );
GreenCandle = Close > Ref( Close, -1 );
GreenVolume =  IIf( GreenCandle, Volume, 0 );
RedVolSum = Sum( RedVolume, VolDays );
GreenVolSum = Sum( GreenVolume, VolDays );

UpDownRatio = GreenVolSum / RedVolSum;
_SECTION_END();

_SECTION_BEGIN( "TrailStop" );
AtrDays = 10;
// ATRVal = ATR(AtrDays);
TrailStop = MA( Close, 21 ) - ATR( AtrDays );
_SECTION_END();



// Calling RS ranking generated from IBD_RS_Ranking.afl
function GetRS( Symbol )
{
    // Retrieve relative strength static var
    return StaticVarGet( "RS_" +  Symbol );
}

// Setting chart title
Title = Name() + "  -   " +
        Date() + ", " +
        "Open = " + Prec( Open, 2 ) + ", " +
        "High = " +  Prec( High, 2 ) + ", " +
        "Low = " +  Prec( Low, 2 ) + ", " +
        "Close = " + Prec( Close, 2 ) +
        " (" + Prec( ROC( Close, 1 ), 2 ) + "%)"  +
        "Volume = " +  NumToStr( Volume, 10.2, True, True ) + ", " +
        EncodeColor( ColorRGB( 211, 211, 211 ) ) + "10 SMA = " +  EncodeColor( colorWhite ) + NumToStr( MA( Close, 10 ), 5.2, True, False ) + ", " +
        EncodeColor( ColorRGB( 169, 169, 169 ) ) + "21 SMA = " +  EncodeColor( colorWhite ) + NumToStr( MA( Close, 21 ), 5.2, True, False ) + ", " +
        EncodeColor( ColorRGB( 102, 153, 204 ) ) + "23 EMA = " +  EncodeColor( colorWhite ) + NumToStr( MA( Close, 23 ), 5.2, True, False ) + ", " +
        EncodeColor( colorGreen ) + "50 SMA = " +  EncodeColor( colorWhite ) + NumToStr( MA( Close, 50 ), 5.2, True, False ) + ", " +
        EncodeColor( ColorRGB( 167, 166, 186 ) ) + "65 EMA = " +  EncodeColor( colorWhite ) + NumToStr( EMA( Close, 65 ), 5.2, True, False ) + ", " +
        EncodeColor( colorWhite ) + "Fall = " +  EncodeColor( colorRed ) + NumToStr( Fall, 5.2, True, False ) + "%" + ", " +
        EncodeColor( colorWhite ) + "TrailStop = " +  EncodeColor( colorRed ) + NumToStr( TrailStop, 5.2, True, False ) +  ", " +
        EncodeColor( colorWhite ) + "Rel Str = " +  EncodeColor( colorYellow ) + Prec( GetRS( Name() ), 0 ) + ", " +
        EncodeColor( colorWhite ) + "UDR = " +  EncodeColor( colorOrange ) + Prec( UpDownRatio, 2 ) + ", " +
        EncodeColor( colorWhite ) + "DCR = " +  EncodeColor( colorAqua ) + Prec( ( Close - Low ) / ( High - Low ), 2 ) + ", " +
        EncodeColor( colorWhite ) + "McapRank = " +  EncodeColor( ColorRGB( 255, 127, 82 ) )  + GetFnData( "Alias" ) // Mcap rank is stored in alias
        ;

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.