How to have multiple simultaneous open position in 'Same' security in amibroker.

#11
hi boufalo,

yes, both will be there, because sigScaleOut is working as Pyramiding (scaling out) on some condition while the ApplyStop is a hard stop and acts as Stop Loss.

if you are running this strategy for multiple instruments (and you want to have portfolio created amongst them) then you have to use Portfolio backtest only but if it is for single instrument (or multiple instruments but each being tested independently) then you can use either one.
thank you
i just try it but i donot understand this part in your code InTrade = Flip( Buy, Sell );

why we have to define the sell? if we are using scaleout ?
also even iif i write Sell = 0; // we do not sell
the system does not open any position

in my code i just quickly made i donot have a sell= somethink; and for that reason i have Error sell used without initialized
any idea?

can i PM to you ?
thank you
 
#13
thank you
i just try it but i donot understand this part in your code InTrade = Flip( Buy, Sell );
intrade = flip(buy,sell); // this line will make the intrade to 1 when first buy occurs and it will remain 1 for all the bars until sell has occured (if you see the e.g of exrem you will understand it is doing the opposite (thus this is used to know if we are currently in the trade (hence the name InTrade)

why we have to define the sell? if we are using scaleout ?
also even iif i write Sell = 0; // we do not sell
the system does not open any position
we need to define buy and sell for backtesting which is cardinal rule in amibroker. but ofcourse if you dont' want to use any sell logic, you can always use Sell = 0;
Sell will close all the open position while sigScaleOut will help you to close partial position. and remember it is buy = sigScaleOut (and never sell = sigScaleOut)

if you are nto getting any open position, then check the logic of buy , the timeframe, the instrument and other parameters.

in my code i just quickly made i donot have a sell= somethink; and for that reason i have Error sell used without initialized
any idea?
Didn't quite understand your problem there,
try writing sell = 0; at the top of the code and see if you still get this error, if yes, paste the whole code here, we shall see.

can i PM to you ?
thank you
ya sure, you can pm me, though I think pasting codes here and troubleshooting will help other readers (now and in future)
 
#14
boufalo

If you can afford the time please do check AB User guide (in .pdf) which is available in amibroker's site and it is a very good tool.

May I also suggest 'Introduction to Amibroker' by howard bandy and also two of his other books, (both of which uses AB as platform source and examples)
 
#15
is that amibroker.pdf has more examples that the original broker.chm?
if not i prefer to press F1 keyboard button in amibroker
as for the 'Introduction to Amibroker' yes i have to older it.
than you
 
#16
Yes, not only the pdf has more examples, it has several screen shots and much detailed explanation of several new topics.
(may be new version of AB help file does include but I haven't updated my AB in a while, so can't be sure).

have a nice learning and god speed.
 
#17
Hi iamaaditya,

Your code on scale in & scale out works great. Thanks a ton for the info.
There is one small error I get.

My scale out is actually the Low of my buysignal bar.
So It's actually a Stop Loss rather than profit exit.

When I scale out, the scale out happens on the correct bar but the scale out price shows as the open price.

Can you help me specify the scale out price .

Thanks :)




Unfortunately the applystop will close complete positionsize of the open position and there is no way to limit that to only some part but there is a nice solution to this problem.

solution is not to use applystop but to scale out, lets say you want to scale out half of the position with stoploss of 5% then

e = Equity( 1 );
PcntProfit = 100 * ( e - ValueWhen( Buy, e ) ) / ValueWhen( Buy, e );
//here PcntProfit will give the Profit % till now in the trade

stopLoss = 5; // change it to any value
InTrade = Flip( Buy, Sell );
doScaleOut = InTrade AND Cross(stopLoss, PcntProfit) ;
//above Intrade is required to remove unnecessary calculations when we are not in trade
//and the cross represents that PcntProfit has moved below stopLoss value
Buy = IIf( doScaleOut, sigScaleOut, Buy);
//I am sure you get the meaning of above line
PosSizeScaleOut = 50; //change to any % (of Position size)
SetPositionSize(IIf( Buy == sigScaleOut , PosSizeScaleOut, False ), spsPercentOfPosition);

//kindly note above Position size has been used only for sigScaleOut, generally when i use I write a combine statement which caters for both original buy position size and scale out position size
for e.g
PosSizeBuy = 30;
PosSizeScaleOut = 50;

SetPositionSize( IIf( Buy == True , PosSizeBuy ,
IIf( Buy == sigScaleOut, PosSizeScaleOut , False ) ),
IIf( Buy == True, spsPercentOfEquity,
IIf( Buy == sigScaleOut, spsPercentOfPosition, False ) ) );


let me know if this was clear , else will show you with full code e.g
 
#18
how one can limit new open positions scrip wise to 2 in amibroker.
Backtesting in intraday on a basket of FNO stocks.
Running 4 strategies want to limit max open positions in any scrip to 2.
 

Similar threads