NQ 1 minute Scalping Indicator For ThinkOrSwim

Sure. I assume
Could you explain further as to what this is showing and what you expect to see? Hard to tell from this what is "wrong". Thanks
Sure. I assume that the outcome should have picked the buy and sell locations at each point or is this more of a long term strategy. I may have expected something different.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@JoeDV Thanks for providing this. I am pretty new at this stuff. I just tested this on todays stock EFOI. This is a 1min chart. Either I am missing something or it isn't working for me.

Screenshot-0.jpg
You have Heiken candles. They gotta be regular ones to see real price action!
 
I recently came upon a nice scalping strategy:
. I coded it for thinkscript and figured I should share it with all you wonderful people here. Designed for NQ 1m, but I see good, bigger trades on 2m as well (I have only traded it on sim thus far). On the 2m, it basically functions as a nice pullback entry in a trend. While the strat creator's only requirement is being above/below 10 ema, I decided to use a 10-20-50 ema filter to get rid of bad signals in chop. There is likely a better trend filter but this gets the job done. I prefer to use my own judgment on whether we're trending or not; the filter merely serves to clean up unnecessary arrows on my chart.

Enjoy, and I look forward to your feedback.

Code:
# Shimi's Scalp Pro Elite Platinum Extreme; Deluxe Edition.
# Based on Quant Trade Edge's Strategy in https://www.youtube.com/watch?v=lhW5czmfc14
# Original Strategy is for NQ 1 minute chart, long only above 10ema and short only below 10ema, risking 1 ATR for .5 ATR target.

# Start EMA
input price = close;
input length = 10;
input displace = 0;

def ema = expAverage(price[-displace], length);
def ema20 = expAverage (price, length=20);
def ema50 = expAverage (price, length=50);

def bull = close > open and low < low[1] and high < high[1] and close > ema and ema > ema20 and ema20 > ema50;
def bear = close < open and low > low[1] and high > high[1] and close < ema and ema < ema20 and ema20 < ema50;

plot upsignal = bull;
plot downsignal = bear;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Have you tried this with QQQ? I day trade QQQ options several times in the 1st 90 minutes.
 
can you share this latest code with me...I downloaded earlier and not working....looking for help thx
  1. "not working" does not provide enough information to say where you went astray.
  2. there in no "lastest" code. There is the basic code in the first post. And then members provided their various flavors. No flavor is better than another, just various styles of trading.
Recommend that you copy & paste the script in the first post.
Here are directions on how to copy & paste:
https://usethinkscript.com/threads/how-to-import-existing-thinkscript-code-on-thinkorswim.10/
Then watch the video again.

If you have any problems, come back with an image of your chart, an explanation of what you expected to see, and a description of what you think you are seeing.

# # # # #
The best way to learn to read charts and indicators is to apply them. Recommend you put it on your chart. Nothing beats personal experience ;) The only way you will know what the plots are doing, is to observe them on your charts and how they inter-relate with your other indicators.

Most indicators need tweaking depending on the timeframe, the market, the ticker.

No one can possibly know what tweaks will work best for you. It is up to you to play with the settings and see how the indicator line up w/ your strategy and with your other indicators.

To determine if this chart setup brings value, analyze it over different timeframes, across history and with multiple instruments.
# # # # #
 
Hello all,

