[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: One Trade per Month


  • Date: Fri, 19 Feb 2010 23:45:52 -0000
  • From: "Mike" <sfclimbers@xxxxxxxxx>
  • Subject: [amibroker] Re: One Trade per Month

PureBytes Links

Trading Reference Links



I was trying to say that you can substitute the code snippets that I gave into the original code that you copied from (i.e. replace the newDay array with a newWeek or newMonth array).

Below is a complete working program for your example strategy. Comment out the weekly setting and uncomment the monthly setting to see it applied to a monthly restriction. Look at the Trace tab in the Log window to see the output.

Required reading would be

SetTradeDelays(0, 0, 0, 0);
SetPositionSize(2, spsPercentOfEquity);

FastMA =
MA(Close, 5);
SlowMA =
MA(Close, 10);

Buy = Cross(FastMA, SlowMA);
BuyPrice = Close;

Sell = Cross(SlowMA, FastMA);
SellPrice = Close;

SetCustomBacktestProc("");

if (Status("action") == actionPortfolio) {
   
_TRACE("Begin custom backtest");

   bo =
GetBacktesterObject();
   bo.PreProcess();

   
/* Weekly */
   weekDays =
DayOfWeek();
   newPeriod = weekDays <
Ref(weekDays, -1);

   
/* Monthly
   months = Month();
   newPeriod = months != Ref(months, -1);
   */


   dates =
DateTime();
   hadTradeThisPeriod =
False;

   
for (i = 0; i < BarCount; i++) {
      
if (newPeriod[i]) {
         
_TRACE("");
         
_TRACE("Begin new period.");
         hadTradeThisPeriod =
False;
      }

      
_TRACE("Bar: " + i + ", " + NumToStr(dates[i], formatDateTime));

      
for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i)) {
         
if (sig.IsEntry() && sig.IsLong()) {
            
if (hadTradeThisPeriod) {
               sig.PosSize =
0;
               
_TRACE("  Skipped signal for " + sig.Symbol);
            }
else {
               hadTradeThisPeriod =
True;
               
_TRACE("  Accepted signal for " + sig.Symbol);
            }
         }
      }

      bo.ProcessTradeSignals(i);
   }

   bo.PostProcess();
}

Mike
--- In amibroker@xxxxxxxxxxxxxxx, "readshark" <readshark@xxx> wrote:
>
> Mike,
>
> Maybe I just do not know how to implement your code, but I do not understand what to do with it.
>
> If you just had a simple MA Crossover script like:
>
> Buy = Cross(FastMA, SlowMA);
> Sell = Cross(SlowMA, FastMA);
>
> How would you implement your code into this?
>
> Thank you for your patience.
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Mike" sfclimbers@ wrote:
> >
> > Weekly:
> >
> > weekDays = DayOfWeek();
> > newWeek = weekDays < Ref(weekDays, -1);
> >
> > Monthly:
> >
> > months = Month();
> > newMonth = months != Ref(months, -1);
> >
> > Mike
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "readshark" <readshark@> wrote:
> > >
> > > I am looking to add some code to one of my trading systems to limit the number of trades to x amount per week.
> > >
> > > I found a code that here that would limit the trades to one per day. Any idea how I alter this to only get one trade on a longer time frame, preferably a week?
> > >
> > > Thank you in advance.
> > >
> > > Here is the link and the code I found. -> http://www.mail-archive.com/amibroker@xxxxxxxxxxxxxxx/msg23006.html
> > >
> > > for (i = 0; i < BarCount; i++)
> > > {
> > > if (newDay[i])
> > > hadTradeToday = False;
> > > for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i))
> > > {
> > > if (sig.IsEntry() && sig.IsLong())
> > > {
> > > if (hadTradeToday)
> > > sig.PosSize = 0;
> > > else
> > > hadTradeToday = True;
> > > }
> > > }
> > > bo.ProcessTradeSignals(i);
> > > }
> > >
> >
>


__._,_.___


**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___