Simple Coding Help - No Promise.

Shantala

Well-Known Member
Looking for dynamic median line with period = number of bars from day beginning as shown in below chart. It should plot median line from first bar of day. If there are 10 bars from day beginning, period should be 10 and so on. At the end of day, we will get 75 bars on 5-min chart, so median line with 75 period. For 3 min, with 125 period.





Tried in following formula by CyberMan, but not successful. Help appreciated.

P = ParamField("Price field",-1);
Daysback = ????????????????;
shift = Param("Look back period",0,0,240,1);

//=============================== Math Formula ========================================================================================================

x = Cum(1);
lastx = LastValue( x ) - shift;
aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) );
bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) );
y = Aa + bb * ( x - (Lastx - DaysBack +1 ) );

//==================Plot the Linear Regression Line ====================================================================================================

LRColor = ParamColor("LR Color", colorCycle );
LRStyle = ParamStyle("LR Style");

LRLine = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );

LRStyle = ParamStyle("LR Style");
Angle = Param("Angle", 0.05, 0, 1.5, 0.01);// A slope higher than 0.05 radians will turn green, less than -0.05 will turn red and anything in between will be white.

LRLine = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );

Pi = 3.14159265 * atan(1); // Pi
SlopeAngle = atan(bb)*(180/Pi);

LineUp = SlopeAngle > Angle;
LineDn = SlopeAngle < - Angle;

if(LineUp)
{
Plot(LRLine, "Lin. Reg. Line Up", IIf(LineUp, colorBrightGreen, colorRed), LRStyle);
}
else
{
Plot(LRLine, "Lin. Reg. Line Down", IIf(LineDn, colorDarkRed, colorRed), LRStyle);
}
 
I found this market profile afl code from a russian site. and I got error message, can somebody fix it.

thanks in advance.


SetChartOptions(3, chartShowDates);
GfxSetOverlayMode( mode = 1 );

nn = StrToNum(ParamList("Days", "1|2|3", 1));
box = Param("step", 10, 1, 100, 1)*TickSize;

NewDay = Day()!= Ref(Day(), -1);
DH = LastValue(HighestSince(NewDay, H, nn));
DL = LastValue(LowestSince(NewDay, L, nn));
Range = DH - DL;
steps = ceil(Range/box); // linage
height = Status("pxheight") - 50; // width of the profile (indention overhand 30 from below 20 pixels)
boxheight = LastValue(height/steps); // size of the box

width = (Status("pxwidth")-110)/3; // offset of the profiles

bars = Highest(BarsSince(NewDay));
ColorStep = LastValue(185/bars);

// ��������� ������������� ����
L = IIf(C > Ref(C, -1) AND L > Ref(C, - 1) AND NOT NewDay, Ref(C, -1), L);
H = IIf(C < Ref(C, -1) AND H < Ref(C, - 1) AND NOT NewDay, Ref(C, -1), H);

function GetDayPrice( fild, shift)
{
DayPrice = LastValue(TimeFrameGetPrice(fild, inDaily, -shift));
return DayPrice;
}

function pixlev(price)
{
result = 30 + (DH - price)/box * boxheight;
return result;
}

procedure PlotProfile(DH, DL, begini, endi, disp)
{
m = 0;
for(j = DH; j > DL; j = j-box)
{
n = 0;
for(i = begini; i < endi; i++)
{
if(H >= j AND L <= j)
{
GfxSelectPen( colorBlack, 1, 0);
GfxSelectSolidBrush(ColorHSB((i-begini)*ColorStep, 255, 255));
GfxRectangle( disp+n*boxheight, 30+m*boxheight, disp+(n+1)*boxheight, 30+(m+1)*boxheight);
n++;
}
}
m++;
}
}

procedure PlotLine(x1, y1, x2, y2, Color)
{
GfxSelectPen(Color, 1, 0);
GfxPolyline( x1, y1, x2, y2);
}

procedure PlotRect(x1, y1, x2, y2, Color)
{
GfxSelectPen(Color, 0, 5);
GfxSelectSolidBrush(Color);
GfxRectangle(x1, y1, x2, y2);
}

procedure PlotPrice(Text, FontName, FontSize, Color, x, y, yAlign, xAlign)
{
GfxSetBkMode(1);
GfxSetTextColor(Color);
GfxSetTextAlign( xAlign|yAlign);
GfxSelectFont(FontName, FontSize, 600); // dont work orientation
GfxTextOut(Text, x, y);
}

