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

[amibroker] How do I use GetRTData



PureBytes Links

Trading Reference Links

 I want to have a Profit Stop sell at a certain time if the profit 
stop is met. 

I was using the close, but the bar doesn't always close at the same 
time. So I tried to use this. 


"LastP = "+GetRTData("Ask"); 

if( ProfitTarget ) // allows taking a profit any time
{
	if( DebugOn AND numPositions != 0 ) _TRACE("#, Profit Stop is 
on. TradePrice=" + NumToStr(TradePrice, 1.3) +  
		", Close=" + NumToStr(LastC, 1.3) + ", ProfitVal=" + 
NumToStr(ProfitVal, 1.2) + "\n");
	if(numPositions > 0 )
	{
		ProfitStopValue = TradePrice + profitVal;
		// note that SellTrigger is also set by trailing stop
		if(LastP >= ProfitStopValue AND hourTrigger)  	
		{
			ProfitStop = 1;  	// used to generate a 
sell signal when profit target is reached
			fSayOnce("profit sell");
		}
		profitDelta = 100 * (ProfitStopValue - LastC); // 
calculates the distance to the stop, when 0 the target has been 
reached
 		if(DebugOn) 	_TRACE("#, ProfitStop 2, Stop value=" 
+ NumToStr(ProfitStopValue, 1.2) + 
			", ProfitDelta=" + NumToStr(profitDelta, 1.2) 
+ "\n");
	}
	else if(numPositions < 0)
	{
		ProfitStopValue = TradePrice - profitVal;
		if(ProfitStopValue >= LastC) 
		{
			ProfitStop = 2;  	// used to generate a 
cover signal when profit target is reached	
			fSayOnce("profit cover");
		}
		profitDelta = 100 * (LastC - ProfitStopValue);  // 
calculates the distance to the stop, when 0 the target has been 
reached
		if(DebugOn) 	_TRACE("#, ProfitStop 3, Stop value=" 
+ NumToStr(ProfitStopValue, 1.2) +  
			", ProfitDelta=" + NumToStr( profitDelta, 
1.2) +  "\n");
	}
}
else
{
	if(DebugOn) 	_TRACE("#, Profit Stop is off." + "\n"); 
}
	
When I verify this, I don't get any errors. However when I use it in 
my chart everything is fine until I turn the profit stop on in my 
parameters, then I get this error.


Error 29.
Variable 'lastp' used without having been initialized.

What am I doing wrong?

Thanks,
Tom



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

**** IMPORTANT ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

*********************
TO GET TECHNICAL SUPPORT from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com
*********************

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

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/

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