dankercookie
New member
I've been trying to code a strategy that buys at the end of the day then sells at the open of the next day, but the script I use only wants to buy and sell the same day. any recommendations. I've tried setting some time and position parameters, but they don't seem to work. here is the code I had. Does anyone know how to do this??
def qty = GetQuantity();
# Define the input parameters
input buyTime = 1400;
input sellTime = 0930;
# Check if it is time to buy
def buyCond = GetTime() == buyTime;
# Check if it is time to sell
def sellCond =GetTime() == sellTime;
# Check if a position is open
def posnotOpen = if (qty > 1) then 1 else 0;
def posopen = if(qty <1) then 1 else 0;
input malength = 200;
def sma = simplemovingavg(length = malength);
# Check if we should buy
def buy = buyCond and posnotopen;
# Check if we should sell
def sell = sellCond and posopen;
AddOrder(OrderType.BUY_TO_OPEN, buy,close, name = "Buy", tickcolor = Color.GREEN, arrowcolor = Color.GREEN);
AddOrder(OrderType.SELL_TO_CLOSE, sell,open, name = "Sell", tickcolor = Color.RED, arrowcolor = Color.RED);
def qty = GetQuantity();
# Define the input parameters
input buyTime = 1400;
input sellTime = 0930;
# Check if it is time to buy
def buyCond = GetTime() == buyTime;
# Check if it is time to sell
def sellCond =GetTime() == sellTime;
# Check if a position is open
def posnotOpen = if (qty > 1) then 1 else 0;
def posopen = if(qty <1) then 1 else 0;
input malength = 200;
def sma = simplemovingavg(length = malength);
# Check if we should buy
def buy = buyCond and posnotopen;
# Check if we should sell
def sell = sellCond and posopen;
AddOrder(OrderType.BUY_TO_OPEN, buy,close, name = "Buy", tickcolor = Color.GREEN, arrowcolor = Color.GREEN);
AddOrder(OrderType.SELL_TO_CLOSE, sell,open, name = "Sell", tickcolor = Color.RED, arrowcolor = Color.RED);