Simple Coding Help - No Promise.

cellclinic

Well-Known Member
Hello Friends :)

Again with a request ... Can i gets thick line option & Buy Sell Arrow in below mentioned Super Trend Formula ???

_SECTION_BEGIN("SuperTrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);

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


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

PositionSize = 100000;

Factor=Optimize("Factor",6,2,10,1);
Pd=Optimize("ATR Periods",34,1,20,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

for (i = 1; i <BarCount; i++) {
TrendUp = Null;
TrendDown = Null;

trend=1;


if (Close>Up[i-1]) {
trend=1;
if (trend[i-1] == -1) changeOfTrend = 1;

}
else if (Close<Dn[i-1]) {
trend=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}
else if (trend[i-1]==1) {
trend=1;
changeOfTrend = 0;
}
else if (trend[i-1]==-1) {
trend=-1;
changeOfTrend = 0;
}

if (trend<0 && trend[i-1]>0) {
flag=1;
}
else {
flag=0;
}

if (trend>0 && trend[i-1]<0) {
flagh=1;
}
else {
flagh=0;
}

if (trend>0 && Dn<Dn[i-1]){
Dn=Dn[i-1];
}

if (trend<0 && Up>Up[i-1])
{ Up=Up[i-1];
}

if (flag==1)
{ Up=(H+L)/2+(Factor*iATR);;
}
if (flagh==1)
{ Dn=(H+L)/2-(Factor*iATR);;
}
if (trend==1) {
TrendUp=Dn;
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}
else if (trend==-1) {
TrendDown=Up;
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}

Plot(TrendUp,"Trend",colorBlack);
Plot(TrendDown,"Down",colorBlack);

Buy = trend==1;
Sell=trend==-1;

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


BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);


Title = EncodeColor(colorWhite)+ "Super Trend AFL code from www.marketcalls.in" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorYellow)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);





Regards ...
 

toughard

Well-Known Member
Hello Friends :)

Again with a request ... Can i gets thick line option & Buy Sell Arrow in below mentioned Super Trend Formula ???

_SECTION_BEGIN("SuperTrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);

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


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

PositionSize = 100000;

Factor=Optimize("Factor",6,2,10,1);
Pd=Optimize("ATR Periods",34,1,20,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

for (i = 1; i <BarCount; i++) {
TrendUp = Null;
TrendDown = Null;

trend=1;


if (Close>Up[i-1]) {
trend=1;
if (trend[i-1] == -1) changeOfTrend = 1;

}
else if (Close<Dn[i-1]) {
trend=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}
else if (trend[i-1]==1) {
trend=1;
changeOfTrend = 0;
}
else if (trend[i-1]==-1) {
trend=-1;
changeOfTrend = 0;
}

if (trend<0 && trend[i-1]>0) {
flag=1;
}
else {
flag=0;
}

if (trend>0 && trend[i-1]<0) {
flagh=1;
}
else {
flagh=0;
}

if (trend>0 && Dn<Dn[i-1]){
Dn=Dn[i-1];
}

if (trend<0 && Up>Up[i-1])
{ Up=Up[i-1];
}

if (flag==1)
{ Up=(H+L)/2+(Factor*iATR);;
}
if (flagh==1)
{ Dn=(H+L)/2-(Factor*iATR);;
}
if (trend==1) {
TrendUp=Dn;
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}
else if (trend==-1) {
TrendDown=Up;
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}

Plot(TrendUp,"Trend",colorBlack);
Plot(TrendDown,"Down",colorBlack);

Buy = trend==1;
Sell=trend==-1;

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


BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);


Title = EncodeColor(colorWhite)+ "Super Trend AFL code from www.marketcalls.in" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorYellow)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);





Regards ...



oh good god.... one persons problems is holding solution for other persons problem...
I just got answer for my question above.... from your question :)
 

amitrandive

Well-Known Member
I'm sorry but I don't exactly understand what you mean. Are you saying that what I'm looking for isn't possible in an Exploration?

