Simple Coding Help - No Promise.

hey guys,

i am new to AMI broker & facing a very basic issue in viewing of charts in amibroker.

when working on intra day time frame i am able to view only today's data , how can i see chart for say 5min tf for past 5 days. :confused:
 

jamit_05

Well-Known Member
Hi,

I need a small code to display the Day Of Week (only first three letters) on an intraday chart. As for the location of that label, it could be blended into the background in grey color in medium sized fonts.

I am hoping to get a mental imprint of dull days which are unprofitable for intraday trading.

TIA
 

amitrandive

Well-Known Member
Hi,

I need a small code to display the Day Of Week (only first three letters) on an intraday chart. As for the location of that label, it could be blended into the background in grey color in medium sized fonts.

I am hoping to get a mental imprint of dull days which are unprofitable for intraday trading.

TIA
Got this from the net.AFL experts please guide/improve.

Use this function and put it to the Include folder of Amibroker e.g. as DayOfWeekName.afl or whatever name

function DayOfWeekName()
{
dow = DayOfWeek();
dayStr =
WriteIf(dow == 0, "Sunday",
WriteIf(dow == 1, "Monday",
WriteIf(dow == 2, "Tuesday",
WriteIf(dow == 3, "Wednesday",
WriteIf(dow == 4, "Thursday",
WriteIf(dow == 5, "Friday",
WriteIf(dow == 6, "Saturday", "Unknown")))))));

return dayStr;
}

then in your main code call that function

#include <DayOfWeekName.afl>;

dow = DayOfWeekName();

then the title of that main code could look as follows

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} - " + dow + " {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

you could use something completely different (so forget about the above one)

like this

iday,Saturday", SelectedValue(DayOfWeek()));

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} - " + DayName + " {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
 

jamit_05

Well-Known Member
Got this from the net.AFL experts please guide/improve.

Use this function and put it to the Include folder of Amibroker e.g. as DayOfWeekName.afl or whatever name

function DayOfWeekName()
{
dow = DayOfWeek();
dayStr =
WriteIf(dow == 0, "Sunday",
WriteIf(dow == 1, "Monday",
WriteIf(dow == 2, "Tuesday",
WriteIf(dow == 3, "Wednesday",
WriteIf(dow == 4, "Thursday",
WriteIf(dow == 5, "Friday",
WriteIf(dow == 6, "Saturday", "Unknown")))))));

return dayStr;
}

then in your main code call that function

#include <DayOfWeekName.afl>;

dow = DayOfWeekName();

then the title of that main code could look as follows

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} - " + dow + " {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

you could use something completely different (so forget about the above one)

like this

iday,Saturday", SelectedValue(DayOfWeek()));

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} - " + DayName + " {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));


I made that file in the Include folder. So far so good.

Could you please give the exact code to be put onto the price chart.... thanks.
 

pratapvb

Well-Known Member
I made that file in the Include folder. So far so good.

Could you please give the exact code to be put onto the price chart.... thanks.
read carefully....
there is a line inbetween that reads "then in your main code call that function"

so above that goes into include folder file

below that into afl of price chart
 

jamit_05

Well-Known Member
read carefully....
there is a line inbetween that reads "then in your main code call that function"

so above that goes into include folder file

below that into afl of price chart

Got it... tks.... Now it is showing in the title.

But, it would be of best if this day showed bang in the middle of the day... meshed into the background in grey fonts... if it is simple to do then please... :)
 

a1b1trader

Well-Known Member
hey guys,

i am new to AMI broker & facing a very basic issue in viewing of charts in amibroker.

when working on intra day time frame i am able to view only today's data , how can i see chart for say 5min tf for past 5 days. :confused:
Must be using a trial version of amibroker
Isnt it so.
In trial version you can not save data.
 
NEED A CODING FOR SUPERTREND INDICATOR

BUY COND: BUY ONLY IF THE HIGH OF SIGNAL CANDLE (AS PER SUPERTREND)
BROKEN.

SELL COND : SELL ONLY IF THE LOW OF SIGNAL CANDLE (AS PER SUPERTREND)
BROKEN.

SEE THE ATTACHMENT


IMAGE LINK IF NOT OPEN
http://imageshack.us/photo/my-images/200/afd.bmp


