- Joined
- 24 October 2005
- Posts
- 1,302
- Reactions
- 834
Hi,
first-time post
But I can only get the above example to work if I have the whole function as inline code directly above the call. Clearly this is not the intention. What am I doing wrong? How/where do I save the function so that it is found by a call in another piece of code?
Hi
I am looking to switch all my symbols from "Use local database only" property for all my symbols, i found this post
http://www.amibroker.com/kb/2006/09/01/how-to-change-property-for-multiple-symbols-at-once/
but i can't get that code to run, i also saw some people comment and said there was an issue with the code, can anybody point me in the right direction?
Thanks
Why not just go to database settings and do it manually?
I just found what you were talking about, thank for the tip!
This should work
SetPositionSize( 100, spsPercentOfEquity );
SetBacktestMode( backtestRegular ); //signal-based backtest, redundant signals are removed
BuyPrice = SAR() + 0.01;
SellPrice = SAR() - 0.01;
Buy = Buyprice>=l and Buyprice<=h and cross(C,SAR());
Sell =Sellprice>=l and Sellprice<=h and cross(SAR(), C);
buy = ExRem( buy, sell );
sell = ExRem( sell, buy );
This should work
SetPositionSize( 100, spsPercentOfEquity );
SetBacktestMode( backtestRegular ); //signal-based backtest, redundant signals are removed
BuyPrice = SAR() + 0.01;
SellPrice = SAR() - 0.01;
Buy = Buyprice>=l and Buyprice<=h and cross(C,SAR());
Sell =Sellprice>=l and Sellprice<=h and cross(SAR(), C);
buy = ExRem( buy, sell );
sell = ExRem( sell, buy );
This should work
SetPositionSize( 100, spsPercentOfEquity );
SetBacktestMode( backtestRegular ); //signal-based backtest, redundant signals are removed
BuyPrice = SAR() + 0.01;
SellPrice = SAR() - 0.01;
Buy = Buyprice>=l and Buyprice<=h and cross(C,SAR());
Sell =Sellprice>=l and Sellprice<=h and cross(SAR(), C);
buy = ExRem( buy, sell );
sell = ExRem( sell, buy );
Hi, may I know these:
1. I think C in cross(C,SAR() means using close price to do the cross, if I use cross(Open,SAR()). then I use the open price to compare with the SAR at the open price right? I guess SAR in amibroker would not always use the close SAR even I do the (Open, SAR())?
2. Even I do SetBacktestMode( backtestRegular );, I still need to do the EXRem? What does the EXRem really do?
Thx!
I am still very confused that does the "C" in cross(C,SAR()); means current price or close...
If I want to just buy when the SAR cross within the price between day high and low (which is all possible price within that day), does it make sense to have cross(C,SAR());? Is there a way to use the "current price" for this concept?
thx!
- - - Updated - - -
I just backtest these codes..no trades for 15 years data...something wrong....
My code (above) had an error. I specified Close>SAR(), but also specified a buyprice. So I was asking AB to buy intra-day before the closing price was known. It looked into the future. Just remove the buyprice and sellprice lines.
It's been so long since you've posted I can't remember what it was you were wanting to do.
As joshmi says, C is either the close or the last price (if calculated intra-day).
hi and thx. I asked you before how to do these:
How to change this AFL codes to
Sell =(SAR() > C) + "only sell if the price is higher than the bought price"?
You told me to try sellPrice>BuyPrice;
Here is my code:
Buy = BuyPrice>=L AND BuyPrice<=H AND Cross(Open,SAR());
Sell =SellPrice>=L AND SellPrice<=H AND Cross(SAR(), Open) AND SellPrice>BuyPrice;
BuyPrice = Open;
SellPrice = Open;
SetPositionSize( 100, spsPercentOfEquity );
SetBacktestMode( backtestRegular );
then it only bought once then never sold in 15 years of data
SetPositionSize( 10, spsPercentOfEquity );
acc = 0.02;
accm = 0.2;
sarc = SAR( acc, accm );
Buy = Sell = 0;
Short = Cover = 0;
YourBuyConditions = SARc < C;
YourSellConditions = SARc > C;
priceatbuy = Null;
patba = Null; // Price At Buy Array (for plotting only)
for ( i = 0; i < BarCount; i++ )//
{
SellSignal = YourSellConditions[ i ] AND Close[ i ] > priceatbuy;
if ( SellSignal AND NOT IsNull( priceatbuy ) )
{
Sell[ i ] = 1;
priceatbuy = Null;
}
BuySignal = YourBuyConditions[ i ];
if ( IsNull( priceatbuy ) AND BuySignal )
{
Buy[ i ] = 1;
priceatbuy = BuyPrice[ i ];
}
patba[ i ] = priceatbuy; // to plot you need an ARRAY, not scalar
}
_SECTION_BEGIN("Price");
SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%), Vol %g {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ) );
Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle(), 0, 1, 0, 0);
_SECTION_END();
Plot( patba, "priceatbuy", colorGreen, styleDots | styleNoLine, 0, 1, 0, 1 );
Plot( SARc, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle( "Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
PlotShapes( Sell*shapeDownArrow, colorRed, 0, H, -15 );
PlotShapes( Sell*shapeHollowDownArrow, colorWhite, 0, H, -15 );
PlotShapes( Sell*shapeHollowSmallCircle, colorRed, 0, SellPrice, 0 );
Has already been discussed here.
One of million ways:
Code:SetPositionSize( 10, spsPercentOfEquity ); acc = 0.02; accm = 0.2; sarc = SAR( acc, accm ); Buy = Sell = 0; Short = Cover = 0; YourBuyConditions = SARc < C; YourSellConditions = SARc > C; priceatbuy = Null; patba = Null; // Price At Buy Array (for plotting only) for( i = 0; i < BarCount; i++ )// { SellSignal = YourSellConditions[ i ] AND Close[ i ] > priceatbuy; if( SellSignal AND NOT IsNull( priceatbuy ) ) { Sell[ i ] = 1; priceatbuy = Null; } BuySignal = YourBuyConditions[ i ]; if( IsNull( priceatbuy ) AND BuySignal ) { Buy[ i ] = 1; priceatbuy = BuyPrice[ i ]; } patba[ i ] = priceatbuy; // to plot you need an ARRAY, not scalar } Plot(patba, "priceatbuy", colorGreen, styleLine ); Plot( SARc, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
What do you mean? Show an example.
SetPositionSize( 100, spsPercentOfEquity );
acc = 0.02;
accm = 0.2;
sarc = SAR( acc, accm );
Buy = Sell = 0;
Short = Cover = 0;
YourBuyConditions = SARc < Open;
YourSellConditions = SARc > Open;
priceatbuy = Null;
patba = Null; // Price At Buy Array (for plotting only)
for( i = 0; i < BarCount; i++ )//
{
SellSignal = YourSellConditions[ i ] AND Open[ i ] > priceatbuy;
if( SellSignal AND NOT IsNull( priceatbuy ) )
{
Sell[ i ] = 1;
priceatbuy = Null;
}
BuySignal = YourBuyConditions[ i ];
if( IsNull( priceatbuy ) AND BuySignal )
{
Buy[ i ] = 1;
priceatbuy = BuyPrice[ i ];
}
patba[ i ] = priceatbuy; // to plot you need an ARRAY, not scalar
}
BuyPrice = Open;
SellPrice = Open;
Plot(patba, "priceatbuy", colorGreen, styleLine );
Plot( SARc, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
SetPositionSize( 10, spsPercentOfEquity );
delay = 1;
SetTradeDelays( delay, delay, delay, delay );
acc = 0.02;
accm = 0.2;
sarc = SAR( acc, accm );
Buy = Sell = 0;
Short = Cover = 0;
BuyPrice = SellPrice = Open;
YourBuyConditions = SARc < C;
YourSellConditions = SARc > C;
priceatbuy = Null;
patba = Null; // Price At Buy Array (for plotting only)
for ( i = 1; i < BarCount; i++ )//
{
SellSignal = YourSellConditions[ i - 1 ] AND Close[ i - 1 ] > priceatbuy;
if ( SellSignal AND NOT IsNull( priceatbuy ) )
{
Sell[ i - 1 ] = 1;
priceatbuy = Null;
}
BuySignal = YourBuyConditions[ i - 1 ];
if ( IsNull( priceatbuy ) AND BuySignal )
{
Buy[ i - 1 ] = 1;
priceatbuy = BuyPrice[ i ];
}
patba[ i ] = priceatbuy; // to plot you need an ARRAY, not scalar
}
_SECTION_BEGIN("Price");
SetChartOptions( 0, chartShowArrows | chartShowDates | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%), Vol %g {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ), V ) );
Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle(), 0, 1, 0, 0);
_SECTION_END();
Plot( patba, "priceatbuy", colorGreen, styleDots | styleNoLine, 0, 1, 0, 1 );
Plot( SARc, _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle( "Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );
PlotShapes( Buy*shapeUpArrow, colorGreen, 0, H, -15 );
PlotShapes( Buy*shapeHollowUpArrow, colorWhite, 0, H, -15 );
PlotShapes( Ref(Buy, -1)*shapeHollowSmallCircle, colorGreen, 0, BuyPrice, 0 );
PlotShapes( Sell*shapeDownArrow, colorRed, 0, H, -15 );
PlotShapes( Sell*shapeHollowDownArrow, colorWhite, 0, H, -15 );
PlotShapes( Ref(Sell, -1)*shapeHollowSmallCircle, colorRed, 0, SellPrice, 0 );
Hi,
I'm new to AmiBroker and have an AFL related question someone can hopefully help me with (I have searched the forum but could not find an answer to my question).
In addition to the system 'Sell' condition I would like to add a time-based Exit, e.g.,
Sell = ConditionXYZ OR BarsSince(Buy) >= 10;
The problem is that buy signals following entry re-set the 'BarsSince(Buy)' time-frame. I would like to remove the extra buy signals, the problem is that 'Buy = ExRem(Buy,Sell);' does not seem to remove the signals? (i.e., it does remove supefluous arrows on the chart, however when checking backtesting results there are still many trades well in excess of the time-limit).
...
Any ideas?
Hi,
I'm new to AmiBroker and have an AFL related question someone can hopefully help me with (I have searched the forum but could not find an answer to my question).
In addition to the system 'Sell' condition I would like to add a time-based Exit, e.g.,
Sell = ConditionXYZ OR BarsSince(Buy) >= 10;
The problem is that buy signals following entry re-set the 'BarsSince(Buy)' time-frame. I would like to remove the extra buy signals, the problem is that 'Buy = ExRem(Buy,Sell);' does not seem to remove the signals? (i.e., it does remove supefluous arrows on the chart, however when checking backtesting results there are still many trades well in excess of the time-limit).
I'm assuming the way around this involves writing a Loop.
HoldBars = 10;
Sell = ConditionXYZ OR ExRemSpan( Ref( Buy, -HoldBars ), HoldBars );
Hello,
It can be done without loops too.
However ApplyStop is recommended as it handles all cases and works fine together with other stops.
Best regards,
Tomasz Janeczko
amibroker.com
No, there is no problem. And it can be done without loop and without ApplyStop.
In your case
Code:HoldBars = 10; Sell = ConditionXYZ OR ExRemSpan( Ref( Buy, -HoldBars ), HoldBars );
But Tomasz recommends using Applystop
ExRem(); is only needed for removing excessive signals in charts or exploration/scan. Backtester takes care of it itself. In addition there you have function SetBacktestMode available.
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?