hi Ravi,

some code below. This code does not do a backtest (although I added some 
necessary ingredients) since you did not define where your exits need to be but 
will get you started.


/* 
how does one write a formula and which also gives visual buy and 
sell arrows, and also runs for a back test......buy when 13 period 
EMA crosses 21EMA on close (completed candle) of a 1 minute chart 
with a condition that the 21 minute EMA of a 5 minute chart should 
be above 13 EMA in 5 mins chart. 
*/ 

SetBarsRequired(10000,10000); 
SetTradeDelays(0,0,0,0); 

SetOption("CommissionMode", 3); 
SetOption("CommissionAmount", 2.75); 
SetOption("FuturesMode",True); 
NumContracts = 1; 
PositionSize = NumContracts * MarginDeposit; 

starttime = 153000; 
endtime = 220000; 
timearray = TimeNum() >= starttime AND TimeNum() <= endtime; 

per1 = 13; 
per2 = 21; 

Aema1 = EMA(C,per1); 
Aema2 = EMA(C,per2); 

// create 5min arrays 
TimeFrameSet( in5Minute ); 
Bema1 = EMA(C,per1); 
Bema2 = EMA(C,per2); 
TimeFrameRestore(); 

// expand 5min arrays 
Bema1 = TimeFrameExpand( Bema1, in5Minute); 
Bema2 = TimeFrameExpand( Bema2, in5Minute); 

// buy constraint 
Buy = Cross(Aema1,Aema2) AND Bema2 > Bema1; 
Buy = Ref(Buy,-1); BuyPrice = Open; 

// chart 
SetChartOptions(0, chartShowDates); 
Plot(C,"Last=",colorWhite,64); 
Plot(Aema1,"Aema1",colorBlue,1); 
Plot(Aema2,"Aema2",colorGreen,1); 
Plot(Bema1,"Bema1",colorAqua,1); 
Plot(Bema2,"Bema2",colorYellow,1); 

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen,0,L,-15); 
PlotShapes(IIf(Buy,shapeHollowUpArrow,shapeNone),colorWhite,0,L,-15); 
PlotShapes(IIf(Buy,shapeHollowSmallCircle,shapeNone),colorWhite,0,BuyPrice,0); 




  ----- Original Message ----- 
  From: mravie7 
  To: [email protected] 
  Sent: Monday, April 20, 2009 12:46 PM
  Subject: [amibroker] help for a formula





  Hi, 
  how does one write a formula and which also gives visual buy and sell arrows, 
and also runs for a back test......
  buy when 13 period EMA crosses 21EMA on close (completed candle) of a 1 
minute chart with a condition that the 21 minute EMA of a 5 minute chart should 
be above 13 EMA in 5 mins chart.

  Thanks in anticipation
  Cheers 
  Ravi



  

Reply via email to