This strategy was set up for swingtrading. As you can see I added EOD, I need to reset each day in order to run it as a DayTrade. Can you help?
Like below example due to market not open yet
Code:
#[email protected]
#positioning
input usetimefilter = yes;
input rthopen = 0930;
input rthclose = 1600;
def RTH = if usetimefilter == yes then if SecondsFromTime(rthopen) >= 0 and
SecondsTillTime(rthclose) >= 0
then 1
else 0 else 1;
input avglength = 14;
input MTaverageType = AverageType.WILDERS;
input ATRLength = 5;
input MTprice = hlc3;
input MTreversalMode = {default ATRpercent, price};
input MTreversalAmount = .5;
##DayATR Value Calculation
def highPrice = FundamentalType.HIGH;
def closePrice = FundamentalType.CLOSE;
def lowPrice = FundamentalType.LOW;
def aggregationPeriod = AggregationPeriod.DAY;
rec AvgTrueRange = MovingAverage(AverageType.SIMPLE, TrueRange(Fundamental (highPrice, period = AggregationPeriod.DAY), Fundamental (closePrice, period = AggregationPeriod.DAY), Fundamental (lowPrice, period = AggregationPeriod.DAY) ), ATRLength);
##############
##ATR percent conversion calculation
rec DayATRReversalValue = MTreversalAmount * (AvgTrueRange / close) * 100;
def mode = if MTreversalMode == MTreversalMode.price then ZigZagTrendSign(price = MTprice, reversalAmount = MTreversalAmount) else ZigZagTrendPercent(price = MTprice, reversalAmount = DayATRReversalValue);
def MTinflection = if MTreversalMode == MTreversalMode.price then if !IsNaN(ZigZagSign(price = MTprice, reversalAmount = MTreversalAmount)) then 1 else 0 else if !IsNaN(ZigZagPercent(price = MTprice, reversalAmount = DayATRReversalValue)) then 1 else 0;
rec MTtrend = if MTinflection == 1 and mode == -1 then 1 else if MTinflection == 1 and mode == 1 then -1 else MTtrend[1];
rec MTupWaveVolume = if MTinflection == 1 and MTtrend == 1 and close > open then volume else if MTinflection == 1 and MTtrend == 1 and close <= open then 0 else if MTtrend == 1 or (MTinflection == 1 and MTtrend == -1 and close >= open) then MTupWaveVolume[1] + volume else 0;
rec MTdownWaveVolume = if MTinflection == 1 and MTtrend == -1 and close < open then volume else if MTinflection == 1 and MTtrend == -1 and close >= open then 0 else if MTtrend == -1 or (MTinflection == 1 and MTtrend == 1 and close <= open) then MTdownWaveVolume[1] + volume else 0;
plot BuySignal = MTinflection[1] and MTdownWaveVolume[2] > 0;
BuySignal.SetDefaultColor(Color.CYAN);
BuySignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuySignal.SetLineWeight(4);
plot SellSignal = MTinflection[1] and MTupWaveVolume[2] > 0;
SellSignal.SetDefaultColor(Color.MAGENTA);
SellSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellSignal.SetLineWeight(4);
def Buy_Time = if MTinflection[1] and MTdownWaveVolume[2] > 0 then 1 else 0;
def Buy_Signal = if RTH == 1 > SecondsTillTime(0930) and Buy_Time == 1 then 1 else 0;
def Sell_Signal = if MTinflection[1] and MTupWaveVolume[2] > 0 then 1 else 0;
def EOD = RTH == 1 > SecondsTillTime(2000);
def orderPrice = open[-1]+((open[-1]+close[-1])/2);
AddOrder(OrderType.BUY_TO_OPEN, RTH and Buy_Signal, price = orderPrice, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "ST_LE");
AddOrder(OrderType.SELL_TO_CLOSE, RTH and Sell_Signal, price = orderPrice, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "ST_SE");
AddOrder(OrderType.SELL_TO_CLOSE, EOD, price = orderPrice, tickcolor = GetColor(9), arrowcolor = GetColor(7), name = "CDS_EOD");
##input MTVolumeAudible_Alert = yes;
def MTVolumeDeviation_Length = 60;
def MTVolumeDeviate = 2;
def MTvolumestdevlength = RelativeVolumeStDev(length = MTVolumeDeviation_Length);
def abovedev = MTvolumestdevlength >= MTVolumeDeviate;
def belowdev = MTvolumestdevlength <= MTVolumeDeviate;
def MTvolumeincrease = volume > volume[1];
def MTvolumedevincrease = MTvolumeincrease and abovedev;
def MTvolumedecrease = volume < volume[1];
def MTvolumedevdecrease = MTvolumedecrease and abovedev;
def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def MTvolumeBuying = V * (C - L) / (H - L);
def MTvolumeSelling = V * (H - C) / (H - L);
input Show_Labels = yes;
AddLabel(Show_Labels, "Buy Vol = " + Round(MTvolumeBuying, 0), if MTvolumeBuying > MTvolumeSelling then Color.GREEN else Color.RED);
AddLabel(Show_Labels, "Sell Vol = " + Round(MTvolumeSelling, 0), if MTvolumeSelling > MTvolumeBuying then Color.GREEN else Color.RED);
Like below example due to market not open yet
Last edited by a moderator: