Simple Coding Help - No Promise.

Plz add buy/sell variables in this afl.

i want scan and explorer this afl. Both or not working.
Plz add both variables.

And plz add .25% profit booking for short or long.
LOng above signal candle high. target high+ .25% Add round symbol in green
Short below signal candle low. target Low- .25% Add round symbol in red.

If possible add Long@ and target.... Short @ and target.. only if possible.. like signal panel
Thanks in advance

PHP:
_SECTION_BEGIN("Zig-zag with buy and sell signals-auto trend lines");


//////////////////////////////////////////////////////////////////////////////////////////


//z_ZigZagValid
// ******** CHARTING
per=Param ("% change",0.25,0.25,2,0.01);

PercentChange = per;
mystartbar = SelectedValue(BarIndex()); // FOR GRAPHING

mystartbardate = LastValue(ValueWhen(mystartbar == BarIndex(), DateNum(),1));

InitialValue = LastValue(ValueWhen(mystartbardate == DateNum(), C , 1 ) ) ;
Temp1 = IIf(BarIndex() >= mystartbar, InitialValue, Null) ;
Plot(Temp1, " ", colorBlack,styleLine);
Plot((1+(LastValue(PercentChange)/100))*(Temp1), " ", colorGreen, styleLine) ;
Plot((1-(LastValue(PercentChange)/100))*(Temp1), " ", colorRed, styleLine) ;

ZZ = Zig(C,LastValue(PercentChange)) ; 
PivotLow = Ref(IIf(Ref(ROC(ZZ,1),-1) < 0 AND ROC(ZZ,1) > 0, 1, Null),1);
PivotHigh = Ref(IIf(Ref(ROC(ZZ,1),-1) > 0 AND ROC(ZZ,1) < 0, 1, Null),1);



Buy_Valid = IIf(C>(1+(LastValue(PercentChange)/100))*(ValueWhen(PivotLow, C,
1))
AND ROC(ZZ,1) > 0,1,0); 
Sell_Valid = IIf(C<(1-(LastValue(PercentChange)/100))*(ValueWhen(PivotHigh, C,
1))
AND ROC(ZZ,1) < 0,1,0); 

Buy_Valid = ExRem(Buy_Valid,Sell_Valid);
Sell_Valid = ExRem(Sell_Valid,Buy_Valid);

PlotShapes( shapeUpArrow*Buy_Valid, colorGreen,0, L, -20); 
PlotShapes( shapeDownArrow*Sell_Valid, colorRed,0,H, -20) ;

BarColors = 
IIf(BarsSince(Buy_Valid) < BarsSince(Sell_Valid) 
AND BarsSince(Buy_Valid)!=0, colorGreen,
IIf(BarsSince(Sell_Valid) < BarsSince(Buy_Valid)
AND BarsSince(Sell_Valid)!=0, colorRed, colorBlue));

Plot(C, " ", BarColors, styleCandle ) ; 
Plot(ZZ," ", colorLightGrey,styleLine|styleThick);
Plot(ZZ," ", BarColors,styleDots|styleNoLine);

Title = Name() + " " + Date() + WriteIf(PivotLow, " Up Pivot
","")+WriteIf(PivotHigh," Down Pivot ","")+ WriteIf(Buy_Valid, " Buy Point ",
"") + WriteIf(Sell_Valid, " Sell Point ", "") ;


AlertIf( Buy_Valid, "SOUND C:\\Windows\\Media\\tada.wav", "Audio alert", 2 );
AlertIf( Sell_Valid,"SOUND C:\\Windows\\Media\\Windows XP Critical Stop.wav", "Audio alert", 2 );


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

x = Cum(1);
s1=C;
s11=C;
pS = TroughBars( s1, per, 1 ) == 0;
endt= SelectedValue(ValueWhen( pS, x, 1 ));
startt=SelectedValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = SelectedValue(ValueWhen( pS, s1, 1 ) );
startS = SelectedValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;
bS = endS;
trendlineS = aS * ( x -endt ) + bS;
g3= IIf(x>startt-10,trendlineS,-1e10);
Plot(g3,"",colorRed,styleThick);

pR = PeakBars( s11, per, 1 ) == 0;
endt1= SelectedValue(ValueWhen( pR, x, 1 ));
startt1=SelectedValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = SelectedValue(ValueWhen( pR, s11, 1 ) );
startR = SelectedValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
g4= IIf(x>startT1-10,trendlineR,-1e10);
Plot(g4,"",colorGreen,styleThick);

//////////////////////////////////////////////////////////////////////////////////////
_SECTION_END();
 
Sir i want afl working for my above strategy
I do this in manual, opening charts of few selected company and with pen & paper. I would now like that ami does that for me

