I created this simple indicator using AIs to figure out where to put my stop losses or to see how much profit/loss they would make if I did set them in said areas. It allows multiple types of inputs percentages, ticks, dollar amount, or entry price offset amount( like trailstop entries). It lets you choose what value is displayed at top labels so you can input a dollar amount or % value if that's what you want and it will display price level on chart and prefered output at top. Live data is calculated after the formation of last candle as well as I only calculate stock and futures price correctly since I don't use any other assets yet.
https://tos.mx/!a6SrxdLb
https://tos.mx/!a6SrxdLb
JavaScript:
input entryPriceCan = 5749.00;
input UseLiveData = yes;
def entryPrice = if UseLiveData then Close(priceType = PriceType.MARK) else entryPriceCan;
input takeProfitPrice = 5750.00;
input stopLossPrice = 5745.00;
input trailStopValue = 5740.00;
input calculationMethod = {default "Candle Price", "Percentage", "Offset from Entry", "Tick Value"};
input displayMethod = {default "Price", "Percentage", "Tick Value", "Offset $ Value"};
input exitMethod = {default "Stop Loss", "Take Profit", "Trail Stop", "Stop Loss and Take Profit", "Stop Loss and Trail Stop", "All"};
input numberOfContracts = 1;
input instrumentType = {default "Futures", "Stocks"};
input positionType = {default long, short};
def tickSize = TickSize();
def tickVal = TickValue();
def stopLoss;
def takeProfit;
def trailStop;
switch (calculationMethod) {
case "Offset from Entry":
stopLoss = if positionType == positionType.long then entryPrice - stopLossPrice else entryPrice + stopLossPrice;
takeProfit = if positionType == positionType.long then entryPrice + takeProfitPrice else entryPrice - takeProfitPrice;
trailStop = if positionType == positionType.long then entryPrice - trailStopValue else entryPrice +trailStopValue;
case "Percentage":
stopLoss = if positionType == positionType.long then entryPrice-(entryPrice*(stopLossPrice/100)) else entryPrice+(entryPrice*(stopLossPrice/100));
takeProfit = if positionType == positionType.long then entryPrice+(entryPrice*(takeProfitPrice/100)) else entryPrice-(entryPrice*(takeProfitPrice/100));
trailStop = if positionType == positionType.long then entryPrice-(entryPrice*(trailStopValue/100)) else entryPrice+(entryPrice*(trailStopValue/100));
case "Tick Value":
stopLoss = if positionType == positionType.long then entryPrice - (stopLossPrice * tickSize) else entryPrice + (stopLossPrice * tickSize);
takeProfit = if positionType == positionType.long then entryPrice + (takeProfitPrice * tickSize) else entryPrice - (takeProfitPrice * tickSize);
trailStop = if positionType == positionType.long then entryPrice - (trailStopValue * tickSize) else entryPrice + (trailStopValue * tickSize);
case "Candle Price":
stopLoss = stopLossPrice;
takeProfit = takeProfitPrice;
trailStop = trailStopValue;
}
def stopLossVal;
def takeProfitVal;
def trailStopVal;
switch (displayMethod) {
case "Price":
stopLossVal = stopLoss;
takeProfitVal = takeProfit;
trailStopVal = trailStop;
case "Percentage":
stopLossVal = if positionType == positionType.long then (entryPrice - stopLoss) / entryPrice * 100 else (stopLoss - entryPrice) / entryPrice * 100;
takeProfitVal = if positionType == positionType.long then (takeProfit - entryPrice) / entryPrice * 100 else (entryPrice - takeProfit) / entryPrice * 100;
trailStopVal = if positionType == positionType.long then (entryPrice - trailStop) / entryPrice * 100 else (trailStop - entryPrice) / entryPrice * 100;
case "Tick Value":
stopLossVal = if positionType == positionType.long then (entryPrice - stopLoss) / tickSize else (stopLoss - entryPrice) / tickSize;
takeProfitVal = if positionType == positionType.long then (takeProfit - entryPrice) / tickSize else (entryPrice - takeProfit) / tickSize;
trailStopVal = if positionType == positionType.long then (entryPrice - trailStop) / tickSize else (trailStop - entryPrice) / tickSize;
case "Offset $ Value":
stopLossVal = if positionType == positionType.long then (entryPrice - stopLoss) else (stopLoss - entryPrice);
takeProfitVal = if positionType == positionType.long then (takeProfit - entryPrice) else (entryPrice - takeProfit);
trailStopVal = if positionType == positionType.long then (entryPrice - trailStop) else (trailStop - entryPrice);
}
def highestBarIndex = HighestAll(if !IsNaN(close) then BarNumber() else Double.NaN);
plot entryLine = if (BarNumber() >= highestBarIndex - 2) then entryPrice else Double.NaN;
entryLine.SetDefaultColor(Color.WHITE);
entryLine.SetLineWeight(2);
plot stopLossLine;
stopLossLine.SetDefaultColor(Color.Red);
stopLossLine.SetLineWeight(2);
plot takeProfitLine;
takeProfitLine.SetDefaultColor(Color.Green);
takeProfitLine.SetLineWeight(2);
plot trailStopLine;
trailStopLine.SetDefaultColor(Color.MAGENTA);
trailStopLine.SetLineWeight(2);
def profitPrice;
def lossPrice;
switch(exitMethod) {
case "Stop Loss":
profitPrice = stopLoss;
lossPrice = stopLoss;
trailStopLine = Double.NaN;
stopLossLine = if (BarNumber() >= highestBarIndex - 2) then stopLoss else Double.NaN;
takeProfitLine = Double.NaN;
case "Take Profit":
profitPrice = takeProfit;
lossPrice = -10000000;
trailStopLine = Double.NaN;
stopLossLine = Double.NaN;
takeProfitLine = if (BarNumber() >= highestBarIndex - 2) then takeProfit else Double.NaN;
case "Trail Stop":
profitPrice = trailStop;
lossPrice = trailStop;
trailStopLine = if (BarNumber() >= highestBarIndex - 2) then trailStop else Double.NaN;
stopLossLine = Double.NaN;
takeProfitLine = Double.NaN;
case "Stop Loss and Take Profit":
profitPrice = takeProfit;
lossPrice = if positionType == positionType.long then Max(stopLoss, takeProfit) else Min(stopLoss, takeProfit);
trailStopLine = Double.NaN;
stopLossLine = if (BarNumber() >= highestBarIndex - 2) then stopLoss else Double.NaN;
takeProfitLine = if (BarNumber() >= highestBarIndex - 2) then takeProfit else Double.NaN;
case "Stop Loss and Trail Stop":
profitPrice = if positionType == positionType.long then Max(stopLoss, trailStop) else Min(stopLoss, trailStop);
lossPrice = if positionType == positionType.long then Max(stopLoss, trailStop) else Min(stopLoss, trailStop);
trailStopLine = if (BarNumber() >= highestBarIndex - 2) then trailStop else Double.NaN;
stopLossLine = if (BarNumber() >= highestBarIndex - 2) then stopLoss else Double.NaN;
takeProfitLine = Double.NaN;
case "All":
profitPrice = takeProfit;
lossPrice = if positionType == positionType.long then Max(stopLoss, trailStop) else Min(stopLoss, trailStop);
trailStopLine = if (BarNumber() >= highestBarIndex - 2) then trailStop else Double.NaN;
stopLossLine = if (BarNumber() >= highestBarIndex - 2) then stopLoss else Double.NaN;
takeProfitLine = if (BarNumber() >= highestBarIndex - 2) then takeProfit else Double.NaN;
}
AddLabel(yes, "Entry Price: " + AsDollars(entryPrice), Color.WHITE);
AddLabel(yes, "Stop Loss: " + stopLossVal, Color.RED);
AddLabel(yes, "Take Profit: " + takeProfitVal, Color.GREEN);
AddLabel(yes, "Trail Stop: " + trailStopVal, Color.MAGENTA);
def profit;
def loss;
switch(instrumentType) {
case "Futures":
profit = if (positionType == positionType.long) then ((tickVal * ((profitPrice - entryPrice) / tickSize)) * numberOfContracts) else ((tickVal * ((entryPrice - profitPrice) / tickSize)) * numberOfContracts);
loss = if (positionType == positionType.long) then ((tickVal * ((lossPrice- entryPrice) / tickSize)) * numberOfContracts) else ((tickVal * ((entryPrice - lossPrice) / tickSize)) * numberOfContracts);
case "Stocks":
profit = if (positionType == positionType.long) then (profitPrice - entryPrice) * numberOfContracts else (entryPrice - profitPrice) * numberOfContracts ;
loss = if (positionType == positionType.long) then (lossPrice- entryPrice) * numberOfContracts else (entryPrice - lossPrice) * numberOfContracts ;
}
#Profit = only profit(for just TP) or only Loss(for just stops)
AddLabel(yes, "Profit: " + AsDollars(profit), Color.YELLOW);
AddLabel(yes, "Loss: " + asDollars(loss), Color.Red);
Last edited: