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







Reply via email to