Advanced for loop in multi time frame loop

I have Master candle condition in 5 minute intraday chart, once it comes true...I want to iterate through next five bars in one minute time frame and check if any of this 5 bars has its close above High of master candle....and High of the same 1 minute bar will be my buy price...I tried the following loop but the buy price not plotting correctly...Please guide in this ragard..I am using 5 minute time frame chart

//setup1buylevel=ValueWhen(Master_buy,Ref(H,-1));

masterbuycontinue = Flip(Master_buy,NewDay);
setup1buyprice=0;
setup1buylevel=0;
setup1buyarray=Null;
setup1buy=False;
close1min = TimeFrameExpand(Close, in1Minute);
setup1b=false;

 //Check if condition is true
for (i = 1; i < BarCount; i++)
{
	
	   
    if(masterbuycontinue[i] AND setup1buylevel==0)
	{
	setup1buylevel = H[i-1];
	
	}
	
	if(setup1buylevel>0)
    {
    
    setup1buyarray = setup1buylevel;
    }
    
    if(NewDay[i])
    {
    
    setup1buylevel = 0;
    
				}
    
   
				TimeFrameSet(in1Minute);
				
				for (j = i; i <=5; j++)
				{
				if(Close[j]>setup1buylevel)
				
				Setup1buy=True;
				
				setup1buyprice=High[i];
				
				
				TimeFrameRestore();
				break;
				}
	      
}

            
Plot(IIf(masterbuycontinue,setup1buyarray,Null),"setup1",colorWhite,styleLine);

Plot(IIf(masterbuycontinue,TimeFrameExpand(setup1buyprice,in1Minute),Null),"setup1",colorGreen,styleLine);

hi, for this scenario you need to have your chart in the 1Minute Timeframe. Then you calculate your signal in the 5Minute timeframe and expand them into the the 1Minute

below and example. Others may check this. I use expand first. I have default intraday settings. I think it is correct

// your base timeframe is SMALL_TF
SMALL_TF = in1Minute;
BIG_TF = in5Minute;

SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 1 );