@JoeDV , would it be possible to create a scan for this? The code you gave in the original post (post #8) works well for me. I'd just like to be able to scan for Buy Signals. Thanks so much
 
Hello all,

@JoeDV , would it be possible to create a scan for this? The code you gave in the original post (post #8) works well for me. I'd just like to be able to scan for Buy Signals. Thanks so much
Ruby:
# Shimi's Scalp Pro Elite Platinum Extreme; Deluxe Edition.
# Based on Quant Trade Edge's Strategy in https://www.youtube.com/watch?v=lhW5czmfc14
# Original Strategy is for NQ 1 minute chart, long only above 10ema and short only below 10ema, risking 1 ATR for .5 ATR target.

# Start EMA
input price = close;
input length = 10;
input displace = 0;

def ema = expAverage(price[-displace], length);
def ema20 = expAverage (price, length=20);
def ema50 = expAverage (price, length=50);

def bull = close > open and low < low[1] and high < high[1] and close > ema and ema > ema20 and ema20 > ema50;
def bear = close < open and low > low[1] and high > high[1] and close < ema and ema < ema20 and ema20 < ema50;

plot upsignal = bull;


Shared Scanner link: http://tos.mx/mZwdQx2 Click here for --> Easiest way to load shared links
ftHk6r6.png
 
I recently came upon a nice scalping strategy:
. I coded it for thinkscript and figured I should share it with all you wonderful people here. Designed for NQ 1m, but I see good, bigger trades on 2m as well (I have only traded it on sim thus far). On the 2m, it basically functions as a nice pullback entry in a trend. While the strat creator's only requirement is being above/below 10 ema, I decided to use a 10-20-50 ema filter to get rid of bad signals in chop. There is likely a better trend filter but this gets the job done. I prefer to use my own judgment on whether we're trending or not; the filter merely serves to clean up unnecessary arrows on my chart.

Enjoy, and I look forward to your feedback.

Code:
# Shimi's Scalp Pro Elite Platinum Extreme; Deluxe Edition.
# Based on Quant Trade Edge's Strategy in https://www.youtube.com/watch?v=lhW5czmfc14
# Original Strategy is for NQ 1 minute chart, long only above 10ema and short only below 10ema, risking 1 ATR for .5 ATR target.

# Start EMA
input price = close;
input length = 10;
input displace = 0;

def ema = expAverage(price[-displace], length);
def ema20 = expAverage (price, length=20);
def ema50 = expAverage (price, length=50);

def bull = close > open and low < low[1] and high < high[1] and close > ema and ema > ema20 and ema20 > ema50;
def bear = close < open and low > low[1] and high > high[1] and close < ema and ema < ema20 and ema20 < ema50;

plot upsignal = bull;
plot downsignal = bear;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Are you still using this successfully?
 
Try this http://tos.mx/5fyTg6X

or if you prefer to copy/paste

JavaScript:
# Shimi's Scalp Pro Elite Platinum Extreme; Deluxe Edition.
# Based on Quant Trade Edge's Strategy in https://www.youtube.com/watch?v=lhW5czmfc14
# Original Strategy is for NQ 1 minute chart, long only above 10ema and short only below 10ema, risking 1 ATR for .5 ATR target.

# Start EMA
input price = close;
input length = 10;
input displace = 0;

def ema = expAverage(price[-displace], length);
def ema20 = expAverage (price, length=20);
def ema50 = expAverage (price, length=50);

def bull = close > open and low < low[1] and high < high[1] and close > ema and ema > ema20 and ema20 > ema50;
def bear = close < open and low > low[1] and high > high[1] and close < ema and ema < ema20 and ema20 < ema50;

def upsignal = bull;
def downsignal = bear;
#UpSignal.SetDefaultColor(Color.UPTICK);
#UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#DownSignal.SetDefaultColor(Color.DOWNTICK);
#DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

###------------------------------------------------------------------------------------------
# Profit and Loss Labels
#
# Fill in the 0>0 in the Create Signals section below to match your buy and sell signal conditions
#
# When using large amounts of hisorical data, P/L may take time to calculate
###------------------------------------------------------------------------------------------

input showSignals = yes; #hint showSignals: show buy and sell arrows
input LongTrades = yes; #hint LongTrades: perform long trades
input ShortTrades = yes; #hint ShortTrades: perform short trades
input showLabels  = yes; #hint showLabels: show PL labels at top
input showBubbles = yes; #hint showBubbles: show PL bubbles at close of trade
input useStops = no;     #hint useStops: use stop orders
input useAlerts = no;    #hint useAlerts: use alerts on signals
input tradeDaytimeOnly = no; #hint tradeDaytimeOnly: (IntraDay Only) Only perform trades during hours stated
input OpenTime = 0930; #hint OpenTime: Opening time of market
input CloseTime = 1600; #hint CloseTime: Closing time of market

#----- ATR Trail ----
input trailType = {default modified, unmodified};
input ATRPeriod = 5;
input ATRFactor = 3.5;
input firstTrade = {default long, short};
input averageType = { default WILDERS, SIMPLE, EXPONENTIAL,HULL, WEIGHTED};

def ATRStop = ATRTrailingStop(trailType, ATRPeriod, ATRFactor, firstTrade, averageType);

#---------------------


def Begin = secondsfromTime(OpenTime);
def End = secondsTillTime(closetime);
# Only use market hours when using intraday timeframe
def isIntraDay = if getaggregationperiod() > 14400000 or getaggregationperiod()==0 then 0 else 1;
def MarketOpen = if !tradeDaytimeOnly or !isIntraDay then 1 else if tradeDaytimeOnly and isIntraDay and Begin > 0 and End > 0 then 1 else 0;
###------------------------------------------------------------------------------------------


######################################################
##  Create Signals -
##  FILL IN THIS SECTION
##      replace 0>0 with your conditions for signals
######################################################

def PLBuySignal = if  MarketOpen AND (upsignal) AND (ATRStop < close ) then 1 else 0 ; # insert condition to create long position in place of the 0>0
def PLSellSignal =  if MarketOpen AND (downsignal) AND (ATRStop > close ) then 1 else 0; # insert condition to create short position in place of the 0>0

def PLBuyStop  = if !useStops then 0 else if (ATRStop > close ) then 1 else 0  ; # insert condition to stop in place of the 0<0
def PLSellStop = if !useStops then 0 else if (ATRStop < close ) then 1 else 0  ; # insert condition to stop in place of the 0>0

def PLMktStop = if MarketOpen[-1] == 0 then 1 else 0; # If tradeDaytimeOnly is set, then stop at end of day


#######################################
##  Maintain the position of trades
#######################################

def CurrentPosition;  # holds whether flat = 0 long = 1 short = -1

if (BarNumber()==1) OR isNaN(CurrentPosition[1]) {
    CurrentPosition = 0;
}else{
        if CurrentPosition[1] == 0 {            # FLAT
            if (PLBuySignal AND LongTrades) {
                CurrentPosition = 1;
            } else if (PLSellSignal AND ShortTrades){
                CurrentPosition = -1;
            } else {
                CurrentPosition = CurrentPosition[1];
            }
       } else if CurrentPosition[1] == 1 {      # LONG
            if (PLSellSignal AND ShortTrades){
                CurrentPosition = -1;
            } else if ((PLBuyStop and useStops) or PLMktStop or (PLSellSignal AND ShortTrades==0)){
                CurrentPosition = 0;
            } else {
                CurrentPosition = CurrentPosition[1];
            }
       } else if CurrentPosition[1] == -1 {     # SHORT
            if (PLBuySignal AND LongTrades){
                CurrentPosition = 1;
            } else if ((PLSellStop and useStops) or PLMktStop or (PlBuySignal and LongTrades==0)){
                CurrentPosition = 0;
            } else {
                CurrentPosition = CurrentPosition[1];
            }
       } else {
            CurrentPosition = CurrentPosition[1];
       }
}


def isLong  = if CurrentPosition == 1 then 1 else 0;
def isShort = if CurrentPosition == -1 then 1 else 0;
def isFlat  = if CurrentPosition == 0 then 1 else 0;

# If not already long and get a PLBuySignal
#Plot BuySig = if (!isLong[1] and PLBuySignal and showSignals and LongTrades) then 1 else 0;
Plot BuySig = if (((isShort[1] and LongTrades) or (isFlat[1] and LongTrades)) and PLBuySignal and showSignals) then 1 else 0;
BuySig.AssignValueColor(color.cyan);
BuySig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuySig.SetLineWeight(5);

Alert(BuySig and useAlerts, "Buy Signal",Alert.bar,sound.Ding);
Alert(BuySig and useAlerts, "Buy Signal",Alert.bar,sound.Ding);

# If not already short and get a PLSellSignal
Plot SellSig = if (((isLong[1] and ShortTrades) or (isFlat[1] and ShortTrades)) and PLSellSignal and showSignals) then 1 else 0;
SellSig.AssignValueColor(color.cyan);
SellSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellSig.SetLineWeight(5);

Alert(SellSig and useAlerts, "Sell Signal",Alert.bar,sound.Ding);
Alert(SellSig and useAlerts, "Sell Signal",Alert.bar,sound.Ding);

# If long and get a PLBuyStop
Plot BuyStpSig = if (PLBuyStop and isLong[1] and showSignals and useStops) or (isLong[1] and PLMktStop) or (isLong[1] and PLSellSignal and !ShortTrades) then 1 else 0;
BuyStpSig.AssignValueColor(color.light_gray);
BuyStpSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
BuyStpSig.SetLineWeight(3);

Alert(BuyStpSig and useAlerts, "Buy Stop Signal",Alert.bar,sound.Ding);
Alert(BuyStpSig and useAlerts, "Buy Stop Signal",Alert.bar,sound.Ding);


# If short and get a PLSellStop
Plot SellStpSig = if (PLSellStop and isShort[1] and showSignals and useStops) or (isShort[1] and PLMktStop) or (isShort[1] and PLBuySignal and !LongTrades) then 1 else 0;
SellStpSig.AssignValueColor(color.light_gray);
SellStpSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
SellStpSig.SetLineWeight(3);

Alert(SellStpSig and useAlerts, "Sell Stop Signal",Alert.bar,sound.Ding);
Alert(SellStpSig and useAlerts, "Sell Stop Signal",Alert.bar,sound.Ding);


#######################################
##  Orders
#######################################

def isOrder = if ((isFlat[1] and (BuySig and LongTrades) or (SellSig and ShortTrades)) or (isLong[1] and BuyStpSig or (SellSig and ShortTrades)) or (isShort[1] and SellStpSig or (BuySig and LongTrades))) then 1 else 0 ;
# If there is an order, then the price is the next days close
def orderPrice = if (isOrder and ((BuySig and LongTrades) or (SellSig and ShortTrades))) then close else orderPrice[1];

def orderCount = compoundValue(1,if isNan(isOrder) or barnumber()==1 then 0 else if (BuySig or SellSig) then orderCount[1]+1 else orderCount[1],0);


#######################################
##  Price and Profit
#######################################

def profitLoss;


if (!isOrder or orderPRice[1]==0){
    profitLoss = 0;
} else if ((isOrder and isLong[1]) and (SellSig or BuyStpSig)){
    profitLoss = close - orderPrice[1];
} else if ((isOrder and isShort[1]) and (BuySig or SellStpSig)) {
    profitLoss = orderPrice[1] - close;
} else {
    profitLoss = 0;
}


# Total Profit or Loss
def profitLossSum = compoundValue(1, if isNaN(isOrder)  or barnumber()==1 then 0 else if isOrder then profitLossSum[1] + profitLoss else profitLossSum[1], 0);

# How many trades won or lost
def profitWinners = compoundValue(1, if isNaN(profitWinners[1]) or barnumber()==1 then 0 else if isOrder and profitLoss > 0 then profitWinners[1] + 1 else profitWinners[1], 0);
def profitLosers = compoundValue(1, if isNaN(profitLosers[1])  or barnumber()==1 then 0 else if isOrder and profitLoss < 0 then profitLosers[1] + 1 else profitLosers[1], 0);
def profitPush = compoundValue(1, if isNaN(profitPush[1])  or barnumber()==1 then 0 else if isOrder and profitLoss == 0 then profitPush[1] + 1 else profitPush[1], 0);

# Current Open Trade Profit or Loss
def TradePL = If isLong then Round(((close - orderprice)/TickSize())*TickValue()) else if isShort then Round(((orderPrice - close)/TickSize())*TickValue()) else 0;

# Convert to actual dollars based on Tick Value for bubbles
def dollarProfitLoss = if orderPRice[1]==0 or isNaN(orderPrice[1]) then 0 else round((profitLoss/Ticksize())*Tickvalue());

# Closed Orders dollar P/L
def dollarPLSum = round((profitLossSum/Ticksize())*Tickvalue());


# Split profits or losses by long and short trades
def profitLong = compoundValue(1, if isNan(profitLong[1])  or barnumber()==1 then 0 else if isOrder and isLong[1] then profitLong[1]+dollarProfitLoss else profitLong[1],0);
def profitShort = compoundValue(1, if isNan(profitShort[1])  or barnumber()==1 then 0 else if isOrder and isShort[1] then profitShort[1]+dollarProfitLoss else profitShort[1],0);
def countLong = compoundValue(1, if isNaN(countLong[1])  or barnumber()==1 then 0 else if isOrder and isLong[1] then countLong[1]+1 else countLong[1],0);
def countShort = compoundValue(1, if isNaN(countShort[1])  or barnumber()==1 then 0 else if isOrder and isShort[1] then countShort[1]+1 else countShort[1],0);

# What was the biggest winning and losing trade
def biggestWin = compoundValue(1, if isNaN(biggestWin[1]) or barnumber()==1 then 0 else if isOrder and (dollarProfitLoss > 0) and (dollarProfitLoss > biggestWin[1]) then dollarProfitLoss else biggestWin[1], 0);
def biggestLoss = compoundValue(1, if isNaN(biggestLoss[1]) or barnumber()==1 then 0 else if isOrder and (dollarProfitLoss < 0) and (dollarProfitLoss < biggestLoss[1]) then dollarProfitLoss else biggestLoss[1], 0);

def ClosedTradeCount = if (isLong or isShort) then orderCount-1 else orderCount;
def OpenTrades = if (isLong or isShort) then 1 else 0;


# What percent were winners
def PCTWin = if (OpenTrades and (TradePL < 0)) then round((profitWinners/(ClosedTradeCount+1))*100,2)
else if (OpenTrades and (TradePL > 0)) then round(((profitWinners+1)/(ClosedTradeCount+1))*100,2) else round(((profitWinners)/(ClosedTradeCount))*100,2) ;

# Average trade
def avgTrade = if (OpenTrades and (TradePL < 0)) then round(((dollarPLSum - TradePL)/(ClosedTradeCount+1)),2)
else if (OpenTrades and (TradePL > 0)) then round(((dollarPLSum + TradePL)/(ClosedTradeCount+1)),2) else round(((dollarPLSum)/(ClosedTradeCount)),2) ;


#######################################
##  Create Labels
#######################################


AddLabel(showLabels and isIntraDay, if MarketOpen then "Market Open" else "Market Closed", color.white);
AddLabel(showLabels, GetSymbol()+" Tick Size: "+TickSize()+" Value: "+TickValue(), color.white);
AddLabel(showLabels and (LongTrades and ShortTrades), "Long+Short Trades", color.white);
AddLabel(showLabels and (LongTrades and !ShortTrades),"Long Trades Only", color.white);
AddLabel(showLabels and (!LongTrades and ShortTrades),"Short Trades Only", color.white);
AddLabel(showLabels and (tradeDaytimeOnly),"Daytime Only", color.white);
AddLabel(showLabels, "Closed Orders: " + ClosedTradeCount + " P/L: " + AsDollars(dollarPLSum), if dollarPLSum > 0 then Color.GREEN else if dollarPLSum< 0 then Color.RED else Color.GRAY);
AddLabel(if !IsNan(orderPrice) and showLabels then 1 else 0, "Closed+Open P/L: "+ AsDollars(TradePL+dollarPLSum), if ((TradePL+dollarPLSum) > 0) then color.green else if ((TradePL+dollarPLSum) < 0) then color.red else color.gray);

AddLabel(showLabels, "Avg per Trade: "+ AsDollars(avgTrade), if avgTrade > 0 then Color.Green else if avgTrade < 0 then Color.RED else Color.GRAY);
AddLabel(showLabels, "Winners: "+ PCTWin +"%",if PCTWin > 50 then color.green else if PCTWin > 40 then color.yellow else color.gray);

AddLabel(showLabels, "MaxUp: "+ AsDollars(biggestWin) +" MaxDown: "+AsDollars(biggestLoss), color.white);
AddLabel(showLabels, "Long Profit: " +AsDollars(profitLong), if profitLong > 0 then color.green else if profitLong < 0 then color.red else color.gray);
AddLabel(showLabels, "Short Profit: " +AsDollars(profitShort), if profitShort > 0 then color.green else if profitShort < 0 then color.red else color.gray);
AddLabel(if !IsNan(CurrentPosition) and showLabels and OpenTrades then 1 else 0, "Open: "+ (If isLong then "Bought" else "Sold") + " @ "+orderPrice, color.white);
AddLabel(if !IsNan(orderPrice) and showLabels and OpenTrades then 1 else 0, "Open Trade P/L: "+ AsDollars(TradePL), if (TradePL > 0) then color.green else if (TradePl < 0) then color.red else color.gray);



#######################################
##  Chart Bubbles for Profit/Loss
#######################################


AddChartBubble(showSignals and showBubbles and isOrder and isLong[1], low, "$"+dollarProfitLoss, if dollarProfitLoss == 0 then Color.LIGHT_GRAY else if dollarProfitLoss > 0 then Color.GREEN else color.Red, 0);
AddChartBubble(showSignals and showBubbles and isOrder and isShort[1], high,  "$"+dollarProfitLoss, if dollarProfitLoss == 0 then Color.LIGHT_GRAY else if dollarProfitLoss > 0 then Color.GREEN else color.Red, 1);

#AssignPriceColor(if CurrentPosition == 1 then color.green else if CurrentPosition == -1 then color.red else color.gray);
I like it and all the signals but how can I take the Profit and Loss Labels out or off?
 
I recently came upon a nice scalping strategy:
. I coded it for thinkscript and figured I should share it with all you wonderful people here. Designed for NQ 1m, but I see good, bigger trades on 2m as well (I have only traded it on sim thus far). On the 2m, it basically functions as a nice pullback entry in a trend. While the strat creator's only requirement is being above/below 10 ema, I decided to use a 10-20-50 ema filter to get rid of bad signals in chop. There is likely a better trend filter but this gets the job done. I prefer to use my own judgment on whether we're trending or not; the filter merely serves to clean up unnecessary arrows on my chart.

Enjoy, and I look forward to your feedback.

Code:
# Shimi's Scalp Pro Elite Platinum Extreme; Deluxe Edition.
# Based on Quant Trade Edge's Strategy in https://www.youtube.com/watch?v=lhW5czmfc14
# Original Strategy is for NQ 1 minute chart, long only above 10ema and short only below 10ema, risking 1 ATR for .5 ATR target.

# Start EMA
input price = close;
input length = 10;
input displace = 0;

def ema = expAverage(price[-displace], length);
def ema20 = expAverage (price, length=20);
def ema50 = expAverage (price, length=50);

def bull = close > open and low < low[1] and high < high[1] and close > ema and ema > ema20 and ema20 > ema50;
def bear = close < open and low > low[1] and high > high[1] and close < ema and ema < ema20 and ema20 < ema50;

plot upsignal = bull;
plot downsignal = bear;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Thanks for your work - on the QTE source video, he talks about using an ATR above 15. When I plot the ATR on TOS, I see good signals in the chart but the ATR is in the 2-4 range. What am I missing?
 
Thanks for your work - on the QTE source video, he talks about using an ATR above 15. When I plot the ATR on TOS, I see good signals in the chart but the ATR is in the 2-4 range. What am I missing?

I hope you don't mind I made some changes to the study to turn it into a strategy for backtesting with a Gandalf Pattern.
Works on all time frames, take a look at the 3m MNQ

Code:
input EnableStrategy = yes;
input UseMarketTime = no; #hint UseMarketTime: Use Trading hours?
input TradeTimeStart = 0930;
input TradeTimeEnd = 1555;
input UseTradeOffTradeTime = no;
input UseMarketTradeTimeToExitPositions = no; #hint UseMarketTradeTimeToExitPositions: Exit/Close open trades based on the market hours selected
input UseDateRange = no; #hint UseDateRange: Trade Signals within the date range specified
input ActiveStartDate = 20230101;
input ActiveEndDate = 20240101;

def activedaterange = GetYYYYMMDD() >= ActiveStartDate and GetYYYYMMDD() <= ActiveEndDate;
def activerange = if UseDateRange then  activedaterange else 1;
AddLabel(UseDateRange, if activerange then "Range " + AsPrice(ActiveStartDate) + " - " + AsPrice(ActiveEndDate) else ""  , Color.WHITE );

def Active = if GetDay() != GetDay()[1]
          then 0
          else if SecondsTillTime(TradeTimeStart) <= 0 and
                  SecondsTillTime(TradeTimeEnd) >= 0
            then 1
            else 0;

def ActiveTradeTime = if UseTradeOffTradeTime then !Active else if UseMarketTime then if SecondsTillTime(TradeTimeStart) <= 0 and
                           SecondsTillTime(TradeTimeEnd) >= 0  then 1 else 0
                    else 1;
def closeallmarket =   ( if UseMarketTime and UseTradeOffTradeTime then Active and !Active[1] and UseMarketTradeTimeToExitPositions else  !ActiveTradeTime and ActiveTradeTime[1])  and UseMarketTradeTimeToExitPositions;
input ShowTime = yes;

input TimeZone = 10.5;
def Hours = Floor(TimeZone + SecondsFromTime(0930) / 60 / 60) - 1;
def Minutes = ((TimeZone + SecondsFromTime(930) / 60 / 60) % 1) * 60;

AddLabel(ShowTime, " Market Time:  " + GetMonth() + "/" +  GetDayOfMonth(GetYYYYMMDD()) + "/"  + (AsPrice(GetYear()))  + ":" + Hours + ":" + Minutes ,
             if !IsNaN(GetTime())
             then Color.LIME
             else if IsNaN(GetTime())
                  then Color.PINK
                  else Color.WHITE);



AddOrder(OrderType.BUY_TO_CLOSE, EnableStrategy  and  closeallmarket, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "BxEdt@ " + open[-1]) ;
AddOrder(OrderType.SELL_TO_CLOSE, EnableStrategy and  closeallmarket, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SxEdt" + open[-1]);
AddOrder(OrderType.BUY_TO_CLOSE, EnableStrategy  and  !activerange, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "BxSession@ " + open[-1]) ;
AddOrder(OrderType.SELL_TO_CLOSE, EnableStrategy and  !activerange, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SxSession@" + open[-1]);
##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


# Shimi's Scalp Pro Elite Platinum Extreme; Deluxe Edition.
# Based on Quant Trade Edge's Strategy in https://www.youtube.com/watch?v=lhW5czmfc14
# Original Strategy is for NQ 1 minute chart, long only above 10ema and short only below 10ema, risking 1 ATR for .5 ATR target.

# Start EMA
input price = close;
input length = 10;
input displace = 0;

def ema = expAverage(price[-displace], length);
def ema20 = expAverage (price, length=20);
def ema50 = expAverage (price, length=50);

def bull = close > open and low < low[1] and high < high[1] and close > ema and ema > ema20 and ema20 > ema50;
def bear = close < open and low > low[1] and high > high[1] and close < ema and ema < ema20 and ema20 < ema50;

plot upsignal = bull;
plot downsignal = bear;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

def averagePrice = ohlc4;
def medianPrice = hl2;
def medianBodyPrice = MidBodyVal();

def entryGandaldfPattern = (averagePrice[1] < medianPrice[1] and
    medianPrice[2] <= averagePrice[1] and
    medianBodyPrice[2] <= averagePrice[3]) or
    (averagePrice[1] < medianPrice[3] and
    medianBodyPrice < medianPrice[2] and
    medianBodyPrice[1] < medianBodyPrice[2]);

def exitGandalfPattern = (averagePrice[1] < medianBodyPrice[1] and
    medianPrice[2] == medianBodyPrice[3] and
    medianBodyPrice[1] <= medianBodyPrice[4]) or
    (averagePrice[2] < medianBodyPrice and
    medianPrice[4] <= averagePrice[3] and
    medianBodyPrice[1] <= averagePrice[1]);

def wiz_buy = bull or (entryGandaldfPattern) ;
def wiz_sell = ( bear ) and (exitGandalfPattern or !entryGandaldfPattern);

input useAutoOrderswiz = yes;

AddOrder(OrderType.BUY_auto, EnableStrategy and activerange and ActiveTradeTime  and useAutoOrderswiz and wiz_buy, name =  "B(w>)@ "  + open[-1], price = open[-1], tickcolor = GetColor(1), arrowcolor = GetColor(1));
AddOrder(OrderType.sell_auto, EnableStrategy and activerange and ActiveTradeTime  and useAutoOrderswiz and wiz_sell, name =   "S(<w)@ "  + open[-1],  price = open[-1], tickcolor = GetColor(4), arrowcolor = GetColor(4));


#######################################
##  START of Strategies DashBoard
####################################
addOrder(OrderType.BUY_AUTO, no);
input enableDashBoard = yes;
input ShowStrategyCurrentPnlBubble = yes;
input ShowStrategyPnlBubble = no;
input ShowStrategyPnlEntryBubble = yes;
input ShowStrategyPnlVertical = no;
Input ShowStrategyProfitLossLabels = yes;
def fpl = FPL();
def StrategyEntryprice = if IsNaN(EntryPrice())  then 0 else EntryPrice();
def ep = entryprice();
def poschange = ( StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice == 0 ) or (  StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice[1] == 0  )   or (  StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice[1] > 0   and StrategyEntryprice[0] > 0 );
def pnlentry =  if  poschange  then  fpl[1] else pnlentry[1];
def currentprofit = fpl() - pnlentry[1];
def pnlprofit =  if pnlentry <> pnlentry[1] then  fpl()[1] - pnlentry[1] else 0  ;
def entryprofit = (if pnlprofit> 0 then 1 else -1 )  * absValue( if  poschange  then if StrategyEntryprice == 0 then open[0] - ep[1] else ep-ep[1] else 0) ;
def dollarentryprofitloss = Round(((entryprofit ) / TickSize()) * TickValue());
AddChartBubble(enableDashBoard and ShowStrategyPnlEntryBubble and poschange and absValue(dollarentryprofitloss  )>0, open[0], AsDollars(dollarentryprofitloss[0]), if dollarentryprofitloss[0] > 0 then Color.light_GREEN else if  dollarentryprofitloss[0] < 0 then Color.pink else Color.BLUE);
AddVerticalLine(ShowStrategyPnlVertical and ShowStrategyPnlEntryBubble and poschange, AsDollars(fpl) + " (" + dollarentryprofitloss + ")" ,  if dollarentryprofitloss > 0 then Color.GREEN else if dollarentryprofitloss < 0 then Color.RED else if pnlentry == 0 then Color.WHITE else Color.CYAN);
def fplpnlprofit = pnlprofit;
AddChartBubble(enableDashBoard and ShowStrategyPnlBubble and poschange[0] and absValue(fplpnlprofit  )>0, open[0], AsDollars(fplpnlprofit[0]), if fplpnlprofit[0] > 0 then Color.GREEN else if  fplpnlprofit[0] < 0 then Color.RED else Color.BLUE);
AddVerticalLine(enableDashBoard and ShowStrategyPnlVertical and ShowStrategyPnlBubble and poschange, AsDollars(fpl) + " (" + pnlprofit + ")" ,  if pnlprofit > 0 then Color.GREEN else if pnlprofit < 0 then Color.RED else if pnlentry == 0 then Color.WHITE else Color.CYAN);
def lastentry =if isnan( entryprice()) then lastentry[1] else entryprice() ;
AddChartBubble(enableDashBoard and ShowStrategyCurrentPnlBubble  and !IsNaN(close) and IsNaN(close [-1] ) and HighestAll(BarNumber()) and absValue(currentprofit)> 0, lastentry, AsDollars(currentprofit[0]), if currentprofit[0] > 0 then Color.green else if  currentprofit[0] < 0 then Color.red else Color.BLUE);

def pl = if ShowStrategyPnlEntryBubble then if isnan( dollarentryprofitloss) then 0 else dollarentryprofitloss else if isnan(fplpnlprofit) then 0 else fplpnlprofit;
def StrategyLongprofitLossSum = CompoundValue(1, if BarNumber() == 1 then 0 else if pl > 0 then StrategyLongprofitLossSum[1] + pl[0] else StrategyLongprofitLossSum[1], 0);
def StrategyShortprofitLossSum = CompoundValue(1, if BarNumber() == 1 then 0 else if pl < 0 then StrategyShortprofitLossSum[1] + pl[0] else StrategyShortprofitLossSum[1], 0);
def StrategyProfittradecnt = if  BarNumber() == 1 then 0 else if pl > 0 then StrategyProfittradecnt[1] + 1 else StrategyProfittradecnt[1] ;
def Strategylosstradecnt = if  BarNumber() == 1 then 0 else if pl < 0 then Strategylosstradecnt[1] + 1 else Strategylosstradecnt[1] ;
def Strategytradecnt = StrategyProfittradecnt + Strategylosstradecnt;
# What percent were winners
def StrategyPCTWin = Round(((StrategyProfittradecnt) / (Strategytradecnt)) * 100, 2) ;
def StrategyPCTLoss = Round(((Strategylosstradecnt) / (Strategytradecnt)) * 100, 2) ;
def StrategyPCTWinamt = Round(((absValue(StrategyLongprofitLossSum/StrategyProfittradecnt)) /absValue( (StrategyLongprofitLossSum/StrategyProfittradecnt) + absValue(StrategyShortprofitLossSum/Strategytradecnt))) * 1, 2) ;
def PCTLossamt =  Round(((absValue(StrategyShortprofitLossSum/Strategylosstradecnt)) /absValue( (StrategyLongprofitLossSum/StrategyProfittradecnt) + absValue(StrategyShortprofitLossSum/Strategytradecnt))) * 1, 2) ;
plot PltEntryPrice = if enableDashBoard then  ep else double.nan;
PltEntryPrice.SetPaintingStrategy(PaintingStrategy.DASHES);
PltEntryPrice.SetdefaultColor(color.cyan);
PltEntryPrice.assignValueColor(if currentprofit then color.green else
if entryprofit < 0 then color.red else color.cyan );

def Strategylowestdrawdown =  min(if isnan(currentprofit) then 0 else currentprofit,Strategylowestdrawdown[1]);
def StrategyHigestdrawUp =  max(if isnan(currentprofit) then 0 else currentprofit,StrategyHigestdrawUp[1]);
def Strategylowestloss = min(pl,Strategylowestloss[1]);
def highestwin = max(pl,highestwin[1]);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels,"Last Entry: "+lastentry +"("+currentprofit +")" ,if currentprofit > 0 then color.light_green else if currentprofit < 0 then color.light_red else color.cyan );
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PNL: " + (FPL()), if FPL() > 0 then Color.LIME else Color.RED);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Winners: " + StrategyPCTWin + "%", if StrategyPCTWin > 50 then Color.GREEN else if StrategyPCTWin > 40 then Color.YELLOW else Color.GRAY);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "ProfitLossSum: " + (StrategyLongprofitLossSum + StrategyShortprofitLossSum), if (StrategyLongprofitLossSum + StrategyShortprofitLossSum) > 0 then Color.LIME else Color.RED);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "ShortprofitLossSum: " + (StrategyShortprofitLossSum), Color.pink);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "LongprofitLossSum: " + (StrategyLongprofitLossSum), Color.LIME);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Trades: " + (Strategytradecnt), Color.WHITE);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Profit Trades: " + (StrategyProfittradecnt), if StrategyProfittradecnt > Strategylosstradecnt then Color.LIME else Color.RED);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Loss Trades: " + (Strategylosstradecnt), if StrategyProfittradecnt < Strategylosstradecnt then Color.LIME else Color.pink);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Profit Factor: " +round(absvalue (StrategyLongprofitLossSum/StrategyShortprofitLossSum)),color.cyan);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Lowest Loss: " + (Strategylowestloss), Color.pink);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Lowest DrawDown: " + (Strategylowestdrawdown), Color.pink);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Highest DrawUp: " + (StrategyHigestdrawUp), Color.LIME);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Highest Win: " + (highestwin), Color.LIME);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PCTWin Trades: " + (StrategyPCTWin), Color.GREEN);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PCTLoss Trades: " + (StrategyPCTLoss), Color.PINK);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PCTWin Amount: " + (StrategyPCTWinamt), Color.GREEN);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PCTLoss Amount: " + (PCTLossamt), Color.PINK);
def firstentry = if Strategytradecnt ==1 then close[1] else firstentry[1];
def buyandhold = Round(((close - firstentry ) / TickSize()) * TickValue());
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Buy&Hold: " + (buyandhold), if buyandhold > 0 then Color.LIME else Color.RED);
#######################################
##  END of Strategy DashBoard
#######################################
 
  • Love
Reactions: IPA
I hope you don't mind I made some changes to the study to turn it into a strategy for backtesting with a Gandalf Pattern.
Works on all time frames, take a look at the 3m MNQ

Code:
input EnableStrategy = yes;
input UseMarketTime = no; #hint UseMarketTime: Use Trading hours?
input TradeTimeStart = 0930;
input TradeTimeEnd = 1555;
input UseTradeOffTradeTime = no;
input UseMarketTradeTimeToExitPositions = no; #hint UseMarketTradeTimeToExitPositions: Exit/Close open trades based on the market hours selected
input UseDateRange = no; #hint UseDateRange: Trade Signals within the date range specified
input ActiveStartDate = 20230101;
input ActiveEndDate = 20240101;

def activedaterange = GetYYYYMMDD() >= ActiveStartDate and GetYYYYMMDD() <= ActiveEndDate;
def activerange = if UseDateRange then  activedaterange else 1;
AddLabel(UseDateRange, if activerange then "Range " + AsPrice(ActiveStartDate) + " - " + AsPrice(ActiveEndDate) else ""  , Color.WHITE );

def Active = if GetDay() != GetDay()[1]
          then 0
          else if SecondsTillTime(TradeTimeStart) <= 0 and
                  SecondsTillTime(TradeTimeEnd) >= 0
            then 1
            else 0;

