Simple Coding Help - No Promise.

Hi all, I am a newcomer to this forum and amibroker.

I am trying to marry a technical analysis overlay to fundamental analysis. I am a subscriber to a newsletter that provides various recommendations that are FA based.

My aim is to use this FA and overlay a momentum strategy to enhance outcomes.

I have a historical record of recommendations from this newsletter and I have been writing an AFL to test ideas. With this historical record I have symbols coming in at various stages and then leaving at a later date. On occasions the same symbol will then rejoin.

Any ideas on code that will allow a trade on a symbol from a certain date, exclude it at a later date and then allow a trade further on.
 
I am trying to marry a technical analysis overlay to fundamental analysis. I am a subscriber to a newsletter that provides various recommendations that are FA based.

My aim is to use this FA and overlay a momentum strategy to enhance outcomes.

I have a historical record of recommendations from this newsletter and I have been writing an AFL to test ideas. With this historical record I have symbols coming in at various stages and then leaving at a later date. On occasions the same symbol will then rejoin.

Any ideas on code that will allow a trade on a symbol from a certain date, exclude it at a later date and then allow a trade further on.
Hi I have found this on another forum:

Code:
dn = DateNum();

switch( Name() ) {
    case "CCC": datecond = dn <= 1140201;  break;
    case "EEE": datecond = dn >= 1141101;  break;
    default: datecond = true; break;
}


period = 20; 
m = MA( Close, period );
Buy = Cross( Close, m ) AND datecond; 
Sell = Cross( m, Close )  AND datecond;
Short = Cover = 0;

This partially works for new entries and exits, however it doesn't cater for a code which exits and then re-enters.

Also it doesn't give a sell condition for a code that is removed from the FA coverage

Any additional code would be gratefully received - Thanks
 
HI all seniors,

I am a newbie to AMI while searching something else i found this site lucky to be here, if any one help me to find a simple AFL which tells you Demand and supply would be better.
I have this code but it isn't very good as it calculate demand and supply on very near prices the higher the range the better it will be

posting the code below here. thanks in advance.

