for ( i = BarCount - from; i < BarCount;i++ ) {
// if (some condition) Buy[i];
}
For Positionsize I use e.g. : SetPositionSize( 1, spsShares ) to use exactly one share.
If I want on some bars(not on all) and Buy-Signals use 2 shares and then one again, how can I code this?
@htrader,
First of all please read here.
It is mandatory in this forum to apply code tags if inserting code.
I'm just reminding because in your other post of few hours ago they are missing too.
It is very easy to apply code tags and it is applied very quickly.
Secondly as for your loop...
Do not do this
i = BarCount - from;
Read here as for not making assumptions on number of bars.
Also ask yourself whether you really need loop at all.
Reminder to be found here.
Hi, thank you for this quick reply and for the tips for inserting afl-code.
I need exactly this from travick, but not only with the buy/sell signals, i need to set the positionssize within a loop through the bararray. I know, the better and faster way is to use the array.
I found my answer, when i combine both replies. My problem was the understanding, that I can on the one hand directly set a buy-signal with buy[i]=1, sell, short...and so on, but for the positionsize I cannot do this directly in the loop, I need a "helper array".
The code has to be like this:
for ( i = 0; i < BarCount;i++ )
{
if ( buycondition )
{
if ( buycond2 )
{
Buy[i] = 1;
Lot_size_helper[i] = 2;
}
else
{
Buy[i] = 1;
Lot_size_helper[i] = 1;
}
}
}
// For Backtest
SetPositionSize( Lot_size_helper, spsShares );