Hi Guys,
So since 1 month been messing around with various aspects of amibroker and AFL languages. Getting a good drip on it now! However, I do have a question about shorting. I wrote this piece of code which basically shorts the stock (I selected a single one) at 9:45AM and covers it at end of day (3:59 PM). However the problem I am having is that its opening it at 9:45, covering it at 9:46,.. then shorting it at 9:47 and covering it at 9:48 and so on until end of day! Below is my code and screenshots. Any help appreciated! Thanks!!!
EndDay = (Day()!= Ref(Day(), 1));
tn = TimeNum();
startTime = 94500; // start in HHMMSS format
endTime = 153000;
Short = tn>startTime AND tn<endTime;
Cover = tn>EndDay;
Short = ExRem( Short, Cover );
Cover = ExRem( Cover, Short );
// SET OPTIONS
SetBacktestMode( backtestRegularRaw);
//https://www.amibroker.com/guide/afl/setoption.html
SetOption("NoDefaultColumns", False);
SetOption("InitialEquity", 100000);
SetOption("AllowSameBarExit", True);
SetOption("ActivateStopsImmediately", True);
SetOption("AllowPositionShrinking", True);
SetOption("FuturesMode", False);
SetOption("InterestRate", 0);
SetOption("MaxOpenPositions", 1);
SetOption("MinShares", 1);
SetOption("PriceBoundChecking", True);
SetOption("CommissionMode", 2); // $ per trade
SetOption("CommissionAmount", 1);
SetOption("AccountMargin", 50);
SetOption("ReverseSignalForcesExit", False);
SetOption("UsePrevBarEquityForPosSizing", False);
SetOption("PortfolioReportMode", 0);
SetOption("DisableRuinStop", False);
SetOption("GenerateReport", 1);
SetOption("RefreshWhenCompleted", True);
SetOption("SettlementDelay", 0);