_SECTION_BEGIN("demand and supply");
SetChartOptions(0,chartShowArrows|chartShowDates);
bk=ParamColor( "Bk col",colorDarkGrey);
SetChartBkColor(bk);
SetBarFillColor(IIf(C>O,colorBrightGreen,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C," | Demand & supply |\nPrice",47,64,0,0,0,0);

sr=ParamToggle("Plot Supp/Res lines","No|Yes" ,1);
Per=Param("Sensitivity",1.5,0.5,5,0.5);
g=Param("No.of Lines",1,1,5,1);
x=Cum(1);
Pk1=PeakBars(H,per,1)== 0;
Tk1=TroughBars(L,per,1)== 0;

px1=LastValue(ValueWhen(pk1,x,1));
px2=LastValue(ValueWhen(Pk1,x,2));
px3=LastValue(ValueWhen(Pk1,x,3));
px4=LastValue(ValueWhen(pk1,x,4));
px5=LastValue(ValueWhen(Pk1,x,5));

tx1=LastValue(ValueWhen(Tk1,x,1));
tx2=LastValue(ValueWhen(Tk1,x,2));
tx3=LastValue(ValueWhen(Tk1,x,3));
tx4=LastValue(ValueWhen(Tk1,x,4));
tx5=LastValue(ValueWhen(Tk1,x,5));

XT1 =LastValue(ValueWhen(pk1,H,1));XT1c =LastValue(ValueWhen(pk1,Max(C,O),1));
XT2 =LastValue(ValueWhen(Pk1,H,2));XT2c =LastValue(ValueWhen(pk1,Max(C,O),2));
XT3 =LastValue(ValueWhen(Pk1,H,3));XT3c =LastValue(ValueWhen(pk1,Max(C,O),3));
XT4 =LastValue(ValueWhen(pk1,H,4));XT4c =LastValue(ValueWhen(pk1,Max(C,O),4));
XT5 =LastValue(ValueWhen(Pk1,H,5));XT5c =LastValue(ValueWhen(pk1,Max(C,O),5));

YT1 =LastValue(ValueWhen(tk1,L,1));YT1c =LastValue(ValueWhen(tk1,Min(O,C),1));
YT2 =LastValue(ValueWhen(tk1,L,2));YT2c =LastValue(ValueWhen(tk1,Min(O,C),2));
YT3 =LastValue(ValueWhen(tk1,L,3));YT3c =LastValue(ValueWhen(tk1,Min(O,C),3));
YT4 =LastValue(ValueWhen(tk1,L,4));YT4c =LastValue(ValueWhen(tk1,Min(O,C),4));
YT5 =LastValue(ValueWhen(tk1,L,5));YT5c =LastValue(ValueWhen(tk1,Min(O,C),5));

pk1=IIf(x>px1 AND g>=1 AND sr,XT1,Null);pk1c=IIf(x>px1 AND g>=1 AND sr,XT1c,Null);
Col1=IIf( LastValue(C)>pk1, ColorRGB(14,14,100), ColorRGB(180,20,20) );
Plot(pk1,"",31,1);PlotOHLC(0,pk1,pk1c,0,"",Col1,styleCloud|styleNoLabel,Null, Null, Null, -1);
pk2=IIf(x>px2 AND g>=2 AND sr,XT2,Null);pk2c=IIf(x>px2 AND g>=2 AND sr,XT2c,Null);
Col2=IIf( LastValue(C)>pk2, ColorRGB(24,24,120), ColorRGB(180,40,40) );
Plot(pk2,"",31,1);PlotOHLC(0,pk2,pk2c,0,"",Col2,styleCloud|styleNoLabel,Null, Null, Null, -2);
pk3=IIf(x>px3 AND g>=3 AND sr,XT3,Null);pk3c=IIf(x>px3 AND g>=3 AND sr,XT3c,Null);
Col3=IIf( LastValue(C)>pk3, ColorRGB(34,34,140),ColorRGB(180,60,60));
Plot(pk3,"",31, 1);PlotOHLC(0,pk3,pk3c,0,"",Col3,styleCloud|styleNoLabel,Null, Null, Null, -3);
pk4=IIf(x>px4 AND g>=4 AND sr,XT4,Null);pk4c=IIf(x>px4 AND g>=4 AND sr,XT4c,Null);
Col4=IIf( LastValue(C)>pk4, ColorRGB(44,44,160), ColorRGB(180,80,80));
Plot(pk4,"",31,1);PlotOHLC(0,pk4,pk4c,0,"",Col4,styleCloud|styleNoLabel,Null, Null, Null, -4);
pk5=IIf(x>px5 AND g>=5 AND sr,XT5,Null);pk5c=IIf(x>px5 AND g>=5 AND sr,XT5c,Null);
Col5=IIf( LastValue(C)>pk5, ColorRGB(54,54,180), ColorRGB(180,100,100));
Plot(pk5,"",31,1);PlotOHLC(0,pk5,pk5c,0,"",Col5,styleCloud|styleNoLabel,Null, Null, Null, -5);
tl1=IIf(x>tx1 AND g>=1 AND sr,YT1,Null);tl1c=IIf(x>tx1 AND g>=1 AND sr,YT1c,Null);
Col1=IIf( LastValue(C)>tl1, ColorRGB(14,14,100), ColorRGB(180,20,20) );
Plot(tl1,"",1,1);PlotOHLC(0,tl1,tl1c,0,"",Col1,styleCloud|styleNoLabel,Null, Null, Null, -1);
tl2=IIf(x>tx2 AND g>=2 AND sr,YT2,Null);tl2c=IIf(x>tx2 AND g>=2 AND sr,YT2c,Null);
Col2=IIf( LastValue(C)>YT2, ColorRGB(24,24,120), ColorRGB(180,40,40));
Plot(tl2,"",1,1);PlotOHLC(0,tl2,tl2c,0,"",Col2,styleCloud|styleNoLabel,Null, Null, Null, -2);
tl3=IIf(x>tx3 AND g>=3 AND sr,YT3,Null);tl3c=IIf(x>tx3 AND g>=3 AND sr,YT3c,Null);
Col3=IIf( LastValue(C)>YT3, ColorRGB(34,34,140), ColorRGB(180,60,60) );
Plot(tl3,"",1,1);PlotOHLC(0,tl3,tl3c,0,"",Col3,styleCloud|styleNoLabel,Null, Null, Null, -3);
tl4=IIf(x>tx4 AND g>=4 AND sr,YT4,Null);tl4c=IIf(x>tx4 AND g>=4 AND sr,YT4c,Null);
Col4=IIf( LastValue(C)>YT4, ColorRGB(44,44,160), ColorRGB(180,80,80) );
Plot(tl4,"",1,1);PlotOHLC(0,tl4,tl4c,0,"",Col4,styleCloud|styleNoLabel,Null, Null, Null, -4);
tl5=IIf(x>tx5 AND g>=5 AND sr,YT5,Null);tl5c=IIf(x>tx5 AND g>=5 AND sr,YT5c,Null);
Col5=IIf( LastValue(C)>YT5, ColorRGB(54,54,180), ColorRGB(180,100,100));
Plot(tl5,"",1,1);PlotOHLC(0,tl5,tl5c,0,"",Col5,styleCloud|styleNoLabel,Null, Null, Null, -5);

_SECTION_END();
 

Nehal_s143

Well-Known Member
If you want to do it for one (or few) scrips, you can do it as follows

Example symbol is X
1) Rename the original symbol to X_ORIG
2) Create another symbol X and let the live feed go to that one
3) Before backfill, rename X to X_LIVE
4) Create another symbol X and backfill
5) Now, you can plot X_ORIG, X_LIVE and X (backfill) on same chart

Do take backups and do remember to delete the unwanted symbols when you are done
Mastermind007 SIr,

I have found one more method to compare data for last few candles open high low close

Code:
CellHeight = 20;
CellWidth = 100;
GfxSelectFont( "Tahoma", CellHeight/2 );

function PrintInCell( string, row, Col )
{
GfxDrawText( string, Col * CellWidth, row * CellHeight, (Col + 1 ) * CellWidth, (row + 1 ) * CellHeight, 0 );
}

PrintInCell( "Open", 0, 0 );
PrintInCell( "High", 0, 1 );
PrintInCell( "Low", 0, 2 );
PrintInCell( "Close", 0, 3 );
PrintInCell( "Volume", 0, 4 );

GfxSelectPen( colorBlue );
for( i = 1; i < 10 && i < BarCount; i++ )
{
PrintInCell( StrFormat("%g", O[ i ] ), i, 0 );
PrintInCell( StrFormat("%g", H[ i ] ), i, 1 );
PrintInCell( StrFormat("%g", L[ i ] ), i, 2 );
PrintInCell( StrFormat("%g", C[ i ] ), i, 3 );
PrintInCell( StrFormat("%g", V[ i ] ), i, 4 );
GfxMoveTo( 0, i * CellHeight );
GfxLineTo( 5 * CellWidth, i * CellHeight );
}
GfxMoveTo( 0, i * CellHeight );
GfxLineTo( 5 * CellWidth, i * CellHeight );

for( Col = 1; Col < 6; Col++ )
{
GfxMoveTo( Col * CellWidth, 0);
GfxLineTo( Col * CellWidth, 10 * CellHeight );
}
take screen shot of new data and compare with old data
 
Last edited:
HI all seniors,

I am a newbie to AMI while searching something else i found this site lucky to be here, if any one help me to find a simple AFL which tells you Demand and supply would be better.
I have this code but it isn't very good as it calculate demand and supply on very near prices the higher the range the better it will be

posting the code below here. thanks in advance.