Explaination
WHENEVER THE CANDLE BREAKS SUPPORT "SELL" IS TO BE TRIGGERED

How to find support:-
When a stock price is in uptrend lowest low between 2 high is the support. If the uptrend continued the support gets modified in the same manner.

and vice versa for triggering BUY
the image demonstrates the strategy

thanx in advance
 
Last edited:

extremist

Well-Known Member
@ abhig10

or pratapji

would u guys plz try ur hand on this.....

i tried but failed.

hope u may help ....!

Requesting on behalf of rvlv

frm : http://www.traderji.com/amibroker/93075-looking-forafl-code-concept-anybody-help-please.html


Looking for afl code for this concept-anybody help please
Hi friends
Here I have a concept which I need afl to be coded.

Concept

50-80 formula
clayburg system page 155
--------------------------

calculate 6 day moving average of new highs
calculate 6 day moving average of new lows

each day add number of new highs to number of new lows.
get sumnewHL

BUY RATIO = 6DAY MA OF NEW HIGHS DIVIDED BY SUMNEWHL

SELL RATIO = 6DAY MA OF LOWS DIVIDED BY SUMNEWHL

YOU NEED 6 DAY MOVING AVERAGE OF THE SUM OF NEW HIGHS AND NEW LOWS.

GO LONG ON A BUY RATIO OF 0.50 OR MORE
EXIT THE MARKET ON A SELL RATIO OF 0.80 OR MORE.
 
Last edited:
@ abhig10

or pratapji

would u guys plz try ur hand on this.....

i tried but failed.

hope u may help ....!

Requesting on behalf of rvlv

frm : http://www.traderji.com/amibroker/93075-looking-forafl-code-concept-anybody-help-please.html


Looking for afl code for this concept-anybody help please
Hi friends
Here I have a concept which I need afl to be coded.

Concept

50-80 formula
clayburg system page 155
--------------------------

calculate 6 day moving average of new highs
calculate 6 day moving average of new lows

each day add number of new highs to number of new lows.
get sumnewHL

BUY RATIO = 6DAY MA OF NEW HIGHS DIVIDED BY SUMNEWHL

SELL RATIO = 6DAY MA OF LOWS DIVIDED BY SUMNEWHL

YOU NEED 6 DAY MOVING AVERAGE OF THE SUM OF NEW HIGHS AND NEW LOWS.

GO LONG ON A BUY RATIO OF 0.50 OR MORE
EXIT THE MARKET ON A SELL RATIO OF 0.80 OR MORE.
Will get you started but you will have to take it up from there

Code:
NewLow  = L == Lowest(L); 
NewHigh = H == Highest(H); 
Filter = NewHigh OR NewLow;

AddToComposite(Sum(NewHigh,1),"~All_Time_High", "C", atcFlagDeleteValues | atcFlagDefaults | 16);
AddToComposite(Sum(NewLow, 1),"~All_Time_Low",  "C", atcFlagDeleteValues | atcFlagDefaults | 16); 
Plot(Foreign("~All_Time_High","C",1),"New All Time High Count",colorBlue,styleThick);   
Plot(Foreign("~All_Time_Low", "C",1),"New All Time Lows Count",colorRed,styleThick);


run the scan to populate the composite ticker . . .


the above code will plot number of new all time highs and lows in your database/scan watch list . . .


rest all the system etc part you should be able to do easily


Happy :)
 

Nehal_s143

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. :(

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 );


_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 );
j = ( O + H + L + C ) / 4;
}
else
{
nm = ( HaHigh1 - HaLow1 );
j = ( HaOpen1 + HaHigh1 + HaLow1 + HaClose1 ) / 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;

TimeFrameRestore();


Nw2f = TimeFrameExpand( Nw, tfrm);
J2f = TimeFrameExpand( J, tfrm);


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

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


Buy = NW<j AND NW2f<j2f;
Sell = NW>j;
Short = NW>j AND NW2f>j2f;
Cover = NW<j;

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();
Please help me to fix signal when chart is scrolled or moved
 
Please help me to fix signal when chart is scrolled or moved

Code:
_SECTION_BEGIN("Dancing_Lines_Give_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();
I plotted NW and J just after buy/sell signal and the jumping signals are due to these values not being stable . . . .

NW and J seem to be dependent on data on the screen / chart . . .

Verify the logic where you are generating these values . . .



Happy :)



Edit

You have already plotted, NW above after the first loop which is stable (yellow flipping line)
these values (NW & J are getting affected/re-assigned on the second loop (10 mins TF)

if you switch the chart to 10 minutes you will see everything will be stable . . . signals and lines . . .



Happy :)
 
Last edited:

Similar threads