Thanks Bruce! That was very obvious :-)
Thanks for the invariant tip too. --- In [email protected], "Bruce" <bru...@...> wrote: > > Think this might be quick so I'll take it. > > Pass the price on that bar/day by using an indexer to get a scalar - > > bo.EnterTrade(i, "BATS", True, LpairPrice[ i ], -20); > > BTW, you might want to get the invariant outside the loop. > IOW, move the Foreign() call outside of the "i" loop. > > > --- In [email protected], "necroboy2" <blair.anson@> wrote: > > > > Hi All, I'm getting Error 19 when I try to call EnterTrade for a > > predefined symbol. I would appreciate if someone could please tell me > > I'm an idiot for missing something obvious in the following...... > > In CBT we typically have this type of code which places a trade on the > > currently obtained signal, but if I also want to enter a long trade on > > the symbol "BATS" whenever a short entry is made then the line > > highlighted in yellow should do the trick. However its giving me an > > Error 19.Any suggestions? > > 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() && > > sig.IsLong()) // Process long entries > > bo.EnterTrade(i, sig.Symbol, sig.IsLong(), sig.Price, sig.PosSize); > > else { // Process long exits > > if (sig.IsExit() && sig.IsLong()) > bo.ExitTrade(i, > > sig.Symbol, sig.Price); } > > // Process short entries if (sig.IsEntry() > && > > !sig.IsLong()) { bo.EnterTrade(i, > > sig.Symbol, sig.IsLong(), sig.Price, sig.PosSize); > > LpairPrice = Foreign("BATS", "C"); > > // HERE is where I get Error 19. COM method/function > > 'EnterTrade' call failed bo.EnterTrade(i, "BATS", True, > > LpairPrice, -20); } else { > > if (sig.IsExit() && !sig.IsLong()) // Process short exits > > bo.ExitTrade(i, sig.Symbol, sig.Price); } > > } // End of for loop over signals at this bar > > bo.HandleStops(i); // Handle programmed stops at this bar > > bo.UpdateStats(i, 1); // Update MAE/MFE stats for bar > > bo.UpdateStats(i, 2); // Update stats at bar's end } // End of > > for loop over bars bo.PostProcess(); // Do post-processing} > > > > > > // Simple trade rules for this exampleBuy = Cross( MA(C,5), MA(C,20) > > );Sell = Cross( MA(C,20), MA(C,5) ); > > Short = Cross( MA(C,30), MA(C,10) );Cover = Cross( MA(C,10), MA(C,30) > ); > > >
