It's my first post, so I want say Hello, from Poland
I have a little question. Is possible set position size of 10% equity by not less than 1600? (damn high provision)
e.g
Initial Equity: 10000
max open positions: 5 or whatever
In my code I set:
SetPositionSize( 10, spsPercentOfEquity ); thats great but how set no less than 1600?
SetCustomBacktestProc("");
if ( Status( "action" ) == actionPortfolio )
{
// retrieve the interface to portfolio backtester
bo = GetBacktesterObject();
bo.PreProcess();
for ( bar = 0; bar < BarCount; bar++ )
{
// this retrieves current value of portfolio-level equity
eq = bo.Equity;
// this for loop iterates through all trade signals and adjust pos size
for ( sig = bo.GetFirstSignal( bar ); sig; sig = bo.GetNextSignal( bar ) )
{
// set 10% of equity but minimum 1600
sig.PosSize = Max( 0.1 * eq, 1600 );
}
bo.ProcessTradeSignals( bar );
}
bo.PostProcess();
}
I have not tested it but maybe the following one could work too:
Code:PositionSize = Max( -10, 1600 );
Upper one doesn't work. So use the other (CBT) one. That one definitely works
_SECTION_BEGIN( "test" );
SetBarsRequired( 1000, 0 );
percent = 10;//Param( "TS %", 10, 1, 200, 1 );
sr = MA( C, 150 );
//Stochastic
slow = StochD( 15, 3, 3 );
quick = StochK( 15, 3 );
// Buy and Sell
Buy = slow > 20 AND Ref( slow, -1 ) < 20 AND sr > Ref( sr, -1 );
Sell = 0;
Short = Cover = 0;
// Stop Loss
StopLevel = 1 - percent / 100;
trailArray = Null;
trailstop = 0;
for ( i = 1; i < BarCount; i++ )
{
if ( trailstop == 0 AND Buy[i] )
{
trailstop = High[i] * stoplevel;
}
else Buy[i] = 0;
if ( trailstop > 0 AND Low[i] < trailstop )
{
Sell[i] = 1;
SellPrice[i] = trailstop;
trailstop = 0;
}
if ( trailstop > 0 )
{
trailstop = Max( High[i] * stoplevel, trailstop );
trailArray[i] = trailstop;
}
}
if ( Status( "actionex" ) == actionIndicator )
{
Buy = ExRem( buy, sell );
Sell = ExRem( sell, buy );
GraphXSpace = 5;
SetChartOptions( 0, chartShowDates | chartShowArrows | chartWrapTitle );
Plot( C, "Price", colorDefault, GetPriceStyle() );
Plot( sr, "Srednia kroczaca", ParamColor( "Color", colorViolet ), ParamStyle( "Style" ) );
dist = 15;
PlotShapes( Buy*shapeUpArrow, colorBlue, 0, L, -dist );
PlotShapes( Sell*shapeDownArrow, colorOrange, 0, H, -dist );
Plot( trailArray, "trailing stop level", colorRed );
}
_SECTION_END();
period1=20;
period2=10;
period1=Param("Maxperiod",20,20,60,5);
period2=Param("Minperiod",10,10,20,5);
HighChannel=Ref(HHV(H,period1),-1);
LowChannel=Ref(LLV(L,period2),-1);
Buy = Close >= Highchannel;
Sell = Close <= Lowchannel;
Is it possible to build an array composed of a combination of the high and low of each bar?
Example (for last 3 bars) - original data in 2 separate arrays, H & L:
H: 1.02, 1.04, 1.01
L: 0.98, 0.99, 0.94
Composed into a new array:
X: 1.02, 0.98, 1.04, 0.99, 1.01, 0.94
Cheers
Thanks for the reply Howard. I want to find the median value of the last n-bar Highs and Lows. I suspect this will involve a loop of some sort. I found a .dll plugin through a Google search but couldn't get AB to recognise it.
SYNTAX Median( array, period )
RETURNS ARRAY
FUNCTION The Median function - finds median (middle element) value of the array over period elements. Note that LOWER median is returned when 'period' is an even number. If you want to get average of upper and lower median for even 'periods' you need to use Percentile( array, period, 50 ) instead. It will do the averaging for you but runs slower.
EXAMPLE // list only symbols which volume is greater than
// median Volume from past 50 days
Filter = Volume > Median( Volume, 50 );
AddColumn( V, "Volume" );
SEE ALSO Percentile() function
AmiBroker has a median function
Yes but it only works on a single array. I need to find the median of two arrays of data combined.
If you could be more specific as to how you visualise the array then I could learn too. Is your X: example leading to a sum of H + L, a sum of H or a sum of L or not a sum? One combination of the H & L of each bar is H + L / 2.Is it possible to build an array composed of a combination of the high and low of each bar?
Example (for last 3 bars) - original data in 2 separate arrays, H & L:
H: 1.02, 1.04, 1.01
L: 0.98, 0.99, 0.94
Composed into a new array:
X: 1.02, 0.98, 1.04, 0.99, 1.01, 0.94
Cheers
The median of a finite list of numbers can be found by arranging all the observations from lowest value to highest value and picking the middle one (e.g., the median of {3, 3, 5, 9, 11} is 5).
_SECTION_BEGIN("Median Bar Values");
BarPeriod = Param("Bar Median Period", 3, 1, 100, 1);
OpenValueMed = Median(Open, BarPeriod);
HighValueMed = Median(High, BarPeriod);
LowValueMed = Median(Low, BarPeriod);
CloseValueMed = Median(Close, BarPeriod);
ColorPlot = IIf(OpenValueMed > Ref(OpenValueMed, -1), colorYellow, colorBlack);
PlotOHLC(OpenValueMed, HighValueMed, LowValueMed, CloseValueMed, "OHLC 3 Bar Median", ColorPlot, styleBar);
_SECTION_END();
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?