def ActiveTradeTime = if UseTradeOffTradeTime then !Active else if UseMarketTime then if SecondsTillTime(TradeTimeStart) <= 0 and
                           SecondsTillTime(TradeTimeEnd) >= 0  then 1 else 0
                    else 1;
def closeallmarket =   ( if UseMarketTime and UseTradeOffTradeTime then Active and !Active[1] and UseMarketTradeTimeToExitPositions else  !ActiveTradeTime and ActiveTradeTime[1])  and UseMarketTradeTimeToExitPositions;
input ShowTime = yes;

input TimeZone = 10.5;
def Hours = Floor(TimeZone + SecondsFromTime(0930) / 60 / 60) - 1;
def Minutes = ((TimeZone + SecondsFromTime(930) / 60 / 60) % 1) * 60;

AddLabel(ShowTime, " Market Time:  " + GetMonth() + "/" +  GetDayOfMonth(GetYYYYMMDD()) + "/"  + (AsPrice(GetYear()))  + ":" + Hours + ":" + Minutes ,
             if !IsNaN(GetTime())
             then Color.LIME
             else if IsNaN(GetTime())
                  then Color.PINK
                  else Color.WHITE);



AddOrder(OrderType.BUY_TO_CLOSE, EnableStrategy  and  closeallmarket, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "BxEdt@ " + open[-1]) ;
AddOrder(OrderType.SELL_TO_CLOSE, EnableStrategy and  closeallmarket, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SxEdt" + open[-1]);
AddOrder(OrderType.BUY_TO_CLOSE, EnableStrategy  and  !activerange, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "BxSession@ " + open[-1]) ;
AddOrder(OrderType.SELL_TO_CLOSE, EnableStrategy and  !activerange, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SxSession@" + open[-1]);
##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


# Shimi's Scalp Pro Elite Platinum Extreme; Deluxe Edition.
# Based on Quant Trade Edge's Strategy in https://www.youtube.com/watch?v=lhW5czmfc14
# Original Strategy is for NQ 1 minute chart, long only above 10ema and short only below 10ema, risking 1 ATR for .5 ATR target.

# Start EMA
input price = close;
input length = 10;
input displace = 0;

def ema = expAverage(price[-displace], length);
def ema20 = expAverage (price, length=20);
def ema50 = expAverage (price, length=50);

def bull = close > open and low < low[1] and high < high[1] and close > ema and ema > ema20 and ema20 > ema50;
def bear = close < open and low > low[1] and high > high[1] and close < ema and ema < ema20 and ema20 < ema50;

plot upsignal = bull;
plot downsignal = bear;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

def averagePrice = ohlc4;
def medianPrice = hl2;
def medianBodyPrice = MidBodyVal();

def entryGandaldfPattern = (averagePrice[1] < medianPrice[1] and
    medianPrice[2] <= averagePrice[1] and
    medianBodyPrice[2] <= averagePrice[3]) or
    (averagePrice[1] < medianPrice[3] and
    medianBodyPrice < medianPrice[2] and
    medianBodyPrice[1] < medianBodyPrice[2]);

def exitGandalfPattern = (averagePrice[1] < medianBodyPrice[1] and
    medianPrice[2] == medianBodyPrice[3] and
    medianBodyPrice[1] <= medianBodyPrice[4]) or
    (averagePrice[2] < medianBodyPrice and
    medianPrice[4] <= averagePrice[3] and
    medianBodyPrice[1] <= averagePrice[1]);

def wiz_buy = bull or (entryGandaldfPattern) ;
def wiz_sell = ( bear ) and (exitGandalfPattern or !entryGandaldfPattern);

input useAutoOrderswiz = yes;

AddOrder(OrderType.BUY_auto, EnableStrategy and activerange and ActiveTradeTime  and useAutoOrderswiz and wiz_buy, name =  "B(w>)@ "  + open[-1], price = open[-1], tickcolor = GetColor(1), arrowcolor = GetColor(1));
AddOrder(OrderType.sell_auto, EnableStrategy and activerange and ActiveTradeTime  and useAutoOrderswiz and wiz_sell, name =   "S(<w)@ "  + open[-1],  price = open[-1], tickcolor = GetColor(4), arrowcolor = GetColor(4));


#######################################
##  START of Strategies DashBoard
####################################
addOrder(OrderType.BUY_AUTO, no);
input enableDashBoard = yes;
input ShowStrategyCurrentPnlBubble = yes;
input ShowStrategyPnlBubble = no;
input ShowStrategyPnlEntryBubble = yes;
input ShowStrategyPnlVertical = no;
Input ShowStrategyProfitLossLabels = yes;
def fpl = FPL();
def StrategyEntryprice = if IsNaN(EntryPrice())  then 0 else EntryPrice();
def ep = entryprice();
def poschange = ( StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice == 0 ) or (  StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice[1] == 0  )   or (  StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice[1] > 0   and StrategyEntryprice[0] > 0 );
def pnlentry =  if  poschange  then  fpl[1] else pnlentry[1];
def currentprofit = fpl() - pnlentry[1];
def pnlprofit =  if pnlentry <> pnlentry[1] then  fpl()[1] - pnlentry[1] else 0  ;
def entryprofit = (if pnlprofit> 0 then 1 else -1 )  * absValue( if  poschange  then if StrategyEntryprice == 0 then open[0] - ep[1] else ep-ep[1] else 0) ;
def dollarentryprofitloss = Round(((entryprofit ) / TickSize()) * TickValue());
AddChartBubble(enableDashBoard and ShowStrategyPnlEntryBubble and poschange and absValue(dollarentryprofitloss  )>0, open[0], AsDollars(dollarentryprofitloss[0]), if dollarentryprofitloss[0] > 0 then Color.light_GREEN else if  dollarentryprofitloss[0] < 0 then Color.pink else Color.BLUE);
AddVerticalLine(ShowStrategyPnlVertical and ShowStrategyPnlEntryBubble and poschange, AsDollars(fpl) + " (" + dollarentryprofitloss + ")" ,  if dollarentryprofitloss > 0 then Color.GREEN else if dollarentryprofitloss < 0 then Color.RED else if pnlentry == 0 then Color.WHITE else Color.CYAN);
def fplpnlprofit = pnlprofit;
AddChartBubble(enableDashBoard and ShowStrategyPnlBubble and poschange[0] and absValue(fplpnlprofit  )>0, open[0], AsDollars(fplpnlprofit[0]), if fplpnlprofit[0] > 0 then Color.GREEN else if  fplpnlprofit[0] < 0 then Color.RED else Color.BLUE);
AddVerticalLine(enableDashBoard and ShowStrategyPnlVertical and ShowStrategyPnlBubble and poschange, AsDollars(fpl) + " (" + pnlprofit + ")" ,  if pnlprofit > 0 then Color.GREEN else if pnlprofit < 0 then Color.RED else if pnlentry == 0 then Color.WHITE else Color.CYAN);
def lastentry =if isnan( entryprice()) then lastentry[1] else entryprice() ;
AddChartBubble(enableDashBoard and ShowStrategyCurrentPnlBubble  and !IsNaN(close) and IsNaN(close [-1] ) and HighestAll(BarNumber()) and absValue(currentprofit)> 0, lastentry, AsDollars(currentprofit[0]), if currentprofit[0] > 0 then Color.green else if  currentprofit[0] < 0 then Color.red else Color.BLUE);

def pl = if ShowStrategyPnlEntryBubble then if isnan( dollarentryprofitloss) then 0 else dollarentryprofitloss else if isnan(fplpnlprofit) then 0 else fplpnlprofit;
def StrategyLongprofitLossSum = CompoundValue(1, if BarNumber() == 1 then 0 else if pl > 0 then StrategyLongprofitLossSum[1] + pl[0] else StrategyLongprofitLossSum[1], 0);
def StrategyShortprofitLossSum = CompoundValue(1, if BarNumber() == 1 then 0 else if pl < 0 then StrategyShortprofitLossSum[1] + pl[0] else StrategyShortprofitLossSum[1], 0);
def StrategyProfittradecnt = if  BarNumber() == 1 then 0 else if pl > 0 then StrategyProfittradecnt[1] + 1 else StrategyProfittradecnt[1] ;
def Strategylosstradecnt = if  BarNumber() == 1 then 0 else if pl < 0 then Strategylosstradecnt[1] + 1 else Strategylosstradecnt[1] ;
def Strategytradecnt = StrategyProfittradecnt + Strategylosstradecnt;
# What percent were winners
def StrategyPCTWin = Round(((StrategyProfittradecnt) / (Strategytradecnt)) * 100, 2) ;
def StrategyPCTLoss = Round(((Strategylosstradecnt) / (Strategytradecnt)) * 100, 2) ;
def StrategyPCTWinamt = Round(((absValue(StrategyLongprofitLossSum/StrategyProfittradecnt)) /absValue( (StrategyLongprofitLossSum/StrategyProfittradecnt) + absValue(StrategyShortprofitLossSum/Strategytradecnt))) * 1, 2) ;
def PCTLossamt =  Round(((absValue(StrategyShortprofitLossSum/Strategylosstradecnt)) /absValue( (StrategyLongprofitLossSum/StrategyProfittradecnt) + absValue(StrategyShortprofitLossSum/Strategytradecnt))) * 1, 2) ;
plot PltEntryPrice = if enableDashBoard then  ep else double.nan;
PltEntryPrice.SetPaintingStrategy(PaintingStrategy.DASHES);
PltEntryPrice.SetdefaultColor(color.cyan);
PltEntryPrice.assignValueColor(if currentprofit then color.green else
if entryprofit < 0 then color.red else color.cyan );

def Strategylowestdrawdown =  min(if isnan(currentprofit) then 0 else currentprofit,Strategylowestdrawdown[1]);
def StrategyHigestdrawUp =  max(if isnan(currentprofit) then 0 else currentprofit,StrategyHigestdrawUp[1]);
def Strategylowestloss = min(pl,Strategylowestloss[1]);
def highestwin = max(pl,highestwin[1]);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels,"Last Entry: "+lastentry +"("+currentprofit +")" ,if currentprofit > 0 then color.light_green else if currentprofit < 0 then color.light_red else color.cyan );
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PNL: " + (FPL()), if FPL() > 0 then Color.LIME else Color.RED);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Winners: " + StrategyPCTWin + "%", if StrategyPCTWin > 50 then Color.GREEN else if StrategyPCTWin > 40 then Color.YELLOW else Color.GRAY);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "ProfitLossSum: " + (StrategyLongprofitLossSum + StrategyShortprofitLossSum), if (StrategyLongprofitLossSum + StrategyShortprofitLossSum) > 0 then Color.LIME else Color.RED);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "ShortprofitLossSum: " + (StrategyShortprofitLossSum), Color.pink);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "LongprofitLossSum: " + (StrategyLongprofitLossSum), Color.LIME);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Trades: " + (Strategytradecnt), Color.WHITE);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Profit Trades: " + (StrategyProfittradecnt), if StrategyProfittradecnt > Strategylosstradecnt then Color.LIME else Color.RED);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Loss Trades: " + (Strategylosstradecnt), if StrategyProfittradecnt < Strategylosstradecnt then Color.LIME else Color.pink);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Profit Factor: " +round(absvalue (StrategyLongprofitLossSum/StrategyShortprofitLossSum)),color.cyan);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Lowest Loss: " + (Strategylowestloss), Color.pink);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Lowest DrawDown: " + (Strategylowestdrawdown), Color.pink);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Highest DrawUp: " + (StrategyHigestdrawUp), Color.LIME);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Highest Win: " + (highestwin), Color.LIME);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PCTWin Trades: " + (StrategyPCTWin), Color.GREEN);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PCTLoss Trades: " + (StrategyPCTLoss), Color.PINK);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PCTWin Amount: " + (StrategyPCTWinamt), Color.GREEN);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PCTLoss Amount: " + (PCTLossamt), Color.PINK);
def firstentry = if Strategytradecnt ==1 then close[1] else firstentry[1];
def buyandhold = Round(((close - firstentry ) / TickSize()) * TickValue());
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Buy&Hold: " + (buyandhold), if buyandhold > 0 then Color.LIME else Color.RED);
#######################################
##  END of Strategy DashBoard
#######################################
I am not seeing anything on my chart?
using regular candles. What is wrong?
 
