Simple Coding Help - No Promise.

Romeo1998

Well-Known Member
Dear friend cellclinic,
in the first pic, daily data is Empty, it is bcoz we r calculating moving average of 200 days, but there is not enough data , so it is shown as being Empty, n hence yellow dots on chart r not shown :happy:
yellow dots will only be shown on chart when current price is above the 200 sma of 15 mins timeframe n 200 sma of daily timeframe :happy:
change the periods in parameters to 10 or 15 n then yellow dots will b shown on chart :happy:
for scanning all stocks which r above the 200 sma of 15 mins timeframe n 200 sma of daily timeframe, just click on explore, n not on backtest :happy:
in this afl, i have not included the buy,sell,short n cover variables, without them u will get error in backtest :)
 
Last edited:
Dear friend Mercedes,
i will have to first understand this Supertrend afl :pompus:
Sir,

I think below AFL would be helpful. TrendUp and TrendDown variables can be used in desired output. But not a tech sevy, so difficult for me to code.

Code:
_SECTION_BEGIN("Super Trend");
Factor=Param("Factor",4,1,10,0.1);
Pd=Param("ATR Periods",10,1,100,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-1; 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,"TrendUp",colorGreen);
Plot(TrendDown,"TrendDown",colorRed);

_SECTION_END();
 

cellclinic

Well-Known Member
Dear friend cellclinic,
in the first pic, daily data is Empty, it is bcoz we r calculating moving average of 200 days, but there is not enough data , so it is shown as being Empty, n hence yellow dots on chart r not shown :happy:
yellow dots will only be shown on chart when current price is above the 200 sma of 15 mins timeframe n 200 sma of daily timeframe :happy:
change the periods in parameters to 10 or 15 n then yellow dots will b shown on chart :happy:
for scanning all stocks which r above the 200 sma of 15 mins timeframe n 200 sma of daily timeframe, just click on explore, n not on backtest :happy:
in this afl, i have not included the buy,sell,short n cover variables, without them u will get error in backtest :)
Hello Friend ...

Here is snap shot for monthly data i have ... But still it is showing error ... & in 2nd image showing enough data to plot 200 sma ... Kindly look into it & help me out Dear :)
 

Attachments

PLEASE HELP TO WRITE THIS AFL CODE TO REDUCE BUY AND SELL FALSE SIGNAL


_SECTION_BEGIN("Price");
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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

HiDay = TimeFrameGetPrice("H", inDaily);
LoDay = TimeFrameGetPrice("L", inDaily);

Plot(HiDay ,"",colorGreen,styleDots | styleNoLine);
Plot(LoDay ,"",colorRed,styleDots | styleNoLine);

//Intraday Hrl HI LO //

HiHrly = TimeFrameGetPrice("H", inHourly);
LoHrly = TimeFrameGetPrice("L", inHourly);

Plot(HiHrly ,"",colorBlue, styleLine );
Plot(LoHrly ,"",colorDarkRed,styleLine);

GfxTextOut("H/H - " + WriteVal(HiHrly) ,50,65);
GfxTextOut("H/L - " + WriteVal(LoHrly) ,50,80);
GfxTextOut("D/H - " + WriteVal(Hiday) ,50,95);
GfxTextOut("D/L - " + WriteVal(Loday) ,50,110);
Filter = 1;
AddColumn(HiHrly,"High");
AddColumn(LoHrly,"Low");


_SECTION_END();

//TimeFrameMode(3);
_SECTION_BEGIN("ADX");
PADX = Param( "ADX", 8, 1, 2000, 1 );
PPDI = Param( "PDI", 8, 1, 2000, 1 );
PMDI = Param( "MDI", 8, 1, 2000, 1 );
tf = Param( "TF", 60, 1, 375, 1 );
expnd=ParamToggle("EXPAND", "EXPANDFIRST|EXPANDLAST",0);

TimeFrameSet(in1Minute*tf );
k0=ADX( PADX );
d0=PDI( PPDI);
M0=MDI( PMDI );
TimeFrameRestore();

k=TimeFrameExpand( k0, in1Minute*tf,expnd );
d=TimeFrameExpand( d0, in1Minute*tf,expnd );
M=TimeFrameExpand( M0, in1Minute*tf,expnd );


//Plot( k,"ADX :", ParamColor( "ADX Color", colorWhite ), ParamStyle("Style") );
//Plot( d,"PDI", ParamColor( "PDI Color", colorGreen), ParamStyle("Style") );
//Plot( M,"MDI", ParamColor( "MDI Color", colorRed), ParamStyle("Style") );

Buy= D>M AND K>21 AND K<30 AND K>Ref(K,-1);
Sell = d<m;
Short = D<M AND K>21 AND K<30 AND K>Ref(K,-1);
Cover=m<d;
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);

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

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorAqua, 0,L, Offset=-20);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorAqua, 0,H, Offset=-10);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorGreen, 0,L, Offset=-10);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorRed, 0,H, Offset=-10);





USE

I USE THIS AFL IN 5 MIN TF WITH 60 MIN PARAMETER SETTING

REQUIRMENT

BUY = WHEN HIGH CROSS BUY HIGH CONDITION
SHORT = WHEN LOW CROSS SHORT LOW CONDITION
 

toocool

Well-Known Member
_SECTION_BEGIN("CRB obv");
x=Param("Min of CR:",30,0,375,1);
nd=Day() != Ref(Day(), -1);

crbh = ValueWhen(nd,Ref(HHV(OBV(),x),-1));
crbl = ValueWhen(nd,Ref(LLV(OBV(),x),-1));

Plot(crbh,"\nCRB H",colorBlack);
Plot(crbL,"\nCRB L",colorBlack);

if( ParamToggle("CRB cloud", "No|Yes", 1))
PlotOHLC(crbl,crbh,crbl,crbl,"",ParamColor("R col",colordarkgrey),stylenoreScale|styleNoLabel|styleCloud,0,0,0,-7);


_SECTION_END();

this is crb obv can we please have change in code for showing next days crb lines drawn with the click of a button ??

show it at eod itself at levels it will show next day

is it possible to plot 2 different instrument obv in same chart for corelation purpose

kindly experts help and code this

regards
 

Similar threads