for(current_trades) { ... }

A for loop that cycles through all open and pending trades with the current asset and algo.

for(open_trades) { ... }

A for loop that cycles through all open, pending, and pool trades of all assets and algos.

for(all_trades) { ... }

A for loop that cycles through all open, pending, and closed trades; useful for a detailed trade statistic after the simulation.

Type:

Macro

Remarks:

Example:

// find all pending trades with the current asset
int numPending(bool isShort)
{
  string CurrentAsset = Asset;
  int num = 0;
  for(open_trades)
    if(strstr(Asset,CurrentAsset) 
      && TradeIsPending && TradeIsShort == isShort)
        num++;
  return num;
}
 
// sum up the profit/loss of all open trades with the current asset
var val = 0;
string CurrentAsset = Asset;
for(open_trades)
  if(strstr(Asset,CurrentAsset) && TradeIsOpen && !TradeIsPhantom)
    val += TradeProfit;

// increase the stop of all winning trades slowly over time
for(open_trades) {
if(TradeProfit > 0 && !TradeIsPool)
TradeStopLimit -= 0.02 * TradeStopDiff;
}
// lock 80% profit of all winning trades for(open_trades) { if(TradeIsOpen && !TradeIsPool && TradeProfit > 0) { TradeTrailLock = 0.80; if(TradeIsShort) TradeTrailLimit = max(TradeTrailLimit,TradePriceClose); else TradeTrailLimit = min(TradeTrailLimit,TradePriceClose); } }

See also:

bar, enterLong/Short, trade variables

 

► latest version online