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

Re: [amibroker] Help with simple code



PureBytes Links

Trading Reference Links



Ed,
 
Do you have a sample of this type of exit loop or know of one in the library I could look at?
What do you think of ApplyStop? Do you know if ApplyStop solves the problems I posted on 10/10 concerning the built in stops not being recognized as trades.
 
James


From: Edward Pottasch <empottasch@xxxxxxxxx>
To: amibroker@xxxxxxxxxxxxxxx
Sent: Mon, October 12, 2009 1:41:03 AM
Subject: Re: [amibroker] Help with simple code

 

hi james,
 
your targets change because you are using Buy and Short signals to define these targets which you later remove with exrem. So before you define your targets you need to remove the redundant signals. I usually think these kind of problems are easier solved using an exit loop but it makes it slower.
 
regards, Ed
 
 
 
----- Original Message -----
From: James
Sent: Sunday, October 11, 2009 11:32 PM
Subject: [amibroker] Help with simple code

 

Can someone help explain what I am doing wrong. In the following code, it appears the variables ShortTarget and LongTarget change when ShortCondition or BuyCondition occur even though these conditions are not part of the definition.

 

Looking at a 30min chart RTH only of ESZ9-GLOBEX- FUT, I get a Sell on 9/30/2009 at 2:00PM which gives a ShortTarget of 1016.80. On 10/1/2009 at 8:30, ShortCondition = 1, but Short  = 0 because of the ExRem statement, yet ShortTarget changes from 1016.80 to 1012.92 which is not intended.

 

Also, this "simple" excercise in coding this simple system is spiraling out of control as I keep thinking TJ's code would be like 3 lines, so I would appreciate suggested improvements for learning.

 

TIA,

James

 

SetFormulaName ("30 34 System");

/*
The 30/34 System is a swing system for trading the S&P E-mini futures (ES).
Signals are taken from a 30 minute chart of the ES with a 34 EMA (exponential moving average).
Only RTH data is used. No entries or exits are made during Globex session.
Entry rules:
Buy when price crosses 34 EMA +1 point.
Sell when price crosses below 34 EMA -1 point.
Profit target is entry price +/- 3%.
Buy stop is 34 EMA -5 points, MIT.
Sell stop is 34 EMA +5 points, MIT.
*/


BuyAvg =
EMA (C,34) + 1
;
SellAvg =
EMA (C, 34) -1
;
LongStopAvg =
EMA (C,34) - 5
;
ShortStopAvg =
EMA (C,34) + 5
;
BuyCondition =
Cross (C
, BuyAvg);
ShortCondition =
Cross (SellAvg, C
);
LongStopCondition =
Cross (LongStopAvg, L
);
ShortStopCondition =
Cross (H
, ShortStopAvg) ;

Buy
= BuyCondition;
LongTarget =
ValueWhen (Buy, C, 1) * 1.03
;
LongProfitCondition =
Cross (H
, LongTarget);
Sell = LongStopCondition OR LongProfitCondition OR
ShortCondition;
Short
= ShortCondition;
ShortTarget =
ValueWhen (Short, C, 1) * 0.97
;
ShortProfitConditio n =
Cross (ShortTarget, L
);
Cover = ShortStopCondition OR ShortProfitConditio n OR
BuyCondition;

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

Plot( BuyAvg, "Buy Average", colorGreen, ParamStyle("Style"
) );
Plot( SellAvg, "Sell Average", colorRed, ParamStyle("Style"
) );
Plot( LongStopAvg, "Long Stop", colorPink, ParamStyle("Style"
) );
Plot( ShortStopAvg, "Short Stop", colorPaleGreen, ParamStyle("Style"
) );

PlotShapes (IIf(Buy,shapeUpArrow,shapeNone), colorGreen,0,Low
);
PlotShapes (IIf(Sell,shapeHollowDownArro w,shapeNone), colorRed,0,High
);
PlotShapes (IIf(Short,shapeDownArrow,shapeNone), colorRed,0,High
);
PlotShapes (IIf(Cover,shapeHollowUpArrow,shapeNone), colorGreen,0,Low
);

PositionSize = MarginDeposit
;

"BuyAvg: " + NumToStr (BuyAvg, 1.2
);
"SellAvg: " + NumToStr (SellAvg, 1.2
) ;
"LongStopAvg: " + NumToStr (LongStopAvg, 1.2
);
"ShortStopAvg: " + NumToStr (ShortStopAvg, 1.2
);
"BuyCondition: " + NumToStr (BuyCondition, 1
);
"ShortCondition: " + NumToStr (ShortCondition, 1
);
"Short: " + NumToStr (Short, 1
);
"LongStopCondition: " + NumToStr (LongStopcondition, 1
);
"ShortStopCondition : " + NumToStr (ShortStopCondition , 1
);
"LongTarget: " + NumToStr (LongTarget, 1.2
);
"ShortTarget: " + NumToStr (ShortTarget, 1.2
);
"LongProfitConditio n: " + NumToStr (LongProfitConditio n, 1
);
"ShortProfitConditi on: " + NumToStr (ShortProfitConditi on, 1
);





__._,_.___


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

__,_._,___