HERE IS THE AFL FOR SUPERTREND :
Code:
_SECTION_BEGIN("SuperTrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;

SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Factor=Param("Factor",3,1,10,1);
Pd=Param("ATR Periods",10,1,100,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

for (i = 1; i <BarCount-1; i++) {
      TrendUp[i] = Null;
      TrendDown[i] = Null;
    
      trend[i]=1;
  
      
      if (Close[i]>Up[i-1]) {
        trend[i]=1;
        if (trend[i-1] == -1) changeOfTrend = 1;
        
      }
      else if (Close[i]<Dn[i-1]) {
        trend[i]=-1;
        if (trend[i-1] == 1) changeOfTrend = 1;
      }
      else if (trend[i-1]==1) {
        trend[i]=1;
        changeOfTrend = 0;      
      }
      else if (trend[i-1]==-1) {
        trend[i]=-1;
        changeOfTrend = 0;
      }

      if (trend[i]<0 && trend[i-1]>0) {
        flag=1;
      }
      else {
        flag=0;
      }
      
      if (trend[i]>0 && trend[i-1]<0) {
        flagh=1;
      }
      else {
        flagh=0;
      }
      
      if (trend[i]>0 && Dn[i]<Dn[i-1]){
        Dn[i]=Dn[i-1];
      }
      
      if (trend[i]<0 && Up[i]>Up[i-1])
        { Up[i]=Up[i-1];
      }
      
      if (flag==1)
      {  Up[i]=(H[i]+L[i])/2+(Factor*iATR[i]);;
        } 
      if (flagh==1)
        { Dn[i]=(H[i]+L[i])/2-(Factor*iATR[i]);;
        }
      if (trend[i]==1) {
        TrendUp[i]=Dn[i];
        if (changeOfTrend == 1) {
            TrendUp[i-1] = TrendDown[i-1];
            changeOfTrend = 0;
        }
      }
      else if (trend[i]==-1) {
        TrendDown[i]=Up[i];
        if (changeOfTrend == 1) {
            TrendDown[i-1] = TrendUp[i-1];
            changeOfTrend = 0;
        }
      }
  } 

Plot(TrendUp,"Trend",colorBlue,styleDots|styleThick|styleNoLine);
Plot(TrendDown,"Down",colorRed,styleDots|styleThick|styleNoLine);

Buy = trend==1;
Sell=trend==-1;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;


BuyPrice=ValueWhen(Buy,H);
SellPrice=ValueWhen(Sell,L);
ShortPrice=ValueWhen(Short,L);
CoverPrice=ValueWhen(Cover,H);

//------filter----///

Filter=Buy OR Sell;
Filter= Cover OR Short;

AddColumn( Buy, "Buy", 1);
AddColumn(Sell, "Sell", 1);
AddColumn(Close,"Close",1.2);
AddColumn(Volume,"Volume",1.0);



Title = EncodeColor(colorYellow)+ "Super Fortune" + " - " +  Name() + " - " + EncodeColor(colorYellow)+ Interval(2) + EncodeColor(colorYellow) +
 "  - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+"  "+"Hi-"+H+"  "+"Lo-"+L+"  "+
"Cl-"+C+"  "+ "Vol= "+ WriteVal(V);
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+"  ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+"  ","")+"\n"+EncodeColor(colorYellow)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy  , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");


PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorBlue, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorBlue, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0,H, Offset=50);                      
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

TrendSL=IIf(trend==1,TrendUp,TrendDown);

for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = H[i];
sig = "BUY";
sl = TrendSL[i];
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);
 
bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "SELL";
entry = L[i];
sl = TrendSL[i];
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);
 
 
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorBlue, colorRed);
ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1));
sl = ssl[BarCount-1];
 

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);

Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorWhite, styleLine|styleDashed, Null, Null, Offset);
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorBlack, styleLine|styleDashed, Null, Null, Offset);


 
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;
 
y = pxHeight;

_SECTION_END();