I hope you don't mind I made some changes to the study to turn it into a strategy for backtesting with a Gandalf Pattern.
Works on all time frames, take a look at the 3m MNQ

Code:
input EnableStrategy = yes;
input UseMarketTime = no; #hint UseMarketTime: Use Trading hours?
input TradeTimeStart = 0930;
input TradeTimeEnd = 1555;
input UseTradeOffTradeTime = no;
input UseMarketTradeTimeToExitPositions = no; #hint UseMarketTradeTimeToExitPositions: Exit/Close open trades based on the market hours selected
input UseDateRange = no; #hint UseDateRange: Trade Signals within the date range specified
input ActiveStartDate = 20230101;
input ActiveEndDate = 20240101;

def activedaterange = GetYYYYMMDD() >= ActiveStartDate and GetYYYYMMDD() <= ActiveEndDate;
def activerange = if UseDateRange then  activedaterange else 1;
AddLabel(UseDateRange, if activerange then "Range " + AsPrice(ActiveStartDate) + " - " + AsPrice(ActiveEndDate) else ""  , Color.WHITE );

def Active = if GetDay() != GetDay()[1]
          then 0
          else if SecondsTillTime(TradeTimeStart) <= 0 and
                  SecondsTillTime(TradeTimeEnd) >= 0
            then 1
            else 0;

