Hello, i am working on 5 mins bars and i want my code to buy 5% from multiple bars till it reach 50000$ then it should sell and it can't sell before it bought all the amount or if the day ended.
Here is part of my code.
my problem is i don't know how to keep buying till i reach the 50000$.
Hi, so i have been trying out to understand the codes from the CBT but my code still doesn't work,
What i want to do is that it should buy from multiple tickers (5 minutes) till it bought with a money amount of 50000, and if it reach that value or the day ends it should wait for the next sell signal to sell all , then it should start all over again
PositionSize = -5;
setCustomBacktestProc("");
if (Status("action") == actionPortfolio)
{
bo = GetBacktesterObject(); // Get backtester object
bo.PreProcess(); // Do pre-processing
for (i = 0; i < BarCount; i++) // Loop through all bars
{
for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i))
{ // Loop through all signals at this bar
if (sig.IsEntry()) // If this signal is a long entry (ie. buy)
{
evol = Foreign("~evol_"+sig.Symbol, "V"); // Get stock's composite volume array
psize = sig.PosSize; // Get position size specified in AFL code
if (psize < 0) // If it's negative (a percentage of equity)
psize = (-psize/100) * evol; // Convert to dollar value using current equity
scnt = psize / sig.Price; // Calculate number of shares for position size
psize = scnt * sig.Price; // Calculate new position size
D = IIf (Day()!= Ref(Day(), -1),1,0);
if (bo.Equity - bo.Cash >= 50000 OR D[i] > 1) // If position size is greater than $50,000
{
psize = 0;
Buy[i] = 0;
}
else
{
Sell[i] = 0;
}
sig.PosSize = psize; // Set modified position size back into object
}
else
{
Buy[i] = 0;
}
} // End of for loop over signals at this bar
bo.ProcessTradeSignals(i); // Process trades at this bar
} // End of for loop over bars
bo.PostProcess(); // Do post-processing
}
@mennatareeq what free version? The free 30 day trial version? You have been a member of this forum for 13 months, how is your version "free"? Also the forum is for support of version 6.0 and later. The forum users are paying to ensure future updates, improvements and development of the software. Why would they support you if you refuse to support the community.