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

[amibroker] Problem: AB seems to have two! different SellPrice values (Bug?)



PureBytes Links

Trading Reference Links

Hello,

I have experienced a strange behavior of my trading system. If I plot
the SellPrice-array in an indicator-window and display the SAME
arrayvalue in the Guru-Commentary, the values are sometimes different.
It seems that the values the indicator shows are correct (I calculated
it manually), but the system trades at the values of the Guru. This
inconsistency seems like a bug to me.
Last week I could just copy the code and save it in a new file and it
worked again, both values were the same. Today the problem occured
again, but doesn't react that friendly. :-(
I hope someone can help me with this problem, cause it'll soon drive
me mad if it won't work reliably.

I attach two versions of the system, the first one seems to work (a
simplified version and rebuild from scratch). The second doesn't show
consistent Sell oder CoverPrice values. It is reduced from my actual
system to the essential.

Regards,
Andreas Pfrengle

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

Simplified System:
//Initialize
SetTradeDelays(0,0,0,0);
Buy = 0;
BuyPrice = O;
Sell = 0;

inmarket = 0;
range = 14;
StopPriceArray = 0;
StopPriceNew = 0;
AvgTR = ATR(range);

//Trading Loop
for (i = range; i < BarCount; i++)
{
	if (inmarket == 0) Buy[i] = 1;
	if (Buy[i] == 1)
	{
		inmarket = 1;
		StopPrice = C[i] - 2 * AvgTR[i];
	}
	StopPriceNew[i] = C[i-1] - 2 * AvgTR[i-1];
	if (Buy[i] != 1) StopPrice = Max(StopPrice, StopPriceNew[i]);
	StopPriceArray[i] = StopPrice;
	SellPrice[i] = Min(StopPrice, O[i]);
	if (inmarket == 1) Sell[i] = (L[i] <= StopPrice);
	if (Sell[i] == 1) inmarket = 0;

}
PositionSize = -10;

//Debug
"AvgTR: " + WriteVal(AvgTR, 1.3);
" ";
"StopPrice: " + WriteVal(StopPriceArray, 1.2);
"SellPrice: " + WriteVal(SellPrice, 1.2);

Plot(StopPriceArray, "Stop", colorBlack, styleDots);
Plot(SellPrice, "SellPrice", colorGrey50, styleDots);
Plot(AvgTR, "AvgTR", colorGold, styleDots|styleOwnScale);
Plot(Buy, "Buy", colorTeal, styleOwnScale);
Plot(Sell, "Sell", colorDarkTeal, styleOwnScale|st
yleDots|styleNoLine);


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

System with odd behavior:

//Parameters
nATR = Param("Stop ATR amount", 2, 0.5, 3, 0.5);
k0 = Param("Adverse Trailing for Stop", 20, 20, 60, 5); 
RSLtrigger = Param("Min RSL-Value", 1, 1, 1.251, 0.05);
Slip = Param("Slippage in Percent per Trade", 0, 0, 2, 0.1);
range = Param("Time Range", 14, 7, 21, 1);
EMAHHVsc = 0.2;  //Smoothing Constant for EMA HHV Since Buy
EMALLVsc = 0.2;  //Smoothing Constant for EMA LLV Since Short


//Initialize
SetTradeDelays(1,0,1,0);
Buy = 0;
BuyPrice = O;
Sell = 0;
Short = 0;
CoverPrice = O;
Cover = 0;
EMAROC = EMA(ROC(C, 1)/100, 3);
EMAHHV[0] = C[0];
EMALLV[0] = C[0];
inmarket = 0;
inmarketshort = 0;
StopPrice = 0;
StopPriceNew = 0;
StopPriceArray = 0;
StopPriceShort = 0;
StopPriceShortNew = 0;
StopPriceShortArray = 0;
AvgTR = ATR(range);

//Trading Loop
for (i = range; i < BarCount; i++)
{
	// Long-Section
	Buyrule[i] = 1;
	if (inmarket == 0 AND inmarketshort == 0) Buy[i] = Buyrule[i];
	if (Buy[i] == 1)
	{
		inmarket = 1;
		StopPrice = C[i] - nATR * AvgTR[i];
	}
	if (Buy[i] == 1) EMAHHV[i] = C[i];
		else EMAHHV[i] = (1-EMAHHVsc) * EMAHHV[i-1]  +  EMAHHVsc * H[i];
	StopPriceNew[i] = EMAHHV[i-1] - (k0*EMAROC[i-1] + nATR) * AvgTR[i-1];
	if (Buy[i] != 1) StopPrice = Max(StopPrice, StopPriceNew[i]);	
//Trailing Stop
	StopPriceArray[i] = StopPrice;
	SellPrice[i] = (1 - Slip/100) * Min(StopPrice, O[i]);	//Sell at Stop
(or Open if lower) minus Slippage
	Sellrule[i] = L[i] <= StopPrice;
	if (inmarket == 1) Sell[i] = Sellrule[i];
	if (Sell[i] == 1 AND Buy[i] == 1) Sell[i] = 0;	//Avoid Sell on same
day as Buy because of TradeDelay (1 day)
	if (Sell[i] == 1) inmarket = 0;

	// Short-Section
	Shortrule[i] = 1;
	if (inmarket == 0 AND inmarketshort == 0) Short[i] = Shortrule[i];
	if (Short[i] == 1)
	{
		inmarketshort = 1;
		StopPriceShort = C[i] + nATR * AvgTR[i];
	}
	if (Short[i] == 1) EMALLV[i] = C[i];
		else EMALLV[i] = (1-EMALLVsc) * EMALLV[i-1]  +  EMALLVsc * L[i];
	StopPriceShortNew[i] = EMALLV[i-1] + (-k0*EMAROC[i-1] + nATR) *
AvgTR[i-1];
	if (Short[i] != 1) StopPriceShort = Min(StopPriceShort,
StopPriceShortNew[i]);		//Trailing Stop
	StopPriceShortArray[i] = StopPriceShort;
	CoverPrice[i] = (1 + Slip/100) * Max(StopPriceShort, O[i]);	//Coverat
Stop (or Open if higher) minus Slippage
	Coverrule[i] = H[i] >= StopPriceShort;
	if (inmarketshort == 1) Cover[i] = Coverrule[i];
	if (Cover[i] == 1 AND Short[i] == 1) Cover[i] = 0;	//Avoid Cover on
same day as Short because of TradeDelay (1 day)
	if (Cover[i] == 1) inmarketshort = 0;

}

WriteVal(EMAHHV, 1.3) + "    : EMAHHV";
WriteVal(AvgTR, 1.3) + "    : AvgTR";
" ";
"Open: " + WriteVal(O, 1.3);
"StopPrice: " + WriteVal(StopPriceArray, 1.2);
"SellPrice: " + WriteVal(SellPrice, 1.2);
" ";
"StopShort: " + WriteVal(StopPriceShortArray, 1.2);
"CoverPrice: " + WriteVal(CoverPrice, 1.2);


Plot(SellPrice, "SellPrice", colorBlack, styleDots);
Plot(CoverPrice, "CoverPrice", colorGrey50, styleDots);
Plot(Buy, "Buy", colorTeal, styleOwnScale);
Plot(Sell, "Sell", colorDarkTeal, styleOwnScale|st
yleDots|styleNoLine);






------------------------ Yahoo! Groups Sponsor --------------------~--> 
<font face=arial size=-1><a href="http://us.ard.yahoo.com/SIG=12hevel9v/M=362343.6886682.7839641.1493532/D=groups/S=1705632198:TM/Y=YAHOO/EXP=1122992415/A=2894350/R=0/SIG=10tj5mr8v/*http://www.globalgiving.com";>Make a difference. Find and fund world-changing projects at GlobalGiving</a>.</font>
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

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

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