for(q = nn; q > 0; q--)
{
begini = LastValue(ValueWhen(NewDay, BarIndex(), q));
endi = LastValue(IIf(q == 1, BarCount, ValueWhen(NewDay, BarIndex(), q-1)));
PlotRect(50 + width*(nn-q), pixlev(GetDayPrice("H", q-1)), // day range
50 + width*(nn-q+1), pixlev(GetDayPrice("L", q-1)), colorLightYellow);
PlotRect(50 + width*(nn-q), pixlev(GetDayPrice("O", q-1)), // open-close range
50 + width*(nn-q+1), pixlev(GetDayPrice("C", q-1)),
IIf(GetDayPrice("O", q-1) > GetDayPrice("C", q-1), ColorHSB(15, 40, 255),
ColorHSB(80, 40, 255)));
PlotLine(50 + width*(nn-q), pixlev(GetDayPrice("C", q-1)), // close line
50 + width*(nn-q+1), pixlev(GetDayPrice("C", q-1)),
IIf( GetDayPrice("O", q-1) > GetDayPrice("C", q-1), colorRed, colorGreen));
PlotProfile(DH, DL, begini, endi, 50 + width*(nn-q));
PlotLine(50 + width*(nn-q), height+40, 50 + width*(nn-q), 0, colorBlack); // vertical line
PlotPrice( " close " + NumToStr(GetDayPrice("C", q-1))+" ", "Tahoma", 10, // plot close price
IIf( GetDayPrice("O", q-1) > GetDayPrice("C", q-1), colorRed, colorGreen),
50+width*(nn-q+1), pixlev(GetDayPrice("C", q-1)),
IIf( GetDayPrice("O", q-1) > GetDayPrice("C", q-1), 0, 8), 2);
PlotPrice( " open " + NumToStr(GetDayPrice("O", q-1))+" ", "Tahoma", 10, // plot open price
colorBlack, 50+width*(nn-q+1), pixlev(GetDayPrice("O", q-1)),
IIf( GetDayPrice("O", q-1) > GetDayPrice("C", q-1), 8, 0), 2);
PlotPrice( " "+NumToStr(GetDayPrice("H", q-1)), "Tahoma", 10, // plot high price
colorBlack, 50+width*(nn-q), pixlev(GetDayPrice("H", q-1)), 8, 0);
PlotPrice(" "+NumToStr(GetDayPrice("L", q-1)), "Tahoma", 10, // plot low price
colorBlack, 50+width*(nn-q), pixlev(GetDayPrice("L", q-1)), 0, 0);
}
Title = Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
 

amitrandive

Well-Known Member
I found this market profile afl code from a russian site. and I got error message, can somebody fix it.

thanks in advance.


SetChartOptions(3, chartShowDates);
GfxSetOverlayMode( mode = 1 );
.
.
.
Title = Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
Mplite works for Ami version 5.8.
Please use # tags for pasting codes
http://www.traderji.com/amibroker/94616-new-amibroker.html#post988446
 
Please try setting the following registry and try on your old version and see:
[HKEY_CURRENT_USER\Software\Microsoft\mwor]"mwor"=dword:00000001


My version 5.80 did show plugin and NiftyPro4point2P() in blue, but throw exception.
cudnt get you how to impement the changes.and will chart appear after the changes. ? i have ami 5.7
 

KelvinHand

Well-Known Member
cudnt get you how to impement the changes.and will chart appear after the changes. ? i have ami 5.7
Use RegEdit and go and search for HKEY_CURRENT_USER\Software\Microsoft\
Create "mwor" folder, then Create mwor var. and set the value to 1.
Note: If you don't know, then google the know how, i don't want waste time for all these.


This is just only 1 small step for you to see whether there is a big change in your side.

Don't ask that kind of silly question, expect me to give you a confirm answer.

I already tell you that, my side got exception issue, I got no idea what happening in the DLL not working, but to see any of your can work.

This kind of exception probably due to old/new amibroker, old compiler caused exception in new amibroker ....etc.


Beside above, the plugin also contain Candle code inside, so if conflict with CdBullishEngulfing(), ... etc. then remove the Candle.dll plugin.
 
Last edited:

augubhai

Well-Known Member
Looking for dynamic median line with period = number of bars from day beginning as shown in below chart. It should plot median line from first bar of day. If there are 10 bars from day beginning, period should be 10 and so on. At the end of day, we will get 75 bars on 5-min chart, so median line with 75 period. For 3 min, with 125 period.





