hi, i know nothing about programming and i'm trying to code a simple AFL system by modifying an existing one. but it does not work, i dont know why. will appreciate if you can help me figure out the coding mistakes, thanks! The function of this simple afl-script is simply to simultaneously place 2 set of orders (1 buy and 1 sell Bracket Orders) according to "previousclose", "inputvalue", "profittarget" and "trailstop" when initiated. it send order through InteractiveBrokers TWS. SCRIPT: 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==DateNumNow AND TN==OpenTime) { StaticVarSet("TodaysOpen",Open); } } } 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 ); } }
Yes, the original code works fine. i copy and paste it and add my stuff.. can you see any "grammatical" or structural mistakes in my dummy script? thanks for your reply.