_SECTION_BEGIN("Price");
range = Param("Periods", 14, 2, 200, 1 );
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot( C, "Close", IIf( PDI(range) > MDI(range), ParamColor("Up Color", colorGreen ),
ParamColor("Down Color", colorRed )), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
 
Last edited:
Try this

Code:
BO = ValueWhen(trend== 1 AND Ref(trend,-1)==-1,H);	Plot(BO,"Trend",colorBlue,styleDashed);
BD = ValueWhen(trend==-1 AND Ref(trend,-1)== 1,L);	Plot(BD,"Down",colorRed,styleDashed);
Buy = Cross(C,BO);		Sell= Cross(BD,C);
NEED A CODING FOR SUPERTREND INDICATOR

BUY COND: BUY ONLY IF THE HIGH OF SIGNAL CANDLE (AS PER SUPERTREND)
BROKEN.

SELL COND : SELL ONLY IF THE LOW OF SIGNAL CANDLE (AS PER SUPERTREND)
BROKEN.

SEE THE ATTACHMENT


IMAGE LINK IF NOT OPEN
http://imageshack.us/photo/my-images/200/afd.bmp


HERE IS THE AFL FOR SUPERTREND :
Code:
_SECTION_BEGIN("SuperTrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;

SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

Factor=Param("Factor",3,1,10,1);
Pd=Param("ATR Periods",10,1,100,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

for (i = 1; i <BarCount-1; i++) {
      TrendUp[i] = Null;
      TrendDown[i] = Null;
    
      trend[i]=1;
  
      
      if (Close[i]>Up[i-1]) {
        trend[i]=1;
        if (trend[i-1] == -1) changeOfTrend = 1;
        
      }
      else if (Close[i]<Dn[i-1]) {
        trend[i]=-1;
        if (trend[i-1] == 1) changeOfTrend = 1;
      }
      else if (trend[i-1]==1) {
        trend[i]=1;
        changeOfTrend = 0;      
      }
      else if (trend[i-1]==-1) {
        trend[i]=-1;
        changeOfTrend = 0;
      }

      if (trend[i]<0 && trend[i-1]>0) {
        flag=1;
      }
      else {
        flag=0;
      }
      
      if (trend[i]>0 && trend[i-1]<0) {
        flagh=1;
      }
      else {
        flagh=0;
      }
      
      if (trend[i]>0 && Dn[i]<Dn[i-1]){
        Dn[i]=Dn[i-1];
      }
      
      if (trend[i]<0 && Up[i]>Up[i-1])
        { Up[i]=Up[i-1];
      }
      
      if (flag==1)
      {  Up[i]=(H[i]+L[i])/2+(Factor*iATR[i]);;
        } 
      if (flagh==1)
        { Dn[i]=(H[i]+L[i])/2-(Factor*iATR[i]);;
        }
      if (trend[i]==1) {
        TrendUp[i]=Dn[i];
        if (changeOfTrend == 1) {
            TrendUp[i-1] = TrendDown[i-1];
            changeOfTrend = 0;
        }
      }
      else if (trend[i]==-1) {
        TrendDown[i]=Up[i];
        if (changeOfTrend == 1) {
            TrendDown[i-1] = TrendUp[i-1];
            changeOfTrend = 0;
        }
      }
  } 

Plot(TrendUp,"Trend",colorBlue,styleDots|styleThick|styleNoLine);
Plot(TrendDown,"Down",colorRed,styleDots|styleThick|styleNoLine);

Buy = trend==1;
Sell=trend==-1;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;


BuyPrice=ValueWhen(Buy,H);
SellPrice=ValueWhen(Sell,L);
ShortPrice=ValueWhen(Short,L);
CoverPrice=ValueWhen(Cover,H);

//------filter----///

Filter=Buy OR Sell;
Filter= Cover OR Short;

AddColumn( Buy, "Buy", 1);
AddColumn(Sell, "Sell", 1);
AddColumn(Close,"Close",1.2);
AddColumn(Volume,"Volume",1.0);



Title = EncodeColor(colorYellow)+ "Super Fortune" + " - " +  Name() + " - " + EncodeColor(colorYellow)+ Interval(2) + EncodeColor(colorYellow) +
 "  - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+"  "+"Hi-"+H+"  "+"Lo-"+L+"  "+
"Cl-"+C+"  "+ "Vol= "+ WriteVal(V);
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+"  ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+"  ","")+"\n"+EncodeColor(colorYellow)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy  , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");


PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorBlue, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorBlue, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0,H, Offset=50);                      
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

TrendSL=IIf(trend==1,TrendUp,TrendDown);

for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = H[i];
sig = "BUY";
sl = TrendSL[i];
tar1 = entry + (entry * .0050);
tar2 = entry + (entry * .0092);
tar3 = entry + (entry * .0179);
 
bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "SELL";
entry = L[i];
sl = TrendSL[i];
tar1 = entry - (entry * .0050);
tar2 = entry - (entry * .0112);
tar3 = entry - (entry * .0212);
 
 
bars = i;
i = 0;
}
}
Offset = 20;
Clr = IIf(sig == "BUY", colorBlue, colorRed);
ssl = IIf(bars == BarCount-1, TrendSL[BarCount-1], Ref(TrendSL, -1));
sl = ssl[BarCount-1];
 

Plot(LineArray(bars-Offset, tar1, BarCount, tar1,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar2, BarCount, tar2,1), "", Clr, styleLine|styleDots, Null, Null, Offset);
Plot(LineArray(bars-Offset, tar3, BarCount, tar3,1), "", Clr, styleLine|styleDots, Null, Null, Offset);

Plot(LineArray(bars-Offset, sl, BarCount, sl,1), "", colorWhite, styleLine|styleDashed, Null, Null, Offset);
Plot(LineArray(bars-Offset, entry, BarCount, entry,1), "", colorBlack, styleLine|styleDashed, Null, Null, Offset);


 
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;
 
y = pxHeight;

_SECTION_END();

_SECTION_BEGIN("Price");
range = Param("Periods", 14, 2, 200, 1 );
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot( C, "Close", IIf( PDI(range) > MDI(range), ParamColor("Up Color", colorGreen ),
ParamColor("Down Color", colorRed )), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
 

Similar threads