Tried in following formula by CyberMan, but not successful. Help appreciated.

P = ParamField("Price field",-1);
Daysback = ????????????????;
shift = Param("Look back period",0,0,240,1);

//=============================== Math Formula ========================================================================================================

x = Cum(1);
lastx = LastValue( x ) - shift;
aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) );
bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) );
y = Aa + bb * ( x - (Lastx - DaysBack +1 ) );

//==================Plot the Linear Regression Line ====================================================================================================

LRColor = ParamColor("LR Color", colorCycle );
LRStyle = ParamStyle("LR Style");

LRLine = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );

LRStyle = ParamStyle("LR Style");
Angle = Param("Angle", 0.05, 0, 1.5, 0.01);// A slope higher than 0.05 radians will turn green, less than -0.05 will turn red and anything in between will be white.

LRLine = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null );

Pi = 3.14159265 * atan(1); // Pi
SlopeAngle = atan(bb)*(180/Pi);

LineUp = SlopeAngle > Angle;
LineDn = SlopeAngle < - Angle;

if(LineUp)
{
Plot(LRLine, "Lin. Reg. Line Up", IIf(LineUp, colorBrightGreen, colorRed), LRStyle);
}
else
{
Plot(LRLine, "Lin. Reg. Line Down", IIf(LineDn, colorDarkRed, colorRed), LRStyle);
}
Try this... I modified the code from http://www.traderji.com/amibroker/78585-custom-study-indicator-augu-lines.html

Color = ParamColor("Color",colorRed);
x = BarIndex()+1;
startx = ValueWhen(Day()!=Ref(Day(),-1), x);
endx = LastValue(x);
Periods = LastValue(endx - startx + 1);
intercept = LastValue(ValueWhen(x==endx, LinRegIntercept(C, Periods)));
slope = LastValue(ValueWhen(x==endx, LinRegSlope(C, Periods)));
y = intercept + slope * ( x - (endx - Periods + 1 ) );

RL = IIf( x > (endx - Periods) AND x <= endx, y , Null );
Plot(RL, "", Color);
 

Shantala

Well-Known Member
Try this... I modified the code from http://www.traderji.com/amibroker/78585-custom-study-indicator-augu-lines.html

Color = ParamColor("Color",colorRed);
x = BarIndex()+1;
startx = ValueWhen(Day()!=Ref(Day(),-1), x);
endx = LastValue(x);
Periods = LastValue(endx - startx + 1);
intercept = LastValue(ValueWhen(x==endx, LinRegIntercept(C, Periods)));
slope = LastValue(ValueWhen(x==endx, LinRegSlope(C, Periods)));
y = intercept + slope * ( x - (endx - Periods + 1 ) );

RL = IIf( x > (endx - Periods) AND x <= endx, y , Null );
Plot(RL, "", Color);

Thanks, this is what I was looking for.:thumb:
 
Hello All,

I currently use following formula to export data from Amibroker in .txt format to feed it in another charting software,
A text file is created for each symbol in specified folder.
For Example if I want to export hourly data of all symbols, all I need to do is load the Afl in Automatic Analysis window in setting set timeframe to hourly then click OK and than run a scan.

I wanted to know if we could write it in a way to get 2 time frame data in 2 separate folders, Example currently it only exports hourly format, is it possible to get hourly as well as 15 min data exported in 2 separate folder?

I tried making changes, but no success.

[/code]

fh = fopen( "c:\\SaveData\\Hourly\\"+Name()+".txt", "w");
if( fh )
{

fputs( "Ticker,Date,Time,Open,High,Low,Close,Volume \n", fh );
y = Year();
m = Month();
d = Day();
r = Hour();
e = Minute();
n = Second();

for( i = 0; i < BarCount; i++ )
{
fputs( Name() + "," , fh );
ds = StrFormat("%02.0f/%02.0f/%02.0f,",
y[ i ], m[ i ], d[ i ] );
fputs( ds, fh );

ts = StrFormat("%02.0f:%02.0f:%02.0f,",
r[ i ],e[ i ],n[ i ] );
fputs( ts, fh );

qs = StrFormat("%.4f,%.4f,%.4f,%.4f,%.0f\n",
O[ i ],H[ i ],L[ i ],C[ i ],V[ i ] );
fputs( qs, fh );
}

fclose( fh );
}

Buy = TimeFrameCompress(fh,inHourly);
Buy = 0;

[\code]
 

Similar threads