def ActiveTradeTime = if UseTradeOffTradeTime then !Active else if UseMarketTime then if SecondsTillTime(TradeTimeStart) <= 0 and
                           SecondsTillTime(TradeTimeEnd) >= 0  then 1 else 0
                    else 1;
def closeallmarket =   ( if UseMarketTime and UseTradeOffTradeTime then Active and !Active[1] and UseMarketTradeTimeToExitPositions else  !ActiveTradeTime and ActiveTradeTime[1])  and UseMarketTradeTimeToExitPositions;
input ShowTime = yes;

input TimeZone = 10.5;
def Hours = Floor(TimeZone + SecondsFromTime(0930) / 60 / 60) - 1;
def Minutes = ((TimeZone + SecondsFromTime(930) / 60 / 60) % 1) * 60;

AddLabel(ShowTime, " Market Time:  " + GetMonth() + "/" +  GetDayOfMonth(GetYYYYMMDD()) + "/"  + (AsPrice(GetYear()))  + ":" + Hours + ":" + Minutes ,
             if !IsNaN(GetTime())
             then Color.LIME
             else if IsNaN(GetTime())
                  then Color.PINK
                  else Color.WHITE);



AddOrder(OrderType.BUY_TO_CLOSE, EnableStrategy  and  closeallmarket, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "BxEdt@ " + open[-1]) ;
AddOrder(OrderType.SELL_TO_CLOSE, EnableStrategy and  closeallmarket, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SxEdt" + open[-1]);
AddOrder(OrderType.BUY_TO_CLOSE, EnableStrategy  and  !activerange, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "BxSession@ " + open[-1]) ;
AddOrder(OrderType.SELL_TO_CLOSE, EnableStrategy and  !activerange, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SxSession@" + open[-1]);
##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


# Shimi's Scalp Pro Elite Platinum Extreme; Deluxe Edition.
# Based on Quant Trade Edge's Strategy in https://www.youtube.com/watch?v=lhW5czmfc14
# Original Strategy is for NQ 1 minute chart, long only above 10ema and short only below 10ema, risking 1 ATR for .5 ATR target.

# Start EMA
input price = close;
input length = 10;
input displace = 0;

def ema = expAverage(price[-displace], length);
def ema20 = expAverage (price, length=20);
def ema50 = expAverage (price, length=50);

def bull = close > open and low < low[1] and high < high[1] and close > ema and ema > ema20 and ema20 > ema50;
def bear = close < open and low > low[1] and high > high[1] and close < ema and ema < ema20 and ema20 < ema50;

plot upsignal = bull;
plot downsignal = bear;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

def averagePrice = ohlc4;
def medianPrice = hl2;
def medianBodyPrice = MidBodyVal();

def entryGandaldfPattern = (averagePrice[1] < medianPrice[1] and
    medianPrice[2] <= averagePrice[1] and
    medianBodyPrice[2] <= averagePrice[3]) or
    (averagePrice[1] < medianPrice[3] and
    medianBodyPrice < medianPrice[2] and
    medianBodyPrice[1] < medianBodyPrice[2]);

def exitGandalfPattern = (averagePrice[1] < medianBodyPrice[1] and
    medianPrice[2] == medianBodyPrice[3] and
    medianBodyPrice[1] <= medianBodyPrice[4]) or
    (averagePrice[2] < medianBodyPrice and
    medianPrice[4] <= averagePrice[3] and
    medianBodyPrice[1] <= averagePrice[1]);

def wiz_buy = bull or (entryGandaldfPattern) ;
def wiz_sell = ( bear ) and (exitGandalfPattern or !entryGandaldfPattern);

input useAutoOrderswiz = yes;

AddOrder(OrderType.BUY_auto, EnableStrategy and activerange and ActiveTradeTime  and useAutoOrderswiz and wiz_buy, name =  "B(w>)@ "  + open[-1], price = open[-1], tickcolor = GetColor(1), arrowcolor = GetColor(1));
AddOrder(OrderType.sell_auto, EnableStrategy and activerange and ActiveTradeTime  and useAutoOrderswiz and wiz_sell, name =   "S(<w)@ "  + open[-1],  price = open[-1], tickcolor = GetColor(4), arrowcolor = GetColor(4));


#######################################
##  START of Strategies DashBoard
####################################
addOrder(OrderType.BUY_AUTO, no);
input enableDashBoard = yes;
input ShowStrategyCurrentPnlBubble = yes;
input ShowStrategyPnlBubble = no;
input ShowStrategyPnlEntryBubble = yes;
input ShowStrategyPnlVertical = no;
Input ShowStrategyProfitLossLabels = yes;
def fpl = FPL();
def StrategyEntryprice = if IsNaN(EntryPrice())  then 0 else EntryPrice();
def ep = entryprice();
def poschange = ( StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice == 0 ) or (  StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice[1] == 0  )   or (  StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice[1] > 0   and StrategyEntryprice[0] > 0 );
def pnlentry =  if  poschange  then  fpl[1] else pnlentry[1];
def currentprofit = fpl() - pnlentry[1];
def pnlprofit =  if pnlentry <> pnlentry[1] then  fpl()[1] - pnlentry[1] else 0  ;
def entryprofit = (if pnlprofit> 0 then 1 else -1 )  * absValue( if  poschange  then if StrategyEntryprice == 0 then open[0] - ep[1] else ep-ep[1] else 0) ;
def dollarentryprofitloss = Round(((entryprofit ) / TickSize()) * TickValue());
AddChartBubble(enableDashBoard and ShowStrategyPnlEntryBubble and poschange and absValue(dollarentryprofitloss  )>0, open[0], AsDollars(dollarentryprofitloss[0]), if dollarentryprofitloss[0] > 0 then Color.light_GREEN else if  dollarentryprofitloss[0] < 0 then Color.pink else Color.BLUE);
AddVerticalLine(ShowStrategyPnlVertical and ShowStrategyPnlEntryBubble and poschange, AsDollars(fpl) + " (" + dollarentryprofitloss + ")" ,  if dollarentryprofitloss > 0 then Color.GREEN else if dollarentryprofitloss < 0 then Color.RED else if pnlentry == 0 then Color.WHITE else Color.CYAN);
def fplpnlprofit = pnlprofit;
AddChartBubble(enableDashBoard and ShowStrategyPnlBubble and poschange[0] and absValue(fplpnlprofit  )>0, open[0], AsDollars(fplpnlprofit[0]), if fplpnlprofit[0] > 0 then Color.GREEN else if  fplpnlprofit[0] < 0 then Color.RED else Color.BLUE);
AddVerticalLine(enableDashBoard and ShowStrategyPnlVertical and ShowStrategyPnlBubble and poschange, AsDollars(fpl) + " (" + pnlprofit + ")" ,  if pnlprofit > 0 then Color.GREEN else if pnlprofit < 0 then Color.RED else if pnlentry == 0 then Color.WHITE else Color.CYAN);
def lastentry =if isnan( entryprice()) then lastentry[1] else entryprice() ;
AddChartBubble(enableDashBoard and ShowStrategyCurrentPnlBubble  and !IsNaN(close) and IsNaN(close [-1] ) and HighestAll(BarNumber()) and absValue(currentprofit)> 0, lastentry, AsDollars(currentprofit[0]), if currentprofit[0] > 0 then Color.green else if  currentprofit[0] < 0 then Color.red else Color.BLUE);

def pl = if ShowStrategyPnlEntryBubble then if isnan( dollarentryprofitloss) then 0 else dollarentryprofitloss else if isnan(fplpnlprofit) then 0 else fplpnlprofit;
def StrategyLongprofitLossSum = CompoundValue(1, if BarNumber() == 1 then 0 else if pl > 0 then StrategyLongprofitLossSum[1] + pl[0] else StrategyLongprofitLossSum[1], 0);
def StrategyShortprofitLossSum = CompoundValue(1, if BarNumber() == 1 then 0 else if pl < 0 then StrategyShortprofitLossSum[1] + pl[0] else StrategyShortprofitLossSum[1], 0);
def StrategyProfittradecnt = if  BarNumber() == 1 then 0 else if pl > 0 then StrategyProfittradecnt[1] + 1 else StrategyProfittradecnt[1] ;
def Strategylosstradecnt = if  BarNumber() == 1 then 0 else if pl < 0 then Strategylosstradecnt[1] + 1 else Strategylosstradecnt[1] ;
def Strategytradecnt = StrategyProfittradecnt + Strategylosstradecnt;
# What percent were winners
def StrategyPCTWin = Round(((StrategyProfittradecnt) / (Strategytradecnt)) * 100, 2) ;
def StrategyPCTLoss = Round(((Strategylosstradecnt) / (Strategytradecnt)) * 100, 2) ;
def StrategyPCTWinamt = Round(((absValue(StrategyLongprofitLossSum/StrategyProfittradecnt)) /absValue( (StrategyLongprofitLossSum/StrategyProfittradecnt) + absValue(StrategyShortprofitLossSum/Strategytradecnt))) * 1, 2) ;
def PCTLossamt =  Round(((absValue(StrategyShortprofitLossSum/Strategylosstradecnt)) /absValue( (StrategyLongprofitLossSum/StrategyProfittradecnt) + absValue(StrategyShortprofitLossSum/Strategytradecnt))) * 1, 2) ;
plot PltEntryPrice = if enableDashBoard then  ep else double.nan;
PltEntryPrice.SetPaintingStrategy(PaintingStrategy.DASHES);
PltEntryPrice.SetdefaultColor(color.cyan);
PltEntryPrice.assignValueColor(if currentprofit then color.green else
if entryprofit < 0 then color.red else color.cyan );

def Strategylowestdrawdown =  min(if isnan(currentprofit) then 0 else currentprofit,Strategylowestdrawdown[1]);
def StrategyHigestdrawUp =  max(if isnan(currentprofit) then 0 else currentprofit,StrategyHigestdrawUp[1]);
def Strategylowestloss = min(pl,Strategylowestloss[1]);
def highestwin = max(pl,highestwin[1]);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels,"Last Entry: "+lastentry +"("+currentprofit +")" ,if currentprofit > 0 then color.light_green else if currentprofit < 0 then color.light_red else color.cyan );
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PNL: " + (FPL()), if FPL() > 0 then Color.LIME else Color.RED);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Winners: " + StrategyPCTWin + "%", if StrategyPCTWin > 50 then Color.GREEN else if StrategyPCTWin > 40 then Color.YELLOW else Color.GRAY);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "ProfitLossSum: " + (StrategyLongprofitLossSum + StrategyShortprofitLossSum), if (StrategyLongprofitLossSum + StrategyShortprofitLossSum) > 0 then Color.LIME else Color.RED);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "ShortprofitLossSum: " + (StrategyShortprofitLossSum), Color.pink);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "LongprofitLossSum: " + (StrategyLongprofitLossSum), Color.LIME);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Trades: " + (Strategytradecnt), Color.WHITE);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Profit Trades: " + (StrategyProfittradecnt), if StrategyProfittradecnt > Strategylosstradecnt then Color.LIME else Color.RED);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Loss Trades: " + (Strategylosstradecnt), if StrategyProfittradecnt < Strategylosstradecnt then Color.LIME else Color.pink);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Profit Factor: " +round(absvalue (StrategyLongprofitLossSum/StrategyShortprofitLossSum)),color.cyan);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Lowest Loss: " + (Strategylowestloss), Color.pink);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Lowest DrawDown: " + (Strategylowestdrawdown), Color.pink);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Highest DrawUp: " + (StrategyHigestdrawUp), Color.LIME);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Highest Win: " + (highestwin), Color.LIME);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PCTWin Trades: " + (StrategyPCTWin), Color.GREEN);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PCTLoss Trades: " + (StrategyPCTLoss), Color.PINK);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PCTWin Amount: " + (StrategyPCTWinamt), Color.GREEN);
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "PCTLoss Amount: " + (PCTLossamt), Color.PINK);
def firstentry = if Strategytradecnt ==1 then close[1] else firstentry[1];
def buyandhold = Round(((close - firstentry ) / TickSize()) * TickValue());
AddLabel(enableDashBoard and ShowStrategyProfitLossLabels, "Buy&Hold: " + (buyandhold), if buyandhold > 0 then Color.LIME else Color.RED);
#######################################
##  END of Strategy DashBoard
#######################################
@Ramisegal Could you help me with part of the logic in this strategy? Where in this strategy causes the scalping piece? When looking at the logic I don't see how buys and sells more frequently. On another platform trying to create this, it doesn't show as frequent buy/sells.
1708704660981.png
 
@Ramisegal Could you help me with part of the logic in this strategy? Where in this strategy causes the scalping piece? When looking at the logic I don't see how buys and sells more frequently. On another platform trying to create this, it doesn't show as frequent buy/sells.View attachment 21143
Lol
I did not name this strategy only included the Gandalf pattern in its entry logic.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
444 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top