Muscalonus
New member
Hi - I was looking to see if anyone can help getting my simple MACD strategy to stop trading for the day once the "Profit" sell_to_close order is completed.
I have tried a few things like tracking FPL, but it seems way over my head to get it to work.
I have tried a few things like tracking FPL, but it seems way over my head to get it to work.
Code:
def marketopen = 930;
def marketclose = 1533;
def begin = SecondsFromTime(marketopen);
def end = SecondsTillTime(marketclose);
def tradingday = begin > 0 and end > 0;
def eod = end < 1;
# Define how many shares to purchase in Dollar amount
input positionsize = 500;
# Define the length for the MACD 3
input fastLength3 = 10;
input slowLength3 = 26;
input MACDLength3 = 9;
input averageType3 = AverageType.EXPONENTIAL;
input averagetype = averagetype.EXPONENTIAL;
# Calculate the MACD values for 3
def Value3 = MovingAverage(averageType, close, fastLength3) - MovingAverage(averageType, close, slowLength3);
def Avg3 = MovingAverage(averageType, Value3, MACDLength3);
def Diff3 = Value3 - Avg3;
def ZeroLine = 0;
# Condition MACD 3 value is greater
def zerobid3 = Diff3[3] <= 0;
def bid3 = Diff3 > Diff3[1];
def Value3UP = Value3 > Value3[1];
# Define Stoploss STOPLX and ProfitLX Code
input offsetType = {default percent, value, tick};
input stop = 3.0;
input target = 9.9;
def entryPrice = EntryPrice();
def mult;
switch (offsetType) {
case percent:
mult = entryPrice / 1000;
case value:
mult = 1;
case tick:
mult = TickSize();
}
def stopPrice = entryPrice - stop * mult;
def targetPrice = entryPrice + target * mult;
# Define the Buy and Sell terms
def buy = tradingday and Value3UP;
# Add a buy order
AddOrder(OrderType.BUY_TO_OPEN, buy, close, 1000 / close, name = "buy", tickcolor = Color.GREEN);
# Add a stop loss order
AddOrder(OrderType.SELL_TO_CLOSE, low <= stopPrice, name = "StopLoss", tickcolor = GetColor(5), arrowcolor = GetColor(5));
# Add a profit target order
AddOrder(OrderType.SELL_TO_CLOSE, high >= targetPrice, name = "Profit", tickcolor = GetColor(6), arrowcolor = GetColor(6));