Forum Replies Created
-
AuthorPosts
-
Stephen JamesMember
Said, the EnableRotationalTrading() function is now obsolete. Just use SetBacktestMode( backtestRotational ) as they do the same thing apparently.
Stephen JamesMemberThat looks fine Said – set time frame, then restore as you have done. I’m guessing you added the TimeFrameCompress line for plotting?
Stephen JamesMemberI agree with Said that at the beginning it is good to practice writing code as repetition will aid memory retention. I believe there are more than 350 built in functions alone so we are not going to remember them all, but you will gain exposure to the most common ones, which we’ve tried to cover in the course. Just remember Julian, you have just started and it does get a lot easier.
My coding started about 6-7 years ago with explorations for discretionary setups, some custom indicators, then onto systems. Having said the above, I now use snippets or templates constantly so I’m not reinventing the wheel. I also refer to the user guide regularly to check on code that I may not have used before or for a while.
If I get stuck on a concept, usually within 1-2 hours of trying out my initial thoughts, I find the best thing to do in many cases is to ‘walk away’. You’d be amazed at how many coding concepts I solve when not at the computer. Horses for courses there perhaps!
Stephen JamesMemberTry creating two entries in the looping, the second using sigscalein as the Buy.
I just did the example below on the fly – it may need some tweaking..
Code:for (j = 1; j < BarCount; j++) { if (LPriceAtBuy==0 AND LE[j]) { Buy[j] = True; LPriceAtBuy = LEPrice[j]; BuyPrice[j] = LEPrice[j]; LBIT[j] = 1; if (LPriceAtBuy==0 AND LE2[j]) { Buy[j] = SigScaleIn; BuyPrice[j] = LEPrice2[j]; } } //Then for position sizing something along these lines:- SetPositionSize( 50, spsPercentOfEquity ); SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleIn ) );Stephen JamesMemberdo mean to scale in Oliver? e.g. buy 50% of position at first limit, rest at second?
Stephen JamesMemberYou’d have to use the custom backtester. Try this link:-
http://www.amibroker.com/kb/2006/03/06/re-balancing-open-positions/
Stephen JamesMemberI understand you can code an equity curve MA against a single symbol in AB, but not portfolio equity (in standard backtest mode at least).
Stephen JamesMemberI very much doubt that is possible in AmiBroker from a coding / testing perspective.
Stephen JamesMemberRounded tick sizes for ASX (US can just use 0.01 for tick) for Buy Limit Orders. Other rounding options are ‘floor’ or ‘ceiling’ (search user guide).
Code:Tick = IIf(OrderPrice<0.10,0.001,IIf(OrderPrice<2.00,0.005,0.01));
BuyLimVal = round(OrderPrice/Tick);
BuyLimit = BuyLimVal * Tick;Stephen JamesMemberTemplate for an ‘n’ Bar Exit (or stale exit). Designed to use with other exits so FlagExit can be used for the exploration and plotting of exit signals.
Code:ExitBars = Param(“# Exit Bars”,5,2,100,1);//=================================================================================
//Looping
//=================================================================================
Buy = 0;
Sell = 0;
PriceAtBuy = 0;
LBIT = 0;
FlagExit = 0;
//=================================================================================
for (j = 1; j < BarCount; j++) { if (PriceAtBuy==0 AND LE[j]) { Buy[j] = True; PriceAtBuy = LEPrice[j]; BuyPrice[j] = LEPrice[j]; LBIT[j] = 1; } else if (PriceAtBuy > 0)
{
LBIT[j] = LBIT[j-1]+1;if (LBIT[j] == ExitBars)
{
FlagExit[j] = True;
}if (LBIT[j] > ExitBars)
{
Sell[j] = True;
SellPrice[j] = Open[j];
PriceAtBuy = 0;
}
}
}Stephen JamesMemberNot that I’m aware of Oilver
Stephen JamesMemberThis may help:-
Setoption(AllowPositionShrinking,True);
or select the setting in the Analyser General tab.
Either will allow partial positions
Stephen JamesMemberIs the residual balance enough for a full position at that time?
Stephen JamesMemberBreakeven Trail Stop looping
Code:Buy = 0;
Sell = 0;
LStop = Null;
PriceAtBuy = 0;
LBIT = 0;
BELevel = Null; //initiated to Nullfor (j = 1; j < BarCount; j++) { if (PriceAtBuy==0 AND LE[j]) { Buy[j] = True; BuyPrice[j] = Open[j]; PriceAtBuy = BuyPrice[j]; LStop[j] = Max(TrailStop[j-1],TrailStop[j]); LStop[j-1] = TrailStop[j-1]; BELevel[j] = PriceAtBuy; //assign PriceAtBuy which contains the BuyPrice to the array LBIT[j] = 1; if (LBIT[j]==1 AND L[j] <= LStop[j-1]) { Sell[j] = True; SellPrice[j] = Min(Open[j],LStop[j-1]); PriceAtBuy = 0; } } else if (PriceAtBuy > 0)
{
LBIT[j] = LBIT[j-1]+1;if (LBIT[j]>1)
{
LStop[j] = Max(LStop[j-1],TrailStop[j]);
BELevel[j] = BELevel[j-1]; //continuation of the array
}if (LBIT[j]>1 AND Close[j] > (BELevel[j-1]*1.1)) //condition to move stop to BE
{
LStop[j] = Max(LStop[j],BELevel[j-1]); //stop reset to continue higher
}if (LBIT[j]>1 AND L[j] <= LStop[j-1]) { Sell[j] = True; SellPrice[j] = Min(Open[j],LStop[j-1]); PriceAtBuy = 0; } } }
Stephen JamesMemberPosition Sizing Options – Long and Short system
Code:LRiskAmnt = P – LIS; //Price minus Long Initial stop
SRiskAmnt = SIS – P; //Short Initial stop minus Price
“”;
“Position Sizing Method:”;
PosSizeMethod = ParamList(“Position Sizing Method:”,”Fixed Fractional Risk %|Fixed $ Risk Amount|Fixed $ Total Position Size|Fixed % of Portfolio Equity”,0);//Fixed Fractional Risk Percentage
Risk1Pcnt = Param(“Fixed Fractional Risk %”,1,0.01,5,0.01);
Risk1 = IIf(Buy,Risk1Pcnt*Ref(P,-1)/Ref(LRiskAmnt,-1),Risk1Pcnt*Ref(P,-1)/Ref(SRiskAmnt,-1));
//Fixed $ Risk Amount
Risk2Amnt = Param (“Fixed $ Risk Ammount”,1000,1,100000,100);
Risk2 = IIf(Buy,Risk2Amnt*Ref(P,-1)/Ref(LRiskAmnt,-1),Risk2Amnt*Ref(P,-1)/Ref(SRiskAmnt,-1));
//Fixed $ Position Size
FDAmount = Param (“Fixed $ Total Position Size”,5000,100,100000,100);
//Fixed % of Portfolio Equity
FPAmount = Param(“Fixed % of Portfolio Equity”,5,1,100,1);if(PosSizeMethod == “Fixed Fractional Risk %”) SetPositionSize(Risk1,spsPercentOfEquity);
if(PosSizeMethod == “Fixed $ Risk Amount”) SetPositionSize(Risk2,spsShares);
if(PosSizeMethod == “Fixed $ Total Position Size”) SetPositionSize(FDAmount,spsValue);
if(PosSizeMethod == “Fixed % of Portfolio Equity”) SetPositionSize(FPAmount,spsPercentOfEquity); -
AuthorPosts