Simple Coding Help - No Promise.

pratapvb

Well-Known Member
Hi

This is modified version of Super Trend indicator.

I have used combination of 5 min and 10 min Time frame in code, 10 min coding value is correct, same is verified in bottom color ribbon, but when used on chart, as we scroll/shift chart signal is moving.... signals are not repainting, just when we scroll signals are moving. :(

...
...

Please help me to fix signal when chart is scrolled or moved
I did not find any change in signal while scrolling

btw what is the modification to super trend in this?

P.S. Happy already replied....I was using 15min chart
 
I did not find any change in signal while scrolling

P.S. Happy already replied....I was using 15min chart
Hello Pratap

The solution to the problem is very simple, she has reused the same variables on 2 loops for two different TFs :)

Just trying to show how to go about debugging these issues . . . .


btw what is the modification to super trend in this?
I guess the modification is using HA candles instead of normal candles to get the ST value . . .

I was using 15min chart

The signals will be stable on 10 Minutes and above charts



Happy :)
 
Last edited:
Hello Nehal

Try this . . . if you didn't get it on your own first . . . :)


Code:
 _SECTION_BEGIN("SuperTrend Modi");
SetChartOptions(0, chartShowDates | chartWrapTitle);
Plot( C, "Close", colorRose, styleCandle | styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
kk = Optimize( "mult", Param( "mult", 2, 1, 6, 0.25 ), 1, 2, 0.25 );
Per = Optimize( "period", Param( "period", 10, 5, 50, 1 ), 5, 50, 1 );
sdfact = 2;//Param( "Standard Deviation Factor", 2, 0.5, 5, 0.1 );
offset = 2;//Param( "Offset", 2, 1, 50, 1 );
tc = ParamList( "Channel Display", List = "No Channel|Channel|ChannelRT|Both
Channels", 1 );
ms = ParamToggle( "Trend", "Regular|Smoothed", 1 );

//x = Cum( 1 );
HaClose = ( O + H + L + C ) / 4;
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );

if ( ms == 0 )
{
nm = ( H - L );
j = ( O + H + L + C ) / 4;
}
else
{
nm = ( HaHigh - HaLow );
j = ( HaOpen + HaHigh + HaLow + HaClose ) / 4;
}

rfsctor = WMA( nm, Per );

revers = kk * rfsctor;
Trend = 1;
NW[0] = 0;

for ( i = 1;i < BarCount;i++ )
{
if ( Trend[i-1] == 1 )
{
if ( j[i] < NW[i-1] )
{
Trend[i] = -1;
NW[i] = j[i] + Revers[i];
}
else
{
Trend[i] = 1;

if ( ( j[i] - Revers[i] ) > NW[i-1] )
{
NW[i] = j[i] - Revers[i];
}
else
{
NW[i] = NW[i-1];
}
}
}

if ( Trend[i-1] == -1 )
{
if ( j[i] > NW[i-1] )
{
Trend[i] = 1;
NW[i] = j[i] - Revers[i];
}
else
{
Trend[i] = -1;

if ( ( j[i] + Revers[i] ) < NW[i-1] )
{
NW[i] = j[i] + Revers[i];
}
else
{
NW[i] = NW[i-1];
}
}
}
}

cp = ( H + L ) / 2;

Plot( IIf( NW < j, NW, Null ), "", ParamColor( "ColorTrailLong", colorYellow ), styleLine | styleDashed );
Plot( IIf( NW > j, NW, Null ), "", ParamColor( "ColorTrailShort", colorYellow ), styleLine | styleDashed );

//Plot(J,"J",colorWhite, styleDashed);
_SECTION_END();

_SECTION_BEGIN("SuperTrend Modi 10min");
tf=10;
tfrm=in1Minute*tf;
TimeFrameSet(tfrm);

kk = Optimize( "mult", Param( "mult", 2, 1, 6, 0.25 ), 1, 2, 0.25 );
Per = Optimize( "period", Param( "period", 10, 5, 50, 1 ), 5, 50, 1 );
sdfact = 2;
offset = 2;
tc = ParamList( "Channel Display", List = "No Channel|Channel|ChannelRT|Both
Channels", 1 );
ms = ParamToggle( "Trend", "Regular|Smoothed", 1 );

//x = Cum( 1 );
HaClose1 = ( O + H + L + C ) / 4;
HaOpen1 = AMA( Ref( HaClose1, -1 ), 0.5 );
HaHigh1 = Max( H, Max( HaClose1, HaOpen1 ) );
HaLow1 = Min( L, Min( HaClose1, HaOpen1 ) );

if ( ms == 0 )
{
nm = ( H - L );
J1 = ( O + H + L + C ) / 4;
}
else
{
nm = ( HaHigh1 - HaLow1 );
J1 = ( HaOpen1 + HaHigh1 + HaLow1 + HaClose1 ) / 4;
}

rfsctor = WMA( nm, Per );

revers = kk * rfsctor;
Trend = 1;
NW1[0] = 0;

for ( i = 1;i < BarCount;i++ )
{
if ( Trend[i-1] == 1 )
{
if ( J1[i] < NW1[i-1] )
{
Trend[i] = -1;
NW1[i] = J1[i] + Revers[i];
}
else
{
Trend[i] = 1;

if ( ( J1[i] - Revers[i] ) > NW1[i-1] )
{
NW1[i] = J1[i] - Revers[i];
}
else
{
NW1[i] = NW1[i-1];
}
}
}

if ( Trend[i-1] == -1 )
{
if ( J1[i] > NW1[i-1] )
{
Trend[i] = 1;
NW1[i] = J1[i] - Revers[i];
}
else
{
Trend[i] = -1;

if ( ( J1[i] + Revers[i] ) < NW1[i-1] )
{
NW1[i] = J1[i] + Revers[i];
}
else
{
NW1[i] = NW1[i-1];
}
}
}
}

cp = ( H + L ) / 2;

TimeFrameRestore();


Nw2f = TimeFrameExpand( NW1, tfrm);
J2f = TimeFrameExpand( J1, tfrm);


mycNjt=IIf(NW2f < j2f,colorBlue,
     IIf(NW2f > j2f,colorRed,31));

Plot(5, "ribbon", mycNjt, styleOwnScale| styleArea|styleNoLabel,-0.5,100);
 
_SECTION_END();


_SECTION_BEGIN("Dancing_Signals");
Buy = NW<J AND NW2f<j2f;
Sell = NW>J;
Short = NW>j AND NW2f>j2f;
Cover = NW<j;

//Plot(NW,"\nNW",colorRed);
//Plot(J,"J",colorBlue);

Buy=ExRem(Buy,Sell);
Short=ExRem(Short,Cover);
Sell=ExRem(Sell,Buy);
Cover=ExRem(Cover,Short);

PlotShapes(Buy*shapeUpArrow,colorBlue,0,L,-33);
PlotShapes(Sell*shapeHollowDownArrow,colorRed,0,L,-33);
PlotShapes(Short*shapeDownArrow,colorRed,0,H,-33);
PlotShapes(Cover*shapeHollowUpArrow,colorBlue,0,L,-33);

_SECTION_END();

_SECTION_BEGIN("PriceCandle");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorPink ), styleNoTitle | styleCandle|styleNoLabel ); 
_SECTION_END();

