Need Help with Daily High and Low Breakout Strategy

D

dstock

New member
Hello, I need some help to improvise the Daily high low indicator. I mainly used for scalping in 1min time-frame chart without pre-market session. I converted into TOS strategy for testing purposes but there is a problem with it. It creates the first order right away after opening candle. For example, If I set "marketOpen" time as "931" or 9:31am, It creates order at next candle or 9:32 according to the 9:31 candle. If 9:31 candle is red than it creates a short position if it's green than it creates long position. I tried to fix it by changing "marketOpen" time, let's say "940", same issue, order at 9:32 candle and 9:41 candle.

So my goal is to disable creating order at the second candle depending on "marketOpen" time OR in another word, ignore first candle and previous candle before "marketOpen" time. for instance, if my "marketOpen" time is 1000 or 10 am then ignore all candles from 9:30 am till 10 am.





Link for strategy
https://tos.mx/ltZhUKr
Link for Workspace w/ stop loss added
https://tos.mx/qbPjsdD

Code:
input marketOpen = 931;
input marketClose = 1600;
input intraDaySpan = {Default "SameDay" , "OverNight"};
input numberOfDays = 1;
input numberOfYears = 0;

def okToPlot = GetLastDay() - numberOfDays <= GetDay() and GetLastYear() - numberOfYears <= GetYear() ;

def OpenCounter =  SecondsFromTime(marketOpen);
def CloseCounter = SecondsTillTime(marketClose);

def MarketHours = if OpenCounter >= 0 and CloseCounter >= 0 then 1 else 0;

def beforeMidnight = OpenCounter >= 0 and CloseCounter <= 0;
def afterMidnight = OpenCounter <= 0 and CloseCounter >= 0 ;

def Today ;
def hideChartBubbles ;
rec DailyHigh ;
rec DailyLow ;

switch (intraDaySpan) {
    case "SameDay":
    Today = if GetDay() != GetDay()[1] then 1 else 0;
    DailyHigh = if MarketHours then if high > DailyHigh[1] then high else DailyHigh[1] else high;
    DailyLow = if Today then low else if MarketHours then if low < DailyLow[1] then low else DailyLow[1] else low;
    hideChartBubbles = MarketHours;
    case "OverNight":
    Today = 0;
    DailyHigh = if beforeMidnight or afterMidnight then if high > DailyHigh[1] then high else DailyHigh[1] else  high;
    DailyLow = if beforeMidnight or afterMidnight then if low < DailyLow[1] then low else DailyLow[1] else low;
    hideChartBubbles = beforeMidnight or afterMidnight;
};

plot TodaysHigh = if okToPlot and hideChartBubbles  then DailyHigh else Double.NaN;
plot TodaysLow = if okToPlot and hideChartBubbles then DailyLow else Double.NaN;
TodaysHigh.SetDefaultColor(Color.GREEN);
TodaysLow.SetDefaultColor(Color.RED);


Def high= DailyHigh > DailyHigh[1] ;
Alert(high,"New High", Alert.BAR, Sound.Bell);
AddOrder(OrderType.BUY_AUTO, high , tickColor = GetColor(1), arrowColor = GetColor(1), name = ".");



Def low= DailyLow < DailyLow[1] ;
Alert(low, "New Low", Alert.BAR, Sound.Bell);
AddOrder(OrderType.Sell_AUTO, low , tickColor = GetColor(1), arrowColor = GetColor(1), name = ".");
 
Last edited:

Similar threads

Top