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

[amibroker] Re: Camarilla System- Help Needed



PureBytes Links

Trading Reference Links

Can somebody help me with this code: 

This is a Camarilla Based system with the following rules:

1. You will be given 4 levels, R3,R4,S3,S4. If price hits R3 stop and reverse[if you carry a long already, otherwise just short] with MidRes=avg of R3 and R4 as stops.

2. If price hits S3 stop and reverse with stop of MidSup=avg of S3 and S4.

3. If the price breaches S4 levels, short with stop of MidSup,and this will be called a negative BO.
4. If the price breaches R4 levels, go long with stop of MidRes and this will called a positive BO.
5. In case of BO, square off the position at the last 5 minutes of the day[until unless the stop is hit]

This is the code: I request help from Amibroker members to help me out with this. The code apparently doesn't work[no trades made] for the index I am trying to run :D but it does make some trades for other scrips, but apparently it is making trades on a daily timeframe.

//Camarilla Based Trading System
YHigh = TimeFrameGetPrice("H", inDaily, -1);// yesterdays high 
YLow = TimeFrameGetPrice("L", inDaily, -1);//low 
YClose = TimeFrameGetPrice("C",inDaily, -1);//close 
R4= YClose+ ((YHigh-Ylow)*1.1)/2;
R3= YClose+ ((YHigh-Ylow)*1.1)/4;
S3= YClose- ((YHigh-Ylow)*1.1)/4;
S4= YClose- ((YHigh-Ylow)*1.1)/2;
MidRes=(R3+R4)/2;
MidSup=(S3+S4)/2;
LongTrade=False;
ShortTrade=False;
PosBreakOut=False;
NegBreakOut=False;

R3Hit=Cross(R3,C);
S3Crossed=Cross(C,S3) ;
R4breached=Cross(C,R4);
S4breached=Cross(S4,C);
RightNow=TimeNum();
TimeFrameSet(in5Minute);
for(i=0;i<BarCount;i++)
{
	if(R3Hit[i] AND LongTrade==False)				//First Hit   
	{
		Short[i]=1; 									//shortit
		ShortTrade=True;		
       Stop=MidRes[i];                            //and keep the stop at MidRes
	}
   else if(R3Hit[i] AND LongTrade==True)       //Carrying a long trade already
   {
        Sell[i]=1;								  //square up the long trade
        LongTrade=False; 
        Short[i]=1;                           //initiate a short trade
        ShortTrade=True;
        Stop=MidRes[i];                         //set the stop at MidRes
   }
   if(S3Crossed[i] AND ShortTrade==True)         //Carrying a short trade already
	{
         Cover[i]=1;                         //square it up
         ShortTrade=False;
         Buy[i]=1;                           //Initiate a long trade
        LongTrade=True;
	     Stop=MidSup[i];								//Set the stop at MidSup

	}
  else if(S3Crossed[i] AND ShortTrade==False)    //First Hit
   {
         Buy[i]=1;								//Go Long
         LongTrade=True;
         Stop=MidSup[i];							//Set the stop at MidSup
   }
 if(R4breached[i])
  {
         Buy[i]=1;
         Stop=MidRes[i];
         PosBreakOut=True;
  }
 if(S4breached[i])
  {
         Short[i]=1;
         Stop=MidSup[i];
         NegBreakOut=True;
  }
 if(LongTrade==True AND C[i]<Stop)
  {
        Sell[i]=1;
        LongTrade=False;
  }
 if(ShortTrade==True AND C[i]>Stop)
 { 
         Cover[i]=1;
         ShortTrade=False;
 }
 if(PosBreakOut==True AND C[i]<Stop)
 {
         Sell[i]=1;
         PosBreakOut=False;
 }
 if(NegBreakOut==True AND C[i]>Stop)
 { 
		Cover[i]=1;
       NegBreakOut=False;
 }
if(RightNow[i]>=032500 AND PosBreakOut==True)
{
      Sell[i]=1;
      PosBreakOut=False;
}
if(RightNow[i]>=032500 AND NegBreakOut)
{
      Cover[i]=1;
      NegBreakOut=False;
}

}
TimeFrameRestore();

Please do help.
Soham



------------------------------------

**** 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/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/