Happy :)
 

Nehal_s143

Well-Known Member
I did not find any change in signal while scrolling

btw what is the modification to super trend in this?

P.S. Happy already replied....I was using 15min chart
Sir yellow line look likes super trend hence I gave name super trend modified, problem was if used on 5 min, Happy sir had given perfect solution :) :clapping:
 
Please solve this doubt in afl creation?


In below said code i need the following codes to added in the afl

There should be an exit signal for every entry of buy or sell signal comes to an end.

Means

The moment BUY signals stops, i need exit signal
The moment SELL signals stops, i need exit signal


Should be able to backtest the afl code.

Code:
_SECTION_BEGIN("Price1");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

sp = Param( "RSI Period", 7, 1, 100 );
r = RSI( sp );
Buy = r > 70;
Sell = r < 30;

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes(shape, IIf( Buy, colorBrightGreen, colorRed ), 0, IIf( Buy, Low, High ) );

if( ParamToggle("Tooltip shows", "All Values | Only Prices" ) )
{
 ToolTip=StrFormat("Open: %g\nHigh:  %g\nLow:   %g\nClose:  %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}
_SECTION_END();
Need the changes as shown in the image


http://postimg.org/image/3z63dpfs3/


Thanks

Sudha
 

pratapvb

Well-Known Member
Please solve this doubt in afl creation?


In below said code i need the following codes to added in the afl

There should be an exit signal for every entry of buy or sell signal comes to an end.

Means

The moment BUY signals stops, i need exit signal
The moment SELL signals stops, i need exit signal


Should be able to backtest the afl code.

Code:
_SECTION_BEGIN("Price1");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();

sp = Param( "RSI Period", 7, 1, 100 );
r = RSI( sp );
Buy = r > 70;
Sell = r < 30;

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes(shape, IIf( Buy, colorBrightGreen, colorRed ), 0, IIf( Buy, Low, High ) );

if( ParamToggle("Tooltip shows", "All Values | Only Prices" ) )
{
 ToolTip=StrFormat("Open: %g\nHigh:  %g\nLow:   %g\nClose:  %g (%.1f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}
_SECTION_END();
Need the changes as shown in the image


http://postimg.org/image/3z63dpfs3/


Thanks

Sudha
normally Short variable is used for sale and Sell variable is used to cover Buys so instead of

Buy = r > 70;
Sell = r < 30;

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes(shape, IIf( Buy, colorBrightGreen, colorRed ), 0, IIf( Buy, Low, High ) );

do

Buy = r > 70;
Short = r < 30;

shape = Buy * shapeUpArrow + Short * shapeDownArrow;
PlotShapes(shape, IIf( Buy, colorBrightGreen, colorRed ), 0, IIf( Buy, Low, High ) );

Sell = ref(buy, -1) and r < 70 ;
Cover = ref(short, -1) and r >30 ;

sell = exrem(sell, buy) ;
cover = exrem(cover, short) ;
shape1 = Cover * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes(shape, colorblack, 0, IIf( Buy, High, Low ) );

you get the idea I suppose.....just a warning...above code is not tested so if any syntax error pls forgive
 
normally Short variable is used for sale and Sell variable is used to cover Buys so instead of

Buy = r > 70;
Sell = r < 30;

shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes(shape, IIf( Buy, colorBrightGreen, colorRed ), 0, IIf( Buy, Low, High ) );

do

Buy = r > 70;
Short = r < 30;

shape = Buy * shapeUpArrow + Short * shapeDownArrow;
PlotShapes(shape, IIf( Buy, colorBrightGreen, colorRed ), 0, IIf( Buy, Low, High ) );

Sell = ref(buy, -1) and r < 70 ;
Cover = ref(short, -1) and r >30 ;

sell = exrem(sell, buy) ;
cover = exrem(cover, short) ;
shape1 = Cover * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes(shape, colorblack, 0, IIf( Buy, High, Low ) );

you get the idea I suppose.....just a warning...above code is not tested so if any syntax error pls forgive
Hello sir,

Please give an idea how to create exploration for the above code


Thanks

Sudha
 

Similar threads