if( Interval() == SMALL_TF )
{
    // define your signal in the BIG_TF
    TimeFrameSet( BIG_TF );
    ema20 = EMA( C, 20 );
    buysignal = Cross( C, ema20 );
    hh = IIf( buysignal, H, Null );
    ll = IIf( buysignal, L, Null );
    TimeFrameRestore();

    // expand BIG_TF to SMALL_TF
    exp1 = expandFirst;
    ema20 = TimeFrameExpand( ema20, BIG_TF, exp1 );
    buysignal = TimeFrameExpand( buysignal, BIG_TF, exp1 );
    hh = TimeFrameExpand( hh, BIG_TF, exp1 );
    ll = TimeFrameExpand( ll, BIG_TF, exp1 );

    buytriggerlevel = ValueWhen( hh, hh );
    Buy = Cross( C, buytriggerlevel ) AND BarsSince( buysignal ) <= 5;
    Buy = ExRem( Buy, buysignal );
    BuyPrice = C;

    PlotShapes( IIf( buysignal, shapeSmallCircle, shapeNone ), colorYellow, 0, L, -10 );
    Plot( buytriggerlevel, "", colorGreen, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
    Plot( hh, "", colorGreen, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
    Plot( ema20, "", colorAqua, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
    PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, 0, L, -10 );
    PlotShapes( IIf( Buy, shapeSmallCircle, shapeNone ), colorWhite, 0, BuyPrice, 0 );
    PlotOHLC( hh, hh, ll, ll, "", ColorRGB( 50, 50, 50 ), styleCloud | styleNoLabel, Null, Null, 0, -1, 1 );
}

so here are the intraday settings I use:

1 Like

signals look like this:

1 Like

1 more update. The width of the entry area depends on:

SafeDivide( Big_TF, SMALL_TF )

so in case you set the BIG_TF to in15Minute and the SMALL_TF to in1Minute then the entry zone will be 15 bars

// your base timeframe is SMALL_TF
SMALL_TF = in1Minute;
BIG_TF = in5Minute;

SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 1 );

if( Interval() == SMALL_TF )
{
    // define your signal in the BIG_TF
    TimeFrameSet( BIG_TF );
    ema20 = EMA( C, 20 );
    buysignal = Cross( C, ema20 );
    hh = IIf( buysignal, H, Null );
    ll = IIf( buysignal, L, Null );
    TimeFrameRestore();

    // expand BIG_TF to SMALL_TF
    exp1 = expandFirst;
    ema20 = TimeFrameExpand( ema20, BIG_TF, exp1 );
    buysignal = TimeFrameExpand( buysignal, BIG_TF, exp1 );
    hh = TimeFrameExpand( hh, BIG_TF, exp1 );
    ll = TimeFrameExpand( ll, BIG_TF, exp1 );

    buytriggerlevel = ValueWhen( hh, hh );
    Buy = Cross( C, buytriggerlevel ) AND BarsSince( buysignal ) <= SafeDivide( Big_TF, SMALL_TF );// AND BarsSince( buysignal ) > 0;
    Buy = ExRem( Buy, buysignal );
    BuyPrice = C;

    PlotShapes( IIf( buysignal, shapeSmallCircle, shapeNone ), colorYellow, 0, L, -10 );
    Plot( buytriggerlevel, "", colorGreen, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
    Plot( hh, "", colorGreen, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
    Plot( ema20, "", colorAqua, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
    PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, 0, L, -10 );
    PlotShapes( IIf( Buy, shapeSmallCircle, shapeNone ), colorWhite, 0, BuyPrice, 0 );
    PlotOHLC( hh, hh, ll, ll, "", ColorRGB( 50, 50, 50 ), styleCloud | styleNoLabel, Null, Null, 0, -1, 1 ); // setup/trigger zone
    PlotOHLC( hh, hh, ll, ll, "", ColorRGB( 50, 0, 50 ), styleCloud | styleNoLabel, Null, Null, SafeDivide( Big_TF, SMALL_TF ), -1, 1 ); // entry zone
}

hope it will help you .

Sir, I am using 5 time chart timeframe, where in I have a condtion candle called "Master candle".... Once my master candle condition comes true...I want to break next 5 minute bar into 5 bars of 1 minute each and check if any of this 1 minute bar has its close above High of my Master candle(which is in 5 minute time frame). If any of the bar 1 minute minute has its close above the high of 5 minute master candle My buy condition will come true and high of the same 1 minute bar will be my buyprice....I tried achiving this using the above advanced for loop. but the results are not expected:


you do not understand. You can not get 1-minute signals in a 5Min chart. To get 1-minute signals you need a 1-minute chart (or a lower timeframe). So to do what you want to do is in my code. You create your "Master Candle" condition using the timeframe functions. Below the code. Same code as above but I made it "automatic". If you put that in a 1-minute chart your will get what you planned to do. If you put the code in a 5-minute chart you will also get a result but now the "Master Candle" is 25Minutes broad (5x5Min). I also added 2 parameters where you can change the BIG Timeframe and change the entry zone. But the default code does what you want. But you need a 1-minute data chart

// your base timeframe is SMALL_TF
small_tf_fact = Param( "Small TF factor", 5, 1, 240, 1 ); // this determines the BIG Timeframe
entry_zone_fact = Param( "Entry Zone factor", 1, 1, 10, 1 );

SMALL_TF = Interval();
BIG_TF = SMALL_TF * small_tf_fact;

SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 1 );

// define your signal in the BIG_TF
TimeFrameSet( BIG_TF );
ema20 = EMA( C, 20 );
buysignal = Cross( C, ema20 );
hh = IIf( buysignal, H, Null );
ll = IIf( buysignal, L, Null );
TimeFrameRestore();

// expand BIG_TF to SMALL_TF
exp1 = expandFirst;
ema20 = TimeFrameExpand( ema20, BIG_TF, exp1 );
buysignal = TimeFrameExpand( buysignal, BIG_TF, exp1 );
hh = TimeFrameExpand( hh, BIG_TF, exp1 );
ll = TimeFrameExpand( ll, BIG_TF, exp1 );

buytriggerlevel = ValueWhen( hh, hh );
Buy = Cross( C, buytriggerlevel ) AND BarsSince( buysignal ) <= small_tf_fact * entry_zone_fact;// AND BarsSince( buysignal ) > 0;
Buy = ExRem( Buy, buysignal );
BuyPrice = C;

///PlotShapes( IIf( buysignal, shapeSmallCircle, shapeNone ), colorYellow, 0, L, -10 );
Plot( buytriggerlevel, "", colorGreen, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
Plot( hh, "", colorGreen, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
Plot( ema20, "", colorAqua, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, 0, L, -10 );
PlotShapes( IIf( Buy, shapeSmallCircle, shapeNone ), colorWhite, 0, BuyPrice, 0 );

GfxSetZOrder( -5 );
GfxSetCoordsMode( 1 );
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

function drawZone( x0, y0, x1, y1, clr0, clr1, thk, rnd )
{
    GfxSelectPen( clr0, thk, 0 );
    GfxSelectSolidBrush( clr1 );
    GfxRoundRect( x0, y0, x1, y1, rnd, rnd );
}

h1 = BarsSince( IsEmpty( hh ) );

for( i = lvb; i > fvb; i-- )
{
    if( !IsEmpty( hh[i] ) )
    {
        x0 = bi[i];
        y0 = hh[i];
        x1 = x0 - h1[i] + 1;
        y1 = ll[i];
        drawZone( x0, y0, x1, y1, ColorRGB( 0, 250, 0 ), ColorRGB( 0, 30, 0 ), 1, 10 );
        drawZone( x0 + 1, y0, x0 + ( small_tf_fact * entry_zone_fact ), y1, ColorRGB( 250, 0, 250 ), ColorRGB( 30, 0, 30 ), 1, 10 );
        i = i - h1[i];
    }
}

Title = 
EncodeColor( colorAqua )
+ "SMALL TF: " + ( SMALL_TF / 60 ) + " Min"
+ " | " + "BIG TF: " + ( BIG_TF / 60 ) + " Min";

2 Likes

Sir, I am using 5 minute exploration for scanning my signals...does the 1 minute close will give me my desired signal in 5 minute eploration?

you will need to do you exploration also in the 1 Minute timeframe. That is the only way to determine a signal in the 1-minute timeframe. In the 5-minute timeframe you can not see 1-minute signals

Yes sir...thank you very much!

Sir, My current code is running in 5 minutes exploration. Can i integrate above code for 1 minute and run exploration in multiple time frame??

I guess it is possible. Your database timeframe should be 1-minute or lower. You would have to adjust the code a bit I would think. Which explorations do you want to run simultaneously?

  1. 5Min master bars with 1Min signals
  2. 15Min master bar with 5Min signals

i never tested it myself. Let me know what signals you want and I can play around with it a bit.

Below some updated code. Also have a look at the chart below. I now show the "master bar" as a candle. So this chart is in the 1Min timeframe and has a 5Min "master bar" with 1Min signals. Just so we are talking about the same thing :smiley: This is what you are talking about, right?

// your base timeframe is SMALL_TF
small_tf_fact = Param( "Small TF factor", 5, 1, 240, 1 ); // this determines the BIG Timeframe
entry_zone_fact = Param( "Entry Zone factor", 1, 1, 10, 1 );
showlong = ParamToggle( "Show Long Signals", "No|Yes", 1 );
showshort = ParamToggle( "Show Short Signals", "No|Yes", 0 );

SMALL_TF = Interval();
BIG_TF = SMALL_TF * small_tf_fact;

SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 1 );

// define your signal in the BIG_TF
TimeFrameSet( BIG_TF );
ema20 = EMA( C, 20 );
buysignal = Cross( C, ema20 );
shortsignal = Cross( ema20, C );
bhh = IIf( buysignal, H, Null );
bll = IIf( buysignal, L, Null );
boo = IIf( buysignal, O, Null );
bcc = IIf( buysignal, C, Null );
sll = IIf( shortsignal, L, Null );
shh = IIf( shortsignal, H, Null );
soo = IIf( shortsignal, O, Null );
scc = IIf( shortsignal, C, Null );
TimeFrameRestore();

// expand BIG_TF to SMALL_TF
exp1 = expandFirst;
ema20 = TimeFrameExpand( ema20, BIG_TF, exp1 );
buysignal = TimeFrameExpand( buysignal, BIG_TF, exp1 );
shortsignal = TimeFrameExpand( shortsignal, BIG_TF, exp1 );
bhh = TimeFrameExpand( bhh, BIG_TF, exp1 );
bll = TimeFrameExpand( bll, BIG_TF, exp1 );
boo = TimeFrameExpand( boo, BIG_TF, exp1 );
bcc = TimeFrameExpand( bcc, BIG_TF, exp1 );
shh = TimeFrameExpand( shh, BIG_TF, exp1 );
sll = TimeFrameExpand( sll, BIG_TF, exp1 );
soo = TimeFrameExpand( soo, BIG_TF, exp1 );
scc = TimeFrameExpand( scc, BIG_TF, exp1 );

buytriggerlevel = ValueWhen( bhh, bhh );
Buy = Cross( C, buytriggerlevel ) AND BarsSince( buysignal ) <= small_tf_fact * entry_zone_fact;// AND BarsSince( buysignal ) > 0;
Buy = ExRem( Buy, buysignal );
BuyPrice = C;

shorttriggerlevel = ValueWhen( sll, sll );
Short = Cross( shorttriggerlevel, C ) AND BarsSince( shortsignal ) <= small_tf_fact * entry_zone_fact;// AND BarsSince( buysignal ) > 0;
Short = ExRem( Short, shortsignal );
ShortPrice = C;

Plot( ema20, "", colorAqua, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );

GfxSetZOrder( -5 );
GfxSetCoordsMode( 1 );
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

function drawTriggerCandle( x0, y0, x1, y1, y2, y3, clr0, clr1, thk, rnd )
{
	// master candle
    GfxSelectPen( clr0, thk, 0 );
    GfxSelectSolidBrush( clr1 );
	GfxRoundRect( x0, y2, x1, y3, rnd, rnd );
	GfxMoveTo( (x0+x1)/2, y3 );
	GfxLineTo( (x0+x1)/2, y0 );
	GfxMoveTo( (x0+x1)/2, y2 );
	GfxLineTo( (x0+x1)/2, y1 );	
	
	// entry zone
	GfxMoveTo( x0, y0 );
	GfxLineTo( x0 + ( small_tf_fact * entry_zone_fact ), y0 );
}

if( showlong )
{
    PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, 0, L, -10 );
    PlotShapes( IIf( Buy, shapeSmallSquare, shapeNone ), colorWhite, 0, BuyPrice, 0 );
    Plot( buytriggerlevel, "", colorGreen, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );

    h1 = BarsSince( IsEmpty( bhh ) );

    for( i = lvb; i > fvb; i-- )
    {
        if( !IsEmpty( bhh[i] ) )
        {
            x0 = bi[i];
            y0 = bhh[i];
            x1 = x0 - h1[i] + 1;
            y1 = bll[i];
            y2 = boo[i];
            y3 = bcc[i];
            drawTriggerCandle( x0, y0, x1, y1, y2, y3, ColorRGB( 0, 250, 0 ), ColorRGB( 0, 60, 0 ), 6, 0 );
            i = i - h1[i];
        }
    }
}

if( showshort )
{
    PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorRed, 0, H, -10 );
    PlotShapes( IIf( Short, shapeSmallSquare, shapeNone ), colorWhite, 0, ShortPrice, 0 );
    Plot( shorttriggerlevel, "", colorRed, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );

    l1 = BarsSince( IsEmpty( sll ) );

    for( i = lvb; i > fvb; i-- )
    {
        if( !IsEmpty( sll[i] ) )
        {
            x0 = bi[i];
            y0 = sll[i];
            x1 = x0 - l1[i] + 1;
            y1 = shh[i];
            y2 = soo[i];
            y3 = scc[i];
            drawTriggerCandle( x0, y0, x1, y1, y2, y3, ColorRGB( 250, 0, 0 ), ColorRGB( 60, 0, 0 ), 6, 0 );
            i = i - l1[i];
        }
    }
}

Title =
    EncodeColor( colorAqua )
    + "SMALL TF: " + ( SMALL_TF / 60 ) + " Min"
    + " | " + "BIG TF: " + ( BIG_TF / 60 ) + " Min";

if( Status( "action" ) == actionExplore )
{
    wdth = 50;
    Filter = Buy OR Short;
    AddColumn( Buy, "Buy", 1.2, colorBlack, IIf( Buy, colorGreen, colorWhite ), wdth );
    AddColumn( Short, "Short", 1.2, colorBlack, IIf( Short, colorRed, colorWhite ), wdth );
}

2 Likes

short answer is yes, this is possible, see:

One of the most generous and helpful coder....Just he needs interesting logic :slight_smile:

2 Likes

Thank you very much sir...I already started working on it... :+1:

1 Like

Thanks Nick for this nice logic.
Just I have a doubt ,if I backtest in 5min interval then which chart should be followed whether 5min or 1 min for trading.
@nick result will be good if master candle based on inside bar concept.

@Kislay98761

Only users with "Verified Badge" are allowed to post on this forum.

Search "Verified Badge" for more information on how to get verified.

same as with resolution on TV. If the smallest timeframe of your data is 5Min, then your signals can only be in the 5Min timeframe, not lower. You can not get 1Min signals in the 5Min timeframe. At least not if you use the close price of a bar as an entry point. Of course you can enter a trade any time you want but with 5Min data it is impossible to say what the price exactly has been withing that 5min bar. Except for the Open and Close of that bar. So with 5Min data you can not have 1Min signals. 5Min signals is the finest grain for 5Min data.

So for the code I posted using 1 Minute data you can make your "Master Candle" as big as you want from 1 bar to higher using the "Small TF Factor" in the param window. default the master candle is set to 5Min when your data is 1Min TF

1 Like

with respect to multi timeframe exploration. As shown in the example this is possible. I did and test and it works fine. But for my code it is a bit complicated. Because with 1Minute data the setting in the analysis window will be 1Minute. So when doing the explore using:
SMALL_TF = in1Minute;
BIG_TF = in5Minute;

works fine. But then when the settings are
SMALL_TF = in5Minute;
BIG_TF = in15Minute;

it becomes more complicated because the exploration setting is in 1Minute TF. So I will leave that to others to solve.

1 addition I made to the code is to make sure that the "Master Candle" always has ALL the (small_tf_fact) number of bars. Because sometimes data points are missing when the market is thin. With 1Min data you sometimes only have 2 or 3 bars in a 5Min period. So these signals are ignored. Or ignored by default. You can also chose to show them.

// your base timeframe is SMALL_TF
small_tf_fact = Param( "Small TF factor", 5, 1, 240, 1 ); // this determines the BIG Timeframe
entry_zone_fact = Param( "Entry Zone factor", 1, 1, 10, 1 );
showlong = ParamToggle( "Show Long Signals", "No|Yes", 1 );
showshort = ParamToggle( "Show Short Signals", "No|Yes", 0 );
showBIG_TF = ParamToggle( "Show BIG Timeframe", "No|Yes", 0 );
ensurewidth = ParamToggle( "Make sure BIG timeframe contains small_tf_fact bars", "No|Yes", 1 ); // make sure BIG_TF contains all bars

bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

SMALL_TF = Interval();
BIG_TF = SMALL_TF * small_tf_fact;

SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 1 );

// define your signal in the BIG_TF
TimeFrameSet( BIG_TF );
ema20 = EMA( C, 20 );
buysignal = Cross( C, ema20 );
shortsignal = Cross( ema20, C );
bhh = IIf( buysignal, H, Null );
bll = IIf( buysignal, L, Null );
boo = IIf( buysignal, O, Null );
bcc = IIf( buysignal, C, Null );
sll = IIf( shortsignal, L, Null );
shh = IIf( shortsignal, H, Null );
soo = IIf( shortsignal, O, Null );
scc = IIf( shortsignal, C, Null );
TimeFrameRestore();

// expand BIG_TF to SMALL_TF
exp1 = expandFirst;
ema20 = TimeFrameExpand( ema20, BIG_TF, exp1 );
buysignal = TimeFrameExpand( buysignal, BIG_TF, exp1 );
shortsignal = TimeFrameExpand( shortsignal, BIG_TF, exp1 );
bhh = TimeFrameExpand( bhh, BIG_TF, exp1 );
bll = TimeFrameExpand( bll, BIG_TF, exp1 );
boo = TimeFrameExpand( boo, BIG_TF, exp1 );
bcc = TimeFrameExpand( bcc, BIG_TF, exp1 );
shh = TimeFrameExpand( shh, BIG_TF, exp1 );
sll = TimeFrameExpand( sll, BIG_TF, exp1 );
soo = TimeFrameExpand( soo, BIG_TF, exp1 );
scc = TimeFrameExpand( scc, BIG_TF, exp1 );
pnt = TimeFrameExpand( 1, BIG_TF, expandPoint );

lastbarOfMasterCandlePeriod = pnt;
firstbarOfMasterCandlePeriod = Ref( pnt, -1 );
//BIG_TF_BARS = ( ValueWhen( lastbarOfMasterCandlePeriod, bi ) - ValueWhen( firstbarOfMasterCandlePeriod, bi ) ) + 1;

if( ensurewidth )
{
    buysignal = SumSince( firstbarOfMasterCandlePeriod, buysignal, True ) == small_tf_fact;
    shortsignal = SumSince( firstbarOfMasterCandlePeriod, shortsignal, True ) == small_tf_fact;
}

buytriggerlevel = ValueWhen( bhh, bhh );
Buy = Cross( C, buytriggerlevel ) AND BarsSince( buysignal ) <= small_tf_fact * entry_zone_fact;// AND BarsSince( buysignal ) > 0;
Buy = ExRem( Buy, buysignal );
BuyPrice = C;

shorttriggerlevel = ValueWhen( sll, sll );
Short = Cross( shorttriggerlevel, C ) AND BarsSince( shortsignal ) <= small_tf_fact * entry_zone_fact;// AND BarsSince( buysignal ) > 0;
Short = ExRem( Short, shortsignal );
ShortPrice = C;

Plot( ema20, "", colorAqua, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );

GfxSetZOrder( -5 );
GfxSetCoordsMode( 1 );
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

function drawTriggerCandle( x0, y0, x1, y1, y2, y3, clr0, clr1, thk, rnd )
{
    // master candle
    GfxSelectPen( clr0, thk, 0 );
    GfxSelectSolidBrush( clr1 );
    GfxRoundRect( x0, y2, x1, y3, rnd, rnd );
    GfxMoveTo( ( x0 + x1 ) / 2, y3 );
    GfxLineTo( ( x0 + x1 ) / 2, y0 );
    GfxMoveTo( ( x0 + x1 ) / 2, y2 );
    GfxLineTo( ( x0 + x1 ) / 2, y1 );

    // entry zone
    GfxMoveTo( x0, y0 );
    GfxLineTo( x0 + ( small_tf_fact * entry_zone_fact ), y0 );
}

if( showlong )
{
    PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, 0, L, -10 );
    PlotShapes( IIf( Buy, shapeSmallSquare, shapeNone ), colorWhite, 0, BuyPrice, 0 );
    Plot( buytriggerlevel, "", colorGreen, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );

    h1 = BarsSince( IsEmpty( bhh ) );

    for( i = lvb; i > fvb; i-- )
    {
        if( buysignal[i] == 1 )
        {
            x0 = bi[i];
            y0 = bhh[i];
            x1 = x0 - h1[i] + 1;
            y1 = bll[i];
            y2 = boo[i];
            y3 = bcc[i];
            drawTriggerCandle( x0, y0, x1, y1, y2, y3, ColorRGB( 0, 250, 0 ), ColorRGB( 0, 60, 0 ), 6, 0 );
            i = i - h1[i];
        }
    }
}

if( showshort )
{
    PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorRed, 0, H, -10 );
    PlotShapes( IIf( Short, shapeSmallSquare, shapeNone ), colorWhite, 0, ShortPrice, 0 );
    Plot( shorttriggerlevel, "", colorRed, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );

    l1 = BarsSince( IsEmpty( sll ) );

    for( i = lvb; i > fvb; i-- )
    {
        if( shortsignal[i] == 1 )
        {
            x0 = bi[i];
            y0 = sll[i];
            x1 = x0 - l1[i] + 1;
            y1 = shh[i];
            y2 = soo[i];
            y3 = scc[i];
            drawTriggerCandle( x0, y0, x1, y1, y2, y3, ColorRGB( 250, 0, 0 ), ColorRGB( 60, 0, 0 ), 6, 0 );
            i = i - l1[i];
        }
    }
}

if( showBIG_TF )
{
    Plot( lastbarOfMasterCandlePeriod, "", colorYellow, styleHistogram | styleOwnScale | styleNoLabel, 0, 1, 0, -1, 1 );
    Plot( firstbarOfMasterCandlePeriod, "", colorAqua, styleHistogram | styleOwnScale | styleNoLabel, 0, 1, 0, -1, 1 );
}

Title =
    EncodeColor( colorAqua )
    + "SMALL TF: " + ( SMALL_TF / 60 ) + " Min"
    + " | " + "BIG TF: " + ( BIG_TF / 60 ) + " Min";

if( Status( "action" ) == actionExplore )
{
    wdth = 150;
    Filter = Buy OR Short;
    AddColumn( Buy, "Buy", 1.2, colorBlack, IIf( Buy, colorGreen, colorWhite ), wdth );
    AddColumn( Short, "Short", 1.2, colorBlack, IIf( Short, colorRed, colorWhite ), wdth );
}
2 Likes