_SECTION_BEGIN("demand and supply");
SetChartOptions(0,chartShowArrows|chartShowDates);
bk=ParamColor( "Bk col",colorDarkGrey);
SetChartBkColor(bk);
SetBarFillColor(IIf(C>O,colorBrightGreen,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C," | Demand & supply |\nPrice",47,64,0,0,0,0);

sr=ParamToggle("Plot Supp/Res lines","No|Yes" ,1);
Per=Param("Sensitivity",1.5,0.5,5,0.5);
g=Param("No.of Lines",1,1,5,1);
x=Cum(1);
Pk1=PeakBars(H,per,1)== 0;
Tk1=TroughBars(L,per,1)== 0;

px1=LastValue(ValueWhen(pk1,x,1));
px2=LastValue(ValueWhen(Pk1,x,2));
px3=LastValue(ValueWhen(Pk1,x,3));
px4=LastValue(ValueWhen(pk1,x,4));
px5=LastValue(ValueWhen(Pk1,x,5));

tx1=LastValue(ValueWhen(Tk1,x,1));
tx2=LastValue(ValueWhen(Tk1,x,2));
tx3=LastValue(ValueWhen(Tk1,x,3));
tx4=LastValue(ValueWhen(Tk1,x,4));
tx5=LastValue(ValueWhen(Tk1,x,5));

XT1 =LastValue(ValueWhen(pk1,H,1));XT1c =LastValue(ValueWhen(pk1,Max(C,O),1));
XT2 =LastValue(ValueWhen(Pk1,H,2));XT2c =LastValue(ValueWhen(pk1,Max(C,O),2));
XT3 =LastValue(ValueWhen(Pk1,H,3));XT3c =LastValue(ValueWhen(pk1,Max(C,O),3));
XT4 =LastValue(ValueWhen(pk1,H,4));XT4c =LastValue(ValueWhen(pk1,Max(C,O),4));
XT5 =LastValue(ValueWhen(Pk1,H,5));XT5c =LastValue(ValueWhen(pk1,Max(C,O),5));

YT1 =LastValue(ValueWhen(tk1,L,1));YT1c =LastValue(ValueWhen(tk1,Min(O,C),1));
YT2 =LastValue(ValueWhen(tk1,L,2));YT2c =LastValue(ValueWhen(tk1,Min(O,C),2));
YT3 =LastValue(ValueWhen(tk1,L,3));YT3c =LastValue(ValueWhen(tk1,Min(O,C),3));
YT4 =LastValue(ValueWhen(tk1,L,4));YT4c =LastValue(ValueWhen(tk1,Min(O,C),4));
YT5 =LastValue(ValueWhen(tk1,L,5));YT5c =LastValue(ValueWhen(tk1,Min(O,C),5));

pk1=IIf(x>px1 AND g>=1 AND sr,XT1,Null);pk1c=IIf(x>px1 AND g>=1 AND sr,XT1c,Null);
Col1=IIf( LastValue(C)>pk1, ColorRGB(14,14,100), ColorRGB(180,20,20) );
Plot(pk1,"",31,1);PlotOHLC(0,pk1,pk1c,0,"",Col1,styleCloud|styleNoLabel,Null, Null, Null, -1);
pk2=IIf(x>px2 AND g>=2 AND sr,XT2,Null);pk2c=IIf(x>px2 AND g>=2 AND sr,XT2c,Null);
Col2=IIf( LastValue(C)>pk2, ColorRGB(24,24,120), ColorRGB(180,40,40) );
Plot(pk2,"",31,1);PlotOHLC(0,pk2,pk2c,0,"",Col2,styleCloud|styleNoLabel,Null, Null, Null, -2);
pk3=IIf(x>px3 AND g>=3 AND sr,XT3,Null);pk3c=IIf(x>px3 AND g>=3 AND sr,XT3c,Null);
Col3=IIf( LastValue(C)>pk3, ColorRGB(34,34,140),ColorRGB(180,60,60));
Plot(pk3,"",31, 1);PlotOHLC(0,pk3,pk3c,0,"",Col3,styleCloud|styleNoLabel,Null, Null, Null, -3);
pk4=IIf(x>px4 AND g>=4 AND sr,XT4,Null);pk4c=IIf(x>px4 AND g>=4 AND sr,XT4c,Null);
Col4=IIf( LastValue(C)>pk4, ColorRGB(44,44,160), ColorRGB(180,80,80));
Plot(pk4,"",31,1);PlotOHLC(0,pk4,pk4c,0,"",Col4,styleCloud|styleNoLabel,Null, Null, Null, -4);
pk5=IIf(x>px5 AND g>=5 AND sr,XT5,Null);pk5c=IIf(x>px5 AND g>=5 AND sr,XT5c,Null);
Col5=IIf( LastValue(C)>pk5, ColorRGB(54,54,180), ColorRGB(180,100,100));
Plot(pk5,"",31,1);PlotOHLC(0,pk5,pk5c,0,"",Col5,styleCloud|styleNoLabel,Null, Null, Null, -5);
tl1=IIf(x>tx1 AND g>=1 AND sr,YT1,Null);tl1c=IIf(x>tx1 AND g>=1 AND sr,YT1c,Null);
Col1=IIf( LastValue(C)>tl1, ColorRGB(14,14,100), ColorRGB(180,20,20) );
Plot(tl1,"",1,1);PlotOHLC(0,tl1,tl1c,0,"",Col1,styleCloud|styleNoLabel,Null, Null, Null, -1);
tl2=IIf(x>tx2 AND g>=2 AND sr,YT2,Null);tl2c=IIf(x>tx2 AND g>=2 AND sr,YT2c,Null);
Col2=IIf( LastValue(C)>YT2, ColorRGB(24,24,120), ColorRGB(180,40,40));
Plot(tl2,"",1,1);PlotOHLC(0,tl2,tl2c,0,"",Col2,styleCloud|styleNoLabel,Null, Null, Null, -2);
tl3=IIf(x>tx3 AND g>=3 AND sr,YT3,Null);tl3c=IIf(x>tx3 AND g>=3 AND sr,YT3c,Null);
Col3=IIf( LastValue(C)>YT3, ColorRGB(34,34,140), ColorRGB(180,60,60) );
Plot(tl3,"",1,1);PlotOHLC(0,tl3,tl3c,0,"",Col3,styleCloud|styleNoLabel,Null, Null, Null, -3);
tl4=IIf(x>tx4 AND g>=4 AND sr,YT4,Null);tl4c=IIf(x>tx4 AND g>=4 AND sr,YT4c,Null);
Col4=IIf( LastValue(C)>YT4, ColorRGB(44,44,160), ColorRGB(180,80,80) );
Plot(tl4,"",1,1);PlotOHLC(0,tl4,tl4c,0,"",Col4,styleCloud|styleNoLabel,Null, Null, Null, -4);
tl5=IIf(x>tx5 AND g>=5 AND sr,YT5,Null);tl5c=IIf(x>tx5 AND g>=5 AND sr,YT5c,Null);
Col5=IIf( LastValue(C)>YT5, ColorRGB(54,54,180), ColorRGB(180,100,100));
Plot(tl5,"",1,1);PlotOHLC(0,tl5,tl5c,0,"",Col5,styleCloud|styleNoLabel,Null, Null, Null, -5);

_SECTION_END();


Anyone with any solution.....
 
Hi I have found this on another forum:

Code:
dn = DateNum();

switch( Name() ) {
    case "CCC": datecond = dn <= 1140201;  break;
    case "EEE": datecond = dn >= 1141101;  break;
    default: datecond = true; break;
}


period = 20; 
m = MA( Close, period );
Buy = Cross( Close, m ) AND datecond; 
Sell = Cross( m, Close )  AND datecond;
Short = Cover = 0;

This partially works for new entries and exits, however it doesn't cater for a code which exits and then re-enters.

Also it doesn't give a sell condition for a code that is removed from the FA coverage

Any additional code would be gratefully received - Thanks

I have had an answer on another forum to this coding question.

http://www.aussiestockforums.com/fo...=1679&page=122&p=877910&viewfull=1#post877910

It achieves what I have asked. I will do more testing
 
Filter you want is usually called Explorer in Amibroker

Code provided below will do the job. You need to run it in Automatic Analysis. It will show nothing on chart.

Code:
p = Param("Period",10,10,20,1);
Filter = Cross(PDI(p),MDI(p)) & (RSI(p) > 30);

AddColumn(PDI(p), "+DI");
AddColumn(MDI(p), "-DI");
AddColumn(RSI(p), "RSI");


Hello Mastermind sir & all seniors,

Above exploration only for Buy ..

(i want exploration for Sell and buy both).


Condition - Minus DMI Crossover + DMI
RSI < 70
(Both condition to satisfy as told above)


If i m wrong in putting condition... correct me.

(Need Column pointing - BUY - SELL)

Thanx you in advance
 

amitrandive

Well-Known Member
Hello Mastermind sir & all seniors,

Above exploration only for Buy ..

(i want exploration for Sell and buy both).


Condition - Minus DMI Crossover + DMI
RSI < 70
(Both condition to satisfy as told above)


If i m wrong in putting condition... correct me.

(Need Column pointing - BUY - SELL)

Thanx you in advance
www.wi sesto cktrader.com/indicators/1921-adx-+-rsi-select-stock
(remove spaces)
 
Small effort:

only sell condition should be modify:

Code:
p = Param("Period",10,10,20,1);
Filter = Cross(PDI(p),MDI(p)) & (RSI(p) > 30);

AddColumn(PDI(p), "+DI");
AddColumn(MDI(p), "-DI");
AddColumn(RSI(p), "RSI");

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

Buy=Cross(PDI(p),MDI(p))  AND  (RSI(p) > 30);
Sell= (RSI(p) > 70); // here should be modification 

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

PlotShapes( shapeSmallUpTriangle* Buy , colorBlue,0,L,-15);
PlotShapes( shapeSmallDownTriangle* Sell ,colorRed,0,H,-15);

AddColumn(IIf(Buy ,Ref(L,0) ,Null),"Buy Above",6.2,2,colorBlue);  
AddColumn(IIf(Sell ,-Ref(H,0),Null),"Sell Below  ",6.2,2,colorCustom5);
~manoj
 
Last edited:
HTML:
p = Param("Period",10,10,20,1);
Filter = Cross(PDI(p),MDI(p)) & (RSI(p) > 30);

AddColumn(PDI(p), "+DI");
AddColumn(MDI(p), "-DI");
AddColumn(RSI(p), "RSI");

Above afl by mastermind sir is for BUY Conditions...


I need same conditions for Sell with Rsi below 70 levels.

(Both condition to satisfy)
 

Similar threads