Permission denied!

Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

gen_brkout for Amibroker (AFL)

Rating:
2 / 5 (Votes 3)
Tags:
trading system, amibroker

This afl copy from www.lurama125.com, supporting gen_cross_conf.afl

You need to put the following two afls in the include directory:
http://wisestocktrader.com/indicatorpasties/120-liba-afl
http://wisestocktrader.com/indicatorpasties/119-pebslib-afl

Screenshots

Similar Indicators / Formulas

weighted moving average scan
Submitted by naninn over 13 years ago
Kase Peak Osc. V2 batu
Submitted by batu1453 over 10 years ago
Kase CD V2batu
Submitted by batu1453 over 10 years ago
Ichimoku
Submitted by prashantrdx over 10 years ago
EMA System Ribbon
Submitted by yo123 over 13 years ago
Three-Bar Inside Bar Pattern
Submitted by EliStern over 13 years ago

Indicator / Formula

Copy & Paste Friendly
//Gen_BRKOUT.AFL

#include_once <LibA.afl>;

pebstime = Hour()*60+Minute();

OptimizerSetEngine("cmae");

Lastticktime = Param("Lastticktime",9999,0,9999,1); //If like in SA there is a closing tick instead of a closing bar, then we execute immediately there instead of the usual delay of 1 bar
Firsttradetime = Param("FirstTradeTime",0,0,9999,1); //Never do any trade before this time
Lasttradetime = Param("LastTradeTime",9999,0,9999,1); //Never do any trade after this time
Firstsignaltime = Param("FirstSignalTime",0,0,9999,1); //do not trade on signals that trigger before this time, remember trade is entered usually 1 bar delay after signal
Lastsignaltime = Param("LastSignalTime",9999,0,9999,1); //do not trade on signals that trigger after this time, remember trade is entered usually 1 bar delay after signal
ExitatClose = ParamToggle("Exit at Close of Day","No|Yes");
xxxdelay = 1-(pebstime>=Lastticktime)*1; //Ignore the delay when last tick, otherwise that trade will only happen next morning

firststoptime = Param("First Stoptime",0,0,9999,1);
Laststoptime = Param("Last Stoptime",9999,0,9999,1);
TradeSL = Param("Trade stoploss",99999,0,99999,1);
TradeSP = Param("Trade stopprofit",99999,0,99999,1);
DaySL = Param("Day stoploss",99999,0,99999,1);
DaySP = Param("Day stopprofit",99999,0,99999,1);
MonthSL = Param("Month stoploss",99999,0,99999,1);
MonthSP = Param("Month stopprofit",99999,0,99999,1);


n_fn1_par = Param("Channel n",20,1,100,1);
n_fn2_par = Param("Channelwidth n",2,1,10,1);

n_fn1_opt = ParamToggle("Optimize Channel n","Yes|No");
n_fn2_opt = ParamToggle("Optimize Channelwidth","Yes|No");

if (n_fn1_opt==1){
n_fn1= n_fn1_par;
}
else
{
n_fn1 = Optimize("Channel n",n_fn1_par,1,100,1);
}

if (n_fn2_opt==1){
n_fn2 = n_fn2_par;
}
else
{
n_fn2 = Optimize("Channelwidth n",n_fn2_par,1,20,0.25);
}




fn1 = ParamList("Top BRK","HHV|BOLLINGER|KELTNER|FunctionHigh");
fn2 = ParamList("Bottom BRK","LLV|BOLLINGER|KELTNER|FunctionLow");


target_fn = ParamList("TargetFn","OHLC4|O|H|L|C|ema|sma|brkema|brkema2|brkema3|brkema4|frama|kama|tsf|dema|tema|wilder|hull");
n_targetfn_par = Param("n_TargetFn",20,1,100,1);
n_TargetFn_opt = ParamToggle("Optimize n_TargetFn","Yes|No");
if (n_TargetFn_opt==1){
n_targetfn = n_TargetFn_par;
}
else
{
n_targetfn = Optimize("n_TargetFn",n_targetFn_par,1,100,1);
}


Cntxt = ParamList("Context","None|Contextfilter|Contextfilter2");

symbol = ParamStr("Basesymbol",Name());

// trade on next bar open
SetTradeDelays( 0, 0, 0, 0 );
BuyPrice = SellPrice = Open; 
ShortPrice = CoverPrice = Open;

//Points only
PositionSize = MarginDeposit = 1;

SetForeign(symbol);

switch (target_fn){

case "OHLC4":
xxx = (O+H+L+C)/4;
break;
case "O":
xxx = O;
break;
case "H":
xxx=H;
break;
case "L":
xxx=L;
break;
case "C":
xxx = C;
break;
case "ema":
xxx = EMA(C,n_targetfn);
break;
case "sma":
xxx = MA(C,n_targetfn);
break;
case "brkema":
xxx = brkema(n_targetfn);
break;
case "brkema2":
xxx = brkema2(n_targetfn);
break;
case "brkema3":
xxx = brkema3(n_targetfn);
break;
case "brkema4":
xxx = brkema4(n_targetfn);
break;
case "frama":
xxx = frama(n_targetfn);
break;
case "kama":
xxx = kama(n_targetfn,2,30);
break;
case "tsf":
xxx = TSF(C,n_targetfn);
break;
case "dema":
xxx = DEMA(C,n_targetfn);
break;
case "tema":
xxx = TEMA(C,n_targetfn);
break;
case "wilder":
xxx = Wilders(C,n_targetfn);
break;
case "hull":
xxx = HullMA(C,n_targetfn,0);
break;

}

