Hi,

I am trying to test a simple MA Cross over system that uses Buy-Stop and 
Sell-Stop orders. I can't for the life Of me workout how this should work.

What I want the system to do is only trade between the 'tstart' & 'tend' 
parameter. When there is a MA-Cross set a BuyStop or Sell stop order at the 
High/Low of the bar where the MA-Cross ocurred, so the trade is only entered 
when the stop order is taken out.

I would be very gratefull if someone can take a look at my code below and point 
me in the right direction to get this to work.

Thanks,
Pete

//
   //+------------------------------------------------------------------+
   //| Variable/Parameters Start                                        |
   //+------------------------------------------------------------------+
//      Set up the lengths for the moving averages
Length1    = Param("Fast MA",3,1,20,1);
Length2    = Param("Slow MA",30,21,80,1);
// Trade Times
tstart     = 070000; 
tend       = 150000; 
time_valid = TimeNum() >= tstart AND TimeNum() <= tend; 

   //+------------------------------------------------------------------+
   //| Buy Sell Logic                                                   |
   //+------------------------------------------------------------------+
MA1 = MA(C,Length1);
MA2 = MA(C,Length2);

Buy   = Ref(Cross(MA1,MA2),-1) AND time_valid;
Short = Ref(Cross(MA2,MA1),-1) AND time_valid;
Sell = Short;
Cover = Buy;

BuyStop  = Ref(H,-1);
SellStop = Ref(L,-1);

BuyPrice  = Max( BuyStop, Low ); // make sure buy price not less than Low 
SellPrice = Min( SellStop, High ); // make sure sell price not greater than 
High 

Buy  = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

Reply via email to