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

[amibroker] Why this AFL not work?



PureBytes Links

Trading Reference Links

hi all,

i'm not a programmer and know almost nothing about AFL. so i modified 
an existing afl script to create a new one to place order thru 
InteractiveBrokers butit did not work. 
can anyone advise on where it goes wrong? Many thanks!
  
The function of this simple afl-script is very simple.

just to place 2 set of orders (1 buy and 1 sell bracket orders) at 
simutaneously according 
to "previousclose", "inputvalue", "profittarget" and "trailstop" when 
initiated. 

script:

//SETTING
InputValue1 = 50;
InputValue2 = 50;
profitTarget = 50;
trailStop = 50;
PreviousClose = 17000;

TodaysOpen = 17500;
OpenTime = 94500;  //hhmmss  (hh-hour, mm-minute, ss-sec->always00)


//param trigger button to reset status
resetStatus = ParamTrigger("resetStatus","resetStatus");
//START

DateNumNow = Now(3);

DN = DateNum();
TN = TimeNum();


/*


//TodaysOpen = StaticVarGet("TodaysOpen");
//if(IsEmpty(TodaysOpen))
{
	for( i = 0; i < BarCount; i++ ) 
	{ 
		if(DN[i]==DateNumNow AND TN[i]==OpenTime)
		{
			StaticVarSet("TodaysOpen",Open[i]);
		}
	}
}

TodaysOpen = StaticVarGet("TodaysOpen");
*/


//check if order placed
OrderPlaced = StaticVarGet("OrderPlaced");

if(resetStatus)
{
	StaticVarSet("OrderPlaced",0);
}

OrderPlaced = StaticVarGet("OrderPlaced");



//display info
Title = WriteIf(NOT IsEmpty(TodaysOpen), "Today's Open is"+NumToStr
(TodaysOpen,1.0), "")
+"  PreviousClose is"+NumToStr(PreviousClose)
+"\n\nCurrentSetting:\nprofitTarget is "+NumToStr(profitTarget)
+"  trailStop is"+NumToStr(trailStop)
+"\n\n"+WriteIf( (IsEmpty(OrderPlaced) OR OrderPlaced==0),"Order Not 
Created", "Order Created");


//check if order is triggered, place order if condition fullfiled
if( (IsEmpty(OrderPlaced) OR OrderPlaced==0)    )
{

	//Long side, place order
		ibc = GetTradingInterface("IB");
		IBcStatus = ibc.IsConnected();	
	
		if( IBcStatus  )
		{
			StaticVarSet("OrderPlaced",1);
			LimitBuy = PreviousClose+inputvalue1;
			parentID = ibc.PlaceOrder(Name(),  "BUY", 
1, "LMT", LimitBuy, 0, "DAY", False );
			ibc.PlaceOrder(Name(),  "SELL", 1, "LMT", 
LimitBuy+profitTarget, 0, "DAY", False, 1, "", parentID );
			ibc.PlaceOrder(Name(),  "SELL", 
1, "TRAIL", trailStop, trailStop, "DAY", True, 1, "", parentID );
			
		}
	//short side, place order
		ibc = GetTradingInterface("IB");
		IBcStatus = ibc.IsConnected();	
	
		if( IBcStatus  )
		{
			StaticVarSet("OrderPlaced",-1);
			LimitSell = PreviousClose+inputvalue2;
			parentID = ibc.PlaceOrder(Name
(),  "SELL", 1, "LMT", LimitSell, 0, "DAY", False );
			ibc.PlaceOrder(Name(),  "BUY", 1, "LMT", 
LimitSell-profitTarget, 0, "DAY", False, 1, "", parentID );
			ibc.PlaceOrder(Name(),  "BUY", 
1, "TRAIL", trailStop, trailStop, "DAY", True, 1, "", parentID );
			
		}
}

------END OF AFL SCRIPT------









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