Teknik Analiz Dünyasına Hoşgeldiniz. Paylaşmak Güzeldir.

Üye Olma ve Üyelik Sorunlarınız için İletişim algoritmabul@yandex.com

  • DİKKAT: Formüller, Sistemler sadece eğitim amaçlıdır. Alım satım, olası anapara kaybı ve diğer kayıplar dahil olmak üzere "YÜKSEK RİSK" içerir.

Amibroker Amibrokerda SAR indikatöründe Buy-Sell yapma

Amibroker

uysalmurat78

Algorithmist
Katılım
11 May 2022
Mesajlar
1
Merhabalar aşağıda sunduğum Amibroker formülünde Buy-Sell yapmak için gerekli ilave edilmesi gerekeni yapmanız mümkün mü?Böylelikle Scan veya Explorerla tarama yapmam mümkün olur diye düşünüyorum.Yardımcı olmanız mümkün mü?

/www.aflcode.com

IAF = 0.02; // acceleration factor
MaxAF = 0.2; // max acceleration

psar = Close; // initialize
long = 1; // assume long for initial conditions
af = IAF; // init acelleration factor
ep = Low[ 0 ]; // init extreme point
hp = High [ 0 ];
lp = Low [ 0 ];

for( i = 2; i < BarCount; i++ )
{
if ( long )
{
psar [ i ] = psar [ i-1 ] + af * ( hp - psar [ i-1 ] );
}
else
{
psar [ i ] = psar [ i-1 ] + af * ( lp - psar [ i-1 ] );
}

reverse = 0;
//check for reversal
if ( long )
{
if ( Low [ i ] < psar [ i ] )
{
long = 0; reverse = 1; // reverse position to Short
psar [ i ] = hp; // SAR is High point in prev trade
lp = Low [ i ];
af = IAF;
}
}
else
{
if ( High [ i ] > psar [ i ] )
{
long = 1; reverse = 1; //reverse position to long
psar [ i ] = lp;
hp = High [ i ];
af = IAF;
}
}

if ( reverse == 0 )
{
if ( long )
{
if ( High [ i ] > hp )
{
hp = High [ i ];
af = af + IAF;
if( af > MaxAF ) af = MaxAF;
}

if( Low[ i - 1 ] < psar[ i ] ) psar[ i ] = Low[ i - 1 ];
if( Low[ i - 2 ] < psar[ i ] ) psar[ i ] = Low[ i - 2 ];
}
else
{
if ( Low [ i ] < lp )
{
lp = Low [ i ];
af = af + IAF;
if( af > MaxAF ) af = MaxAF;
}

if( High[ i - 1 ] > psar[ i ] ) psar[ i ] = High[ i - 1 ];
if( High[ i - 2 ] > psar[ i ] ) psar[ i ] = High[ i - 2 ];

}
}
}

Plot( Close, "Price", colorBlack, styleCandle );
Plot( psar, "SAR", colorRed, styleDots | styleNoLine | styleThick );

 

algoritma

→ein+1=0←
Algorithmist
Algoritma
Katılım
23 Eki 2020
Mesajlar
1,678
şöyle denenebilir
Kod:
_SECTION_BEGIN("Parabolic SAR");

SetTradeDelays( 1, 1, 1, 1 );
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",100);
SetOption("AccountMargin",10);
SetOption("RefreshWhenCompleted",True);
SetPositionSize(100,spsPercentOfEquity);
SetOption( "AllowPositionShrinking", True );
BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;

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 ) ) ));

Plot( Close, "Price", colorWhite, styleCandle );

accel = Param("Acceleration", 0.1, 0, 1, 0.01);
mx = Param("Max. acceleration", 0.2, 0, 1, 0.1);

F_SAR = SAR(accel,mx);

colordots = IIf(F_SAR < L,colorGreen,IIf(F_SAR> H,colorRed,colorWhite));

Buy = Cross(C,F_SAR);
Short = Cross(F_SAR,C);
Sell=Short;
Cover=Buy;
Plot(F_SAR,"\nF_SAR",colordots,styleDots|styleNoLine);


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

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

StopLoss=Param("stop",1,0.5,3,0.5);
ApplyStop(Type=0,Mode=1,Amount=StopLoss);
  
Target=Param("Target",5,0.5,5,0.5);
ApplyStop(Type=1,Mode=1,Amount=Target);

printf("\nBuy : " + Buy );
printf("\nSell : " + Sell );
printf("\nShort : " + Short );
printf("\nCover : " + Cover );


/* Plot Buy and Sell Signal Arrows */
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);



_SECTION_END();

diğer bir şekilde
Kod:
_SECTION_BEGIN("ema3,15");
x = EMA(Close,3);
y = EMA(Close,15);

Plot(EMA(Close,3),"",colorBrightGreen, styleLine, styleThick);
Plot(EMA(Close,15),"",colorRed, styleLine, styleThick);
GraphXSpace=0.5;
Plot(C,"",colorBlue,styleCandle);
XR=(EMA(Close,3) * (2 / 6 - 1) - EMA(Close,15) * (2 / 11 - 1)) / (2 / 6 - 2 / 11);


Buy = Close > EMA( Close , 15 )
AND Ref( Close , -1 ) > Ref( EMA( Close , 15 ) , -1 )
AND Cross(x,y);

Sell = Close > EMA( Close , 3 )
AND Open > EMA( Close , 3 );

Short = Close < EMA( Close , 3 )
AND Ref( Close , -1 ) < Ref( EMA( Close , 3 ) , -1 )

AND Cross(y,x);

Cover = Close < EMA( Close , 3 )
AND Open < EMA( Close , 3 );

SellPrice=ValueWhen( Sell, C, 1);
BuyPrice=ValueWhen( Buy,C, 1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );


PlotShapes(shapeUpArrow*Buy,colorGreen, 0, L, Offset=-45);
PlotShapes(shapeSmallDownTriangle*Sell,colorGreen, 0, L, Offset=-45);
PlotShapes(shapeSmallUpTriangle*Cover,colorOrange, 0, L, Offset=-45);
PlotShapes(shapeDownArrow*Short,colorOrange, 0, H, Offset=-45);
AlertIf( Buy, "SOUND C:\\Windows\\Media\\notify.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\chord.wav", "Audio alert", 2 );
AlertIf( Cover, "SOUND C:\\Windows\\Media\\notify.wav", "Audio alert", 2 );
AlertIf( Short, "SOUND C:\\Windows\\Media\\chord.wav", "Audio alert", 2 );

_SECTION_END();

_SECTION_BEGIN("supp");
("Price");
RSIperiod = 15; // Param("RSI p",3,14,30,1);
Percent = 5; // Param("ZIG %",8,9,15,1);
EMAperiod = 5; //Param("EMA p",4,5,10,1);
HHVperiod = 8; //Param("HHV p",3,5,10,1);
NumLine = 2; //Param("Num Lines",3,1,20,1);

Base = DEMA(RSI(RSIperiod),EMAperiod);

GraphXSpace=0.5;
Plot(C,"",colorWhite,styleCandle);

for( i = 1; i <= numline; i++ )
{
ResBase = LastValue(Peak(Base,Percent,i));
SupBase = LastValue(Trough(Base,Percent,i));
Plot(ValueWhen( ResBase==Base, HHV(H,HHVperiod) ), "Resist Level", colorRed, styleLine);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorGreen, styleLine);
}

_SECTION_END();

_SECTION_BEGIN("SAR");
acc = Param("Acceleration", 0.02, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 );
Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );

//=================TITLE============================ ================================================== ==================
_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorWhite)+ ":EMA 3/15, Support & Resistance Levels using RSI:, SAR Dotted Line - buy/sell white arrow/triangle - short-cover orange arrow/triangle" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorYellow) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorRed)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","")+
WriteIf(Long AND NOT Buy, "Trade : Long - Entry price Rs."+(BuyPrice),"")+
WriteIf(shrt AND NOT Sell, "Trade : Short - Entry price Rs."+(SellPrice),"")+"\n"+
WriteIf(Long AND NOT Buy, "Current Profit/Loss Rs."+(C-BuyPrice)+"","")+
WriteIf(shrt AND NOT Sell, "Current Profit/Loss Rs."+(SellPrice-C)+"",""));
AlertIf( Buy, "SOUND C:\\Windows\\Media\\Windows XP Startup.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\Ringin.wav", "Audio alert", 2 );

_SECTION_END();

yine psar örneği
Kod:
_SECTION_BEGIN("Parabolic SAR Crossover");
Plot(C,"Close",colorBlack,64);
uptrend=PDI()>MDI()AND Signal()<MACD();
downtrend=MDI()>PDI()AND Signal()>MACD();


Plot( 2, /* defines the height of the Market Trend in percent of pane width */"TREND",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 6 )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );

SetChartBkColor( ParamColor( "Outer panel",colorBlack) );

SetChartOptions(0,chartShowArrows|chartShowDates);
 
NewDay = Day()!= Ref(Day(), -1);
DH = HHV( H, NewDay);
DL =  LLV(L, NewDay);
Plot(DH,"DAY HIGH",colorPaleGreen,ParamStyle("Style"),0,0,0);
Plot(DL,"DAY LOW",colorPink,ParamStyle("Style"),0,0,0);
R1=((DH-DL)*0.33)+DL;
R2=((DH-DL)*0.66)+DL;
Plot(R1,"BEARISH BELOW",colorYellow,styleDashed,0,0,0);
Plot(R2,"BULLISH ABOVE",colorBrightGreen,styleDashed,0,0,0);

accel = Param("Acceleration", 0.02, 0, 1, 0.001);
mx = Param("Max. acceleration", 0.2, 0, 1, 0.001);

F_SAR = SAR(accel,mx);

colordots = IIf(F_SAR < L,colorGreen,IIf(F_SAR> H,colorRed,colorWhite));

Buy = Cross(C,F_SAR); Buy = Ref(Buy,-1); BuyPrice = O;
Sell = Cross(F_SAR,C); Sell = Ref(Sell,-1); SellPrice = O;

SetBarsRequired(-2,-2);
SetChartOptions(0, chartShowDates);
 Plot(F_SAR,"\nF_SAR",colordots,styleDots|styleNoLine);

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBrightGreen,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowUpArrow,shapeNone),colorBrightGreen,0,L,-15);
PlotShapes(IIf(Buy,shapeHollowCircle,shapeNone),colorBlue,0,BuyPrice,0);

PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Sell,shapeHollowDownArrow,shapeNone),colorRed,0,H,-15);
PlotShapes(IIf(Sell,shapeHollowCircle,shapeNone),colorOrange,0,SellPrice,0);
 

Forumdan daha fazla yararlanmak için giriş yapın yada üye olun!

Forumdan daha fazla yararlanmak için giriş yapın veya kayıt olun!

Kayıt ol

Forumda bir hesap oluşturmak tamamen ücretsizdir.

Şimdi kayıt ol
Giriş yap

Eğer bir hesabınız var ise lütfen giriş yapın

Giriş yap