Anything is possible in an exploration.
All I am saying is that either you can use Two Different Analysis Windows for different parameters to get results or combine the two requirements in one AFL with different buy conditions like
Buy1=.....,
Buy2=......,
Filter=Buy1 or Buy2....
 

amitrandive

Well-Known Member
Hello Friends :)

Again with a request ... Can i gets thick line option & Buy Sell Arrow in below mentioned Super Trend Formula ???

_SECTION_BEGIN("SuperTrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);
.
.

Offset=-45);
Regards ...
Changed SuperTrend line to thick line,Buy/Sell arrows are already present in the code.

Code:
_SECTION_BEGIN("SuperTrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);

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


_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

PositionSize = 100000;

Factor=Optimize("Factor",6,2,10,1);
Pd=Optimize("ATR Periods",34,1,20,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

for (i = 1; i <BarCount; i++) {
TrendUp[i] = Null;
TrendDown[i] = Null;

trend[i]=1;


if (Close[i]>Up[i-1]) {
trend[i]=1;
if (trend[i-1] == -1) changeOfTrend = 1;

}
else if (Close[i]<Dn[i-1]) {
trend[i]=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}
else if (trend[i-1]==1) {
trend[i]=1;
changeOfTrend = 0;
}
else if (trend[i-1]==-1) {
trend[i]=-1;
changeOfTrend = 0;
}

if (trend[i]<0 && trend[i-1]>0) {
flag=1;
}
else {
flag=0;
}

if (trend[i]>0 && trend[i-1]<0) {
flagh=1;
}
else {
flagh=0;
}

if (trend[i]>0 && Dn[i]<Dn[i-1]){
Dn[i]=Dn[i-1];
}

if (trend[i]<0 && Up[i]>Up[i-1])
{ Up[i]=Up[i-1];
}

if (flag==1)
{ Up[i]=(H[i]+L[i])/2+(Factor*iATR[i]);;
}
if (flagh==1)
{ Dn[i]=(H[i]+L[i])/2-(Factor*iATR[i]);;
}
if (trend[i]==1) {
TrendUp[i]=Dn[i];
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}
else if (trend[i]==-1) {
TrendDown[i]=Up[i];
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}

Plot(TrendUp,"Trend",colorBlack,styleThick);
Plot(TrendDown,"Down",colorBlack,styleThick);

Buy = trend==1;
Sell=trend==-1;

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


BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);


Title = EncodeColor(colorWhite)+ "Super Trend AFL code from www.marketcalls.in" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorYellow)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
 
Anyone please help me

Conditions

Buy above 1 = 15 deg res from (Prev Day High + Prev day Low )/2
Sell below 1 = 15 deg sup from (Prev Day High + Prev day Low )/2

If Current Day Open > Buy above 1

Buy above 2 = 30 deg res from (Prev Day High + Prev day Low )/2
Sell below 2 = 15 deg sup from (Current Day High)

If Current Day Open < Sell below 1

Buy above 3 = 15 deg res from (Current Day Low )
Sell below 3 = 30 deg sup from (Prev Day High + Prev day Low )/2



Trailing Stoploss for Buy above = 15 deg sup from (Current Day High)
Trailing Stoploss for Sell below = 15 deg res from (Current Day Low)

Please try to code this
Buy Above ,sell below and trailing stoploss levels should be plotted in a side Box
Trailing stoploss should be plotted in graph also

Regards Renjith
 

Anything is possible in an exploration.
All I am saying is that either you can use Two Different Analysis Windows for different parameters to get results or combine the two requirements in one AFL with different buy conditions like
Buy1=.....,
Buy2=......,
Filter=Buy1 or Buy2....
Ok. So any pointers on how I could create the two BUY/SELL conditions?

For eg. if I run an exploration with the following....

Buy = Cross( TEMA_LOWER, TEMA_UPPER ) ;
Sell = Cross( TEMA_UPPER, TEMA_LOWER ) ;

If the above is true today, how do I get the exploration to show me data (date, OHLC) WHEN this condition was true previously too? <-- This would be the BUY2 you mentioned above.
 

trash

Well-Known Member
Ok. So any pointers on how I could create the two BUY/SELL conditions?

For eg. if I run an exploration with the following....

Buy = Cross( TEMA_LOWER, TEMA_UPPER ) ;
Sell = Cross( TEMA_UPPER, TEMA_LOWER ) ;

If the above is true today, how do I get the exploration to show me data (date, OHLC) WHEN this condition was true previously too? <-- This would be the BUY2 you mentioned above.
Do you wanna simulate individual backtest in exploration mode or what is it that you want to do? Your specific requirements are totally unclear. What do you mean by previous condition being true?

Because there are raw signals or non raw signals. For example IF in chart you wouldn't use ExRem there then would output raw signals (while number of raw signals can be equal to number of non raw signals depending on condition).
 
Do you wanna simulate individual backtest in exploration mode or what is it that you want to do? Your specific requirements are totally unclear. What do you mean by previous condition being true?

Because there are raw signals or non raw signals. For example IF in chart you wouldn't use ExRem there then would output raw signals (while number of raw signals can be equal to number of non raw signals depending on condition).
Sorry if I sound unclear. This is as simply I can put it....

Exploration:
Buy = Cross( TEMA_LOWER, TEMA_UPPER ) ;
Sell = Cross( TEMA_UPPER, TEMA_LOWER ) ;

a. Run exploration and get some results. Lets say Stock1 & Stock2.
a1. The above results happen because either of the exploration conditions are true.
b. Check when was the last time Stock1 had a Buy OR Sell?
b2. When was the last time Stock2 had a Buy or Sell?
c. List data for step b, b2 alongside data from step a.
 

amitrandive

Well-Known Member
Dear All

AFL for Stochastic crossover.

I need the arrows to be at the exact crossover locations as shown in the sketch.

Also is there any way to increase the arrow size?




Code:
_SECTION_BEGIN("StochasticsSmooth");
grid_day = IIf(Day()!=Ref(Day(),-1),1,0);  
Plot(grid_day,"",colorDarkGrey,styleHistogram|styleDashed|styleNoLabel|styleOwnScale);
 
SetChartOptions(0,chartShowArrows|chartShowDates);
d1=StochK(18, 9);//, 18) ;
d2=StochD(18,9,3);//, 20);
qw=WMA(d1, 1); wq=WMA(d2, 1);
ww=WMA(qw, 2); ee=WMA(wq, 2);
p1=WMA(ww, 3); p2=WMA(ee, 3);
Plot(p1, "price", colorGreen,styleThick);
Plot(p2, "price", colorRed,styleThick);
 
Overbought = 80 ;
Oversold =20 ;
Center = 50 ;
 
Plot(Overbought, "",colorRed,styleThick) ;
Plot(Oversold, "",colorGreen,styleThick) ;
Plot(Center, "",colorBlue, styleDashed,styleThick) ;
Buy=Cross(p1, p2)  ;
Sell=Cross(p2, p1) ;
PlotShapes(IIf( Sell, shapeDownArrow , shapeNone), colorRed,0, offset =25) ;
PlotShapes(IIf( Buy, shapeUpArrow , shapeNone), colorBlue,0, Offset=50) ;
Cover=Buy; Short=Sell;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
 
 
BuyPrice=ValueWhen(Buy, C);
SellPrice=ValueWhen(Sell, C);
 
 
Filter=Buy OR Sell ;
 
 
                SetOption("NoDefaultColumns", True);
                AddTextColumn(Name(), "Symbol", 77, colorDefault, colorDefault, 120);
                AddColumn(DateTime(), "Trigger Date", formatDateTime);
 
 
 
                AddColumn(IIf(Buy, 66, 83), "Signal", formatChar, colorYellow, IIf(Buy, colorGreen, colorRed));
               AddColumn(IIf(Buy, BuyPrice, SellPrice),  "Entry", 6.2);
 AddColumn(LastValue(C), "Entry Price.", 6.2);
_SECTION_END();
 

Similar threads