Simple Coding Help - No Promise.

raj_singh

Well-Known Member
Please help me to draw high and low line on last 15 minute bar

i am trying following code but it is not working

H1 = TimeFrameGetPrice( "H", inMinute, -1 ); // high
L1 = TimeFrameGetPrice( "L", inMinute, -1 ); // low
 

amitrandive

Well-Known Member
Please help me to draw high and low line on last 15 minute bar

i am trying following code but it is not working

H1 = TimeFrameGetPrice( "H", inMinute, -1 ); // high
L1 = TimeFrameGetPrice( "L", inMinute, -1 ); // low

H1 = TimeFrameGetPrice( "H", in15Minute, -1 ); // high
L1 = TimeFrameGetPrice( "L", in15Minute, -1 ); // low
 
Hi,

Larry Connors has discussed about this in Street Smarts, for catching short term reversals, does anyone has this AFL or can somebody code it?:thanx:

details bellow the chart



This is how you calculate the short-term pivot point for the 2-period rate of change:
1. Subtract today's close from the close two days ago (not yesterday but the day before). Thus, close (day one) - close (day three) equals the 2-period rate of change.
2. Add this number to yesterday's closing price (day two).
3. This will be our short-term pivot number. We want to go home long if we have been on a sell signal and the price then closes above this pivot number. We will look to short if the 2-period rate of change flips from a buy to a sell and the price is going to close below the short-term pivot number.
 
Hello,
why varset is not assigning value right or Is there any issue?
when i do manually,
When there is 2 number under candle I can plot _m line
When i try to same stuff with loop, I get error m2 not initiated
and I tried to initiated with varset


VarSet( "M" + i, TimeFrameExpand( up, i*in1Minute , expandPoint ) );
// Doesn't M2 = TimeFrameExpand( up, 2*in1Minute , expandPoint );


BELOW CODE WORKING FINE
Code:
Plot( C, ""+Interval(2), styleCandle );
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
dt = DateTime();
SetBarsRequired( -2, -2 );
expandmode=expandPoint;

    TimeframeSet( in1Minute );   //  TimeframeSet(i * in1Minute);    
    up = C > O;
    M1 = TimeFrameExpand( up, in1Minute , expandPoint ); 
    TimeframeRestore();
 
    TimeframeSet( 2*in1Minute );
     up = C > O; 
    M2 = TimeFrameExpand( up, 2*in1Minute , expandPoint );
    TimeframeRestore();
     
     dist = 0.1*ATR(1);
    for( b = 0; b < BarCount; b++ )
{
//------  yellow is the Invertedhammer  with NO space
if( m1[b] ) PlotText( "1" , b, L[ b ]-1-dist[1], colorRed );  
if( m2[b] ) PlotText( "2" , b, L[ b ]-1.4-dist[1], colorRed );
if( b > 11 )
[COLOR="Red"][SIZE="2"]if (m2[b])
PlotText( "_m" , b, L[ b ]-1-dist[1], colorgold );
}[/SIZE][/COLOR]


BELOW CODE IS NOT WORKING FINE , SAME STUFF TRIED WITH LOOP
Code:
Plot( C, ""+Interval(2), styleCandle );

for( i = 1; i < 3; i++ )
{

    TimeframeSet( i*in1Minute );
    up = C > O;
    TimeframeRestore();
    
[COLOR="Red"]VarSet( "M" + i, TimeFrameExpand( up, i*in1Minute , expandPoint ) );
// Doesn't  M2  =  TimeFrameExpand( up, 2*in1Minute , expandPoint );[/COLOR]
M = VarGet( "M" + i );

   for( b = 0; b < BarCount; b++ )
    {
if(M[b] )   PlotText(" "+(i), b, L[b]-1-(i), colorRed);

if (M2[b])
{
PlotText( "" , b, y[ b ], colorRed );
}


}
}
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
 
Last edited:

KelvinHand

Well-Known Member
Hello,
why varset is not assigning value right or Is there any issue?
when i do manually,
When there is 2 number under candle I can plot _m line
When i try to same stuff with loop, I get error m2 not initiated
and I tried to initiated with varset


VarSet( "M" + i, TimeFrameExpand( up, i*in1Minute , expandPoint ) );
// Doesn't M2 = TimeFrameExpand( up, 2*in1Minute , expandPoint );


BELOW CODE WORKING FINE
Code:
Plot( C, ""+Interval(2), styleCandle );
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
dt = DateTime();
SetBarsRequired( -2, -2 );
expandmode=expandPoint;

    TimeframeSet( in1Minute );   //  TimeframeSet(i * in1Minute);    
    up = C > O;
    M1 = TimeFrameExpand( up, in1Minute , expandPoint ); 
    TimeframeRestore();
 
    TimeframeSet( 2*in1Minute );
     up = C > O; 
    M2 = TimeFrameExpand( up, 2*in1Minute , expandPoint );
    TimeframeRestore();
     
     dist = 0.1*ATR(1);
    for( b = 0; b < BarCount; b++ )
{
//------  yellow is the Invertedhammer  with NO space
if( m1[b] ) PlotText( "1" , b, L[ b ]-1-dist[1], colorRed );  
if( m2[b] ) PlotText( "2" , b, L[ b ]-1.4-dist[1], colorRed );
if( b > 11 )
[COLOR="Red"][SIZE="2"]if (m2[b])
PlotText( "_m" , b, L[ b ]-1-dist[1], colorgold );
}[/SIZE][/COLOR]


BELOW CODE IS NOT WORKING FINE , SAME STUFF TRIED WITH LOOP
Code:
Plot( C, ""+Interval(2), styleCandle );

for( i = 1; i < 3; i++ )
{

    TimeframeSet( i*in1Minute );
    up = C > O;
    TimeframeRestore();
    
[COLOR="Red"]VarSet( "M" + i, TimeFrameExpand( up, i*in1Minute , expandPoint ) );
// Doesn't  M2  =  TimeFrameExpand( up, 2*in1Minute , expandPoint );[/COLOR]
M = VarGet( "M" + i );

   for( b = 0; b < BarCount; b++ )
    {
if(M[b] )   PlotText(" "+(i), b, L[b]-1-(i), colorRed);

if (M2[b])
{
PlotText( "" , b, y[ b ], colorRed );
}


}
}
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );


See the example properly, how the VarSet generate the variable "string" in the comment.
https://www.amibroker.com/guide/afl/varset.html

Then you must VarGet the string for each variable.
don't treat it as array.

Try out the example code first, before you try to put into a big script, it may not work properly.
 
Last edited:
See the example properly, how the VarSet generate the variable "string" in the comment.
https://www.amibroker.com/guide/afl/varset.html

Then you must VarGet the string for each variable.
don't treat it as array.

Try out the example code first, before you try to put into a big script, it may not work properly.
Hello Kelvinhand,
as example
Code:
for( i = 1; i < 10; i++ ) 
{ 
[B]VarSet( "C"+i, Ref( C, -i ) ); 

Plot( VarGet( "C"+i ), "C"+i, colorRed ); 
//Plot( VarGet( "C"+i ), " ", colorRed ); //works same way
}[/B]
Code:
Plot( C, ""+Interval(2), styleCandle );

for( i = 1; i < 3; i++ )
{

    TimeframeSet( i*in1Minute );
    up = C > O;
    TimeframeRestore();
    
VarSet( "M" + i, TimeFrameExpand( up, i*in1Minute , expandPoint ) );
// [SIZE="3"][B]same way as example it generate M2  =  TimeFrameExpand( up, 2*in1Minute , expandPoint );[/B][/SIZE]
// Doesn't  M2  =  TimeFrameExpand( up, 2*in1Minute , expandPoint );

//[COLOR="RoyalBlue"][SIZE="3"]Then you must VarGet the string for each variable.[/SIZE][/COLOR]
// [B]I've written [COLOR="royalblue"]VarGet( "M" + i );[/COLOR]  [/B]  as below

M = VarGet( "M" + i );

   for( b = 0; b < BarCount; b++ )
    { 
if(M[b] )   PlotText(" "+(i), b, L[b]-1-(i), colorRed);

if (M2[b])
//[COLOR="royalblue"][SIZE="3"]M2[b] is an element of every candle array [/SIZE][/COLOR]  
// should i write Varget("M"+2); ? 
{
PlotText( "" , b, y[ b ], colorRed );
}


}
}
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Isn't M2 = TimeFrameExpand( up, 2*in1Minute , expandPoint ); ?
we've used VarSet( "M" + i, TimeFrameExpand( up, i*in1Minute , expandPoint ) );

VarGet( "M" + i );
This Varget string of each variable, right?

Why is it giving error for M2 ?

regards
 
Last edited:

KelvinHand

Well-Known Member
Hello Kelvinhand,
as example
Code:
for( i = 1; i < 10; i++ ) 
{ 
[B]VarSet( "C"+i, Ref( C, -i ) ); 

Plot( VarGet( "C"+i ), "C"+i, colorRed ); 
//Plot( VarGet( "C"+i ), " ", colorRed ); //works same way
}[/B]
Code:
Plot( C, ""+Interval(2), styleCandle );

for( i = 1; i < 3; i++ )
{

    TimeframeSet( i*in1Minute );
    up = C > O;
    TimeframeRestore();
    
VarSet( "M" + i, TimeFrameExpand( up, i*in1Minute , expandPoint ) );
// [SIZE="3"][B]same way as example it generate M2  =  TimeFrameExpand( up, 2*in1Minute , expandPoint );[/B][/SIZE]
// Doesn't  M2  =  TimeFrameExpand( up, 2*in1Minute , expandPoint );

//[COLOR="RoyalBlue"][SIZE="3"]Then you must VarGet the string for each variable.[/SIZE][/COLOR]
// [B]I've written [COLOR="royalblue"]VarGet( "M" + i );[/COLOR]  [/B]  as below

M = VarGet( "M" + i );

   for( b = 0; b < BarCount; b++ )
    { 
if(M[b] )   PlotText(" "+(i), b, L[b]-1-(i), colorRed);

if (M2[b])
//[COLOR="royalblue"][SIZE="3"]M2[b] is an element of every candle array [/SIZE][/COLOR]  
// should i write Varget("M"+2); ? 
{
PlotText( "" , b, y[ b ], colorRed );
}


}
}
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
Isn't M2 = TimeFrameExpand( up, 2*in1Minute , expandPoint ); ?
we've used VarSet( "M" + i, TimeFrameExpand( up, i*in1Minute , expandPoint ) );

VarGet( "M" + i );
This Varget string of each variable, right?

Why is it giving error for M2 ?

regards
your variables produced by VarSet() are "M1", "M2", "M3"

Is M2 same as "M2" ?

When you do VarGet()

M = VarGet("M1") when i=1
M = VarGet("M2") when i=2
M = VarGet("M3") when i=3
So what is your M2 ?

So the amibroker tell you, I donn't understand M2, because is not initialise
 

Similar threads