switch (fn1){
case "HHV":
_TRACE("top hhv");
aaa = Ref(HHV(H,n_fn1),-1);
break;
case "BOLLINGER":
_TRACE("top bollinger");
aaa = BBandTop(xxx,n_fn1,n_fn2);
break;
case "KELTNER":
_TRACE("top keltner");
CenterLine = MA( xxx, n_fn1 );
aaa = CenterLine + n_fn2 * ATR( n_fn1 );
break;
case "FunctionHigh":
_TRACE("functionhigh");
aaa = Ref(HHV(xxx,n_fn1),-1);
break;

}

switch (fn2){

case "LLV":
_TRACE("bottom llv");
bbb = Ref(LLV(L,n_fn1),-1);
break;
case "BOLLINGER":
_TRACE("bottom bollinger");
bbb = BBandBot(xxx,n_fn1,n_fn2);
break;
case "KELTNER":
_TRACE("bottom keltner");
CenterLine = MA( xxx, n_fn1 );
bbb = CenterLine - n_fn2 * ATR( n_fn1 );
break;
case "FunctionLow":
_TRACE("functionlow");
bbb = Ref(LLV(xxx,n_fn1),-1);
break;

}

Buysignal = (xxx>aaa) AND (pebstime>=firstsignaltime) AND (pebstime<=Lastsignaltime);
Sellsignal = (xxx<bbb) AND (pebstime>=firstsignaltime) AND (pebstime<=Lastsignaltime) OR ((pebstime>=Lastticktime) AND ExitAtClose );

Shortsignal = (xxx<bbb) AND (pebstime>=firstsignaltime) AND (pebstime<=Lastsignaltime);
Coversignal = (xxx>aaa) AND (pebstime>=firstsignaltime) AND (pebstime<=Lastsignaltime) OR ((pebstime>=Lastticktime) AND ExitAtClose);


//is this the best spot to remove the extra signals? i think so because after contextfilters you expect and do not want to remove consecutive buy or short signals 
Buysignal = ExRem(Buysignal,Shortsignal);
Shortsignal = ExRem(Shortsignal,Buysignal);


Longstate = Flip(Buysignal,(Sellsignal OR Shortsignal));
Shortstate = Flip(Shortsignal,(Coversignal OR BuySignal));

Totalstate = Longstate*1+Shortstate*(-1);
totalstate = Ref(totalstate,-xxxdelay); //apply trade delay before applying contextfilter as contextfilters already have trade delay built in




switch (Cntxt){
case "None":
break;
case "Contextfilter":
Totalstate = Contextfilter(Totalstate);
break;
case "Contextfilter2":
Totalstate = Contextfilter2(Totalstate);
break;
}

//apply stops; delay already built in here correctly? still need to adjust for lastticktime 0 delay
totalstate = TradeSLSP(totalstate,1,tradeSL,tradeSP,firststoptime,Laststoptime,Lastticktime);
totalstate = DaySLSP(totalstate,1,DaySL,DaySP,firststoptime,Laststoptime,Lastticktime);
totalstate = MonthSLSP(totalstate,1,MonthSL,MonthSP,firststoptime,Laststoptime,Lastticktime);


Buysignal = (totalstate>0) AND (pebstime>=firsttradetime) AND (pebstime<=Lasttradetime);
Sellsignal = (totalstate<=0) AND (pebstime>=firsttradetime) AND (pebstime<=Lasttradetime);

Shortsignal = (totalstate<0) AND (pebstime>=firsttradetime) AND (pebstime<=Lasttradetime);
Coversignal = (totalstate>=0) AND (pebstime>=firsttradetime) AND (pebstime<=Lasttradetime);

Buysignal = ExRem(Buysignal,Shortsignal);
Shortsignal = ExRem(Shortsignal,Buysignal);

RestorePriceArrays();


Buy = Buysignal;
Sell = Sellsignal;

Short = Shortsignal;
Cover = Coversignal;

Longstate = Flip(Buysignal,(Sellsignal OR Shortsignal));
Shortstate = Flip(Shortsignal,(Coversignal OR BuySignal));

Totalstate = Longstate*1+Shortstate*(-1);
//this totalstate already has the trade delay in

PlotOHLC(0,0,Totalstate,Totalstate,_DEFAULT_NAME(),IIf(Totalstate<0,colorRed,colorGreen),styleCloud);
//Plot(aaa,"aaa",ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 
//Plot(bbb,"bbb",ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 


SetChartBkColor(colorBlack);

2 comments

1. balakrish

this afl not working
Gen_BRKOUT.AFL
totalstate = contextfilter(Totalstate);
break;
case"contextfilter2":
Totalstate = contextfilter2(


^
error 30.
sysntax error

2. tsunamizawa

it will not working, if you do not copy liba.afl & pebslib.afl and paste them to folder amibroker/formulas/include……

try again.

Leave Comment

Please login here to leave a comment.

Back