Support n resistance -code needed in afl-basis follows

rvlv

Active Member
#1
Hi experts
here is a simple support resistance code,but it in mt4.

see attached chart and decide why it is different than others.
can somebody code it in afl please!
Anyone who understands the code concept please share it!
advance thanks

--------------chart hourly here---------


-------------code---------------------------------------------

HTML:
//+------------------------------------------------------------------+
//|                                             SUPRESMultiFrame.mq4 |
//|                                                                  |
//|                                                            RD    |
//+------------------------------------------------------------------+
#property copyright "RD"
#property link      "[email protected]"
#property indicator_chart_window
#define MaxObject    1000
//---- indicator parameters
extern int TimeFrame=1440;
extern int BarsMax=144;
extern int ExtDepth=13;
extern int ExtDeviation=1;
extern int ExtBackstep=5;
extern bool DeleteObjectsOnExit=true;
extern color LineColor1=RosyBrown;
extern color LineColor5=Aqua;
extern color LineColor15=DeepPink;
extern color LineColor30=PaleVioletRed;
extern color LineColor60=Red;
extern color LineColor240=DarkOrange;
extern color LineColor1440=DeepSkyBlue;
extern color LineColor10080=Lime;
//-----------------------
double ExtMapBuffer[];
double ExtMapBuffer2[];
int SUPRESCount=0;
int linewidth;
string NamePattern;
color LineColor;


//+------------------------------------------------------------------+
//|                           Delete objects                         |
//+------------------------------------------------------------------+
int DeleteSupRes()
   {     
      int ObjectCount=ObjectsTotal();
      string names[MaxObject];
      for (int i=0; i<ObjectCount;i++)
         names[i]=ObjectName(i);
      for (i=0; i<ObjectCount;i++) 
      {
         string objname=names[i];
         objname=StringSubstr(objname,0,StringLen(NamePattern));
         if (objname!=NamePattern || ObjectType(names[i])!=OBJ_TREND)
               names[i]="";              
      }
      for (i=0; i<ObjectCount;i++)
      { 
         if (names[i]!="") { 
         ObjectDelete(names[i]);}
      }   
      return(0);
   }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(2);
   SetIndexBuffer(0,ExtMapBuffer);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(0,0.0);
   ArraySetAsSeries(ExtMapBuffer,true);
   ArraySetAsSeries(ExtMapBuffer2,true);
   switch (TimeFrame)
     {
        case 1: linewidth=1; LineColor=LineColor1; break;   
        case 5: linewidth=1; LineColor=LineColor5; break;
        case 15: linewidth=1; LineColor=LineColor15; break;
        case 30: linewidth=1; LineColor=LineColor30; break;
        case 60: linewidth=1; LineColor=LineColor60; break;
        case 240: linewidth=1; LineColor=LineColor240; break;
        case 1440: linewidth=1; LineColor=LineColor1440; break;
        case 10080: linewidth=1; LineColor=LineColor10080; break;
        default: linewidth=1; TimeFrame=Period(); break;
     }
   NamePattern=DoubleToStr(TimeFrame,0)+" SUPRES ";
   if (BarsMax<55) BarsMax=55;
   
   DeleteSupRes();
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
/*      if (DeleteObjectsOnExit) DeleteSupRes();
      return(0);
      
*/

    ObjectsDeleteAll();
          
  }   
  
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int    shift, back,lasthighpos,lastlowpos;
   double val,res;
   double curlow,curhigh,lasthigh,lastlow;
   string objectname;
   
   if(BarsMax==0) {BarsMax=Bars/2;}// return(0);
   for(shift=iBars(NULL,TimeFrame)-ExtDepth; shift>=0; shift--)
     {
      val=iLow(NULL,TimeFrame,Lowest(NULL,TimeFrame,MODE_LOW,ExtDepth,shift));
      if(val==lastlow) val=0.0;
      else 
        { 
         lastlow=val; 
         if((iLow(NULL,TimeFrame,shift)-val)>(ExtDeviation*Point)) val=0.0;
         else
           {
            for(back=1; back<=ExtBackstep; back++)
              {
               res=ExtMapBuffer[shift+back];
               if((res!=0)&&(res>val)) ExtMapBuffer[shift+back]=0.0; 
              }
           }
        } 
      ExtMapBuffer[shift]=val;
      //--- high
      val=iHigh(NULL,TimeFrame,Highest(NULL,TimeFrame,MODE_HIGH,ExtDepth,shift));
      if(val==lasthigh) val=0.0;
      else 
        {
         lasthigh=val;
         if((val-iHigh(NULL,TimeFrame,shift))>(ExtDeviation*Point)) val=0.0;
         else
           {
            for(back=1; back<=ExtBackstep; back++)
              {
               res=ExtMapBuffer2[shift+back];
               if((res!=0)&&(res<val)) ExtMapBuffer2[shift+back]=0.0; 
              } 
           }
        }
      ExtMapBuffer2[shift]=val;
     }

   // final cutting 
   lasthigh=-1; lasthighpos=-1;
   lastlow=-1;  lastlowpos=-1;

   for(shift=iBars(NULL,TimeFrame)-ExtDepth; shift>=0; shift--)
     {
      curlow=ExtMapBuffer[shift];
      curhigh=ExtMapBuffer2[shift];
      if((curlow==0)&&(curhigh==0)) continue;
      //---
      if(curhigh!=0)
        {
         if(lasthigh>0) 
           {
            if(lasthigh<curhigh) ExtMapBuffer2[lasthighpos]=0;
            else ExtMapBuffer2[shift]=0;
           }
         //---
         if(lasthigh<curhigh || lasthigh<0)
           {
            lasthigh=curhigh;
            lasthighpos=shift;
           }
         lastlow=-1;
        }
      //----
      if(curlow!=0)
        {
         if(lastlow>0)
           {
            if(lastlow>curlow) ExtMapBuffer[lastlowpos]=0;
            else ExtMapBuffer[shift]=0;
           }
         //---
         if((curlow<lastlow)||(lastlow<0))
           {
            lastlow=curlow;
            lastlowpos=shift;
           } 
         lasthigh=-1;
        }
     }
  
   for(shift=iBars(NULL,TimeFrame)-1; shift>=0; shift--)
     {
      if(shift>=iBars(NULL,TimeFrame)-ExtDepth) ExtMapBuffer[shift]=0.0;
      else
        {
         res=ExtMapBuffer2[shift];
         if(res!=0.0) ExtMapBuffer[shift]=res;
        }
     }
 ///////////////////////// Lines creation /////////////////   
   int count=0;
   double TempBufferPrice[MaxObject];   
   int TempBufferBar[MaxObject];
   string ObjectNames[MaxObject];
 //////////////////////// lists of lines //////////////////  
   for(shift=BarsMax; shift>0; shift--)
       if (ExtMapBuffer[shift]>0)
         {
            count++;
            TempBufferPrice[count-1]=ExtMapBuffer[shift];
            TempBufferBar[count-1]=shift;
         }   
   for(int i=0; i<count; i++)   
         ObjectNames[i]=/*TimeFrame+"m S/R("+i+")"+DoubleToStr(TempBufferPrice[i],Digits)+" "+*/
                        TimeToStr(iTime(NULL,TimeFrame,TempBufferBar[i]),TIME_DATE|TIME_MINUTES);

 /////// deleting pending objects ///////////////     
   int ObjectForDeleteCount=0;
   string ObjectsForDelete[MaxObject];
   for(i=0; i<ObjectsTotal(); i++)   
      {
         objectname=ObjectName(i);
         if (StringSubstr(objectname,0,StringLen(NamePattern))==NamePattern)
            {
               ObjectForDeleteCount++;
               ObjectsForDelete[ObjectForDeleteCount-1]=objectname;
            }   
      }
   for(i=0; i<count-2; i++)
      {
         objectname=ObjectNames[i];
            for(int j=0; j<ObjectForDeleteCount; j++)
                 if(ObjectsForDelete[j]==objectname)
                  {
                      ObjectsForDelete[j]="";    
                      break;
                  }     
      }
   for(j=0; j<ObjectForDeleteCount; j++)
      if (ObjectsForDelete[j]!="")
      { 
         ObjectDelete(ObjectsForDelete[j]);
      }
 ////////////// objects plotting /////////////////  
   for(i=0; i<count; i++)   
      {
         if (ObjectFind(ObjectNames[i])==-1)
            {
                ObjectCreate(ObjectNames[i],OBJ_TREND,0,iTime(NULL,TimeFrame,TempBufferBar[i]),TempBufferPrice[i],
                                 iTime(NULL,TimeFrame,TempBufferBar[i])+10080*60,TempBufferPrice[i]);
                ObjectSet(ObjectNames[i],OBJPROP_WIDTH,linewidth); 
                ObjectSet(ObjectNames[i],OBJPROP_COLOR,LineColor);
                ObjectSet(ObjectNames[i],OBJPROP_RAY,True);
                ObjectSetText(ObjectNames[i],ObjectNames[i]/*+" "+DoubleToStr(TempBufferPrice[i],Digits),8,"Courier",LightSteelBlue*/);
            } 
      }        
}
 

rvlv

Active Member
#2
HI
can anybody help code this unique support resistance bands or zones please

THe code uses multiple timeframes.

cheers
rvlv
 

saivenkat

Well-Known Member
#3
Hi Rvlv.. Sorry for posting Off topic question here... I have no other go.. than to invite you attention..

Could you tell me any mt4 broker providing unlimited demo, other than GCI.. wherein.. the pairs USDINR, GBPINR, JPYINR, EURINR are covered? From the Chart posted by you.. i could see that you are using xDirect.. Could you please tell me.. does xdirect satisfy my needs?


Regards

Edit: I registered for demo in Xdirect..its valid for 30 days only.. Is there any chance .. by which we can continue to re-register with them once the trial period is over?
 
Last edited:
#4
Hi Rvlv.. Sorry for posting Off topic question here... I have no other go.. than to invite you attention..

Could you tell me any mt4 broker providing unlimited demo, other than GCI.. wherein.. the pairs USDINR, GBPINR, JPYINR, EURINR are covered? From the Chart posted by you.. i could see that you are using xDirect.. Could you please tell me.. does xdirect satisfy my needs?


Regards

Edit: I registered for demo in Xdirect..its valid for 30 days only.. Is there any chance .. by which we can continue to re-register with them once the trial period is over?
The undermentioned broker OANDA gives unlimited demo account for MT4. Earlier they used to give all the four pairs with INR but now they are giving only USDINR.

Link to follow:

https://fxtrade.oanda.com/demo-account/

Regards.
 
#5
HI
can anybody help code this unique support resistance bands or zones please

THe code uses multiple timeframes.

cheers
rvlv
Hi rvlv,

As far as I could gather from the chart it seems the Pivot High & Pivot Low support and resistance lines.

There is a code based on this concept inspired from the Kwik POP system .

Code:
_SECTION_BEGIN("Pivot High Pivot Low");


//user parameters
parmPlotScoreCard = ParamToggle("Plot KPScoreCard", "No|Yes", 1);
parmPlotA900AutoStop = ParamToggle("Plot A900/AutoStop", "No|Yes", 0);
parmA900Color = ParamColor("A900 Color", colorWhite);
parmA900Style = ParamStyle("A900 Style", styleLine, maskAll);
parmAutoStopColor = ParamColor("AutoStop Color", colorYellow);
parmAutoStopStyle = ParamStyle("AutoStop Style", styleLine, maskAll);
parmPPTextColor = ParamColor("PP Text color", colorBlack);
parmPPTrndColorUp = ParamColor("PP Trend Up color", ColorRGB(167,224,243) );
parmPPTrndColorDn = ParamColor("PP Trend Dwn color", ColorRGB(255,192,203) );
parmPPTextOffSet = Param("PP OffSet", 0.60, 0.20, 1.5, 0.1);
parmTickMultipler = Param("M/W tick allowance", 1, 0, 10, 1);
parmA900AutoStopX = ParamToggle("Plot A900/AutoStop Cross", "No|Yes");
parmA900AutoStopColorX = ParamColor("A900/AutoStop Cross Color", colorBlack);
ParmSCThreshold = Param("ScoreCard Threshold", 3, 1, 9, 1);
parmVoice = ParamToggle("Voice 123 Setups", "No|Yes", 0);
parmAlert = ParamToggle("Alert 123 Setups", "No|Yes", 0);
parmPivotPop = ParamToggle("PivotPop", "No|Yes", 1);
parmBarCancel = Param("Bar Cancel", 7, 1, 20, 1);
parmWaterLevelColor = ParamColor("WalterLevel Color", ColorRGB(127,255,212));
parmWaterLevelStyle = ParamStyle("WaterLevel Style", styleLine, maskAll);
parmBBPeriod = Param("Bollinger Band Period", 10, 2, 30, 1);
parmBBSD = Param("bollinger Band SD", 0.8, 0.2, 3.0);
ParmPlotPPIndicators = ParamToggle("Plot Pivot Pop indicators", "No|Yes", 0);
parmBBColor = ParamColor("BBands Color", colorBlack);
parmBBStyle = ParamStyle("BBands Style", styleLine, maskAll);

ParmDebug = ParamToggle("Debug", "No|Yes", 0);

// constants
_N(PaneName = Name() + Interval(2)+ _SECTION_NAME());
_N(NewBarName = "NewBar" + PaneName);

//functions
function NewBarP()
{
PrevDT = StaticVarGet( NewBarName);
DT = LastValue(DateTime());
StaticVarSet( NewBarName,DT);
return DT != PrevDT;
}
function MRoundP(Number, Multiple )
{
if(Multiple == 0 )
{

xMultiple = 0.01; }
else
{
xMultiple = Multiple;
}
Divided = Number / xMultiple;
intDivided = int(Divided);
intDivided = intDivided + round(Divided - intDivided);
return intDivided * xMultiple;
}

//miscellaneous setups
ObjAB = CreateObject("Broker.Application");
ticker = objAB.Stocks(Name() );
if(ticker.TickSize == 0)
{
TickValue = 0.01; //set TickValue to a penney
}
else
{
TickValue = ticker.TickSize; // use Tick Size for this symbol
}
NewBarSignal = NewBarP();
// KP Indicators
KPA900 = E_TSKPA900(Close);
KPAutoStop = E_TSKPAUTOSTOP(High,Low,Close);
Ctmpl = E_TSKPCOLORTMPL(Open,High,Low,Close,Volume); //ScoreCard
KPScoreCard = 0;
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd0 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd1 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd2 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd3 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd4 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd5 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd6 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd7 > 0, 1, -1);
KPScoreCard = KPScoreCard + IIf(tskp_colortmplcnd8 > 0, 1, -1);

if(parmDebug == 1)
{
printf("a900: %0.6f% \nAutoStop: %0.6f%\nScoreCard: %0.0f%\n", KPA900, KPAutoStop, KPScoreCard);
}
if(parmPlotScoreCard == 1)
{
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g% (%0.4f%) {{VALUES}}", O, H, L, C, SelectedValue( C - Ref(C, -1)) ));
if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) )
{
ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.2f%%)\nVolume: "+NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 )));
}
Color = IIf(KPScoreCard >= parmSCThreshold, colorBlue, IIf(KPScoreCard <= -parmSCThreshold, colorRed, colorYellow) );
Plot( C, "Close", Color , styleNoTitle | ParamStyle("OHLC Style",styleBar | styleThick) | GetPriceStyle() );
}
//user want A900/AutoStop plotted
if(parmPlotA900AutoStop == 1)
{
Plot(KPA900, "A900", parmA900Color, parmA900Style);
Plot(KPAutoStop, "AutoStop", parmAutoStopColor, parmAutoStopStyle);
}
// find A900/AutoStop cross over/under with ScoreCard confirmation.
XOUp = (KPA900 > KPAutoStop) AND (KPScoreCard >= parmSCThreshold); // New Pivot Low
XODn = (KPA900 < KPAutoStop) AND (KPScoreCard <= -parmSCThreshold); // New Pivot High
if(parmDebug == 1)
{
printf(WriteIf(XOUp, "before= XOUp: True", "before= XOUp: False") + WriteIf(XODn, " XODn: True\n", " XODn: False\n") );
}
//remove duplicate signals
XOUp = ExRem(XOUp, XODn);
XODn = ExRem(XODn, XOUp);

if(parmDebug == 1)
{
printf(WriteIf(XOUp, "after= XOUp: True", "after= XOUp: False") + WriteIf(XODn, " XODn: True\n", " XODn: False\n") );
}
//find the current Pivot Points - PL and PH
//remember XOUp = 1 means a PL and XODn =1 means a PH
PLBars = IIf(XOUp, LowestSinceBars(XODn, L ,1), 0); //find the bar that produced the Lowest Low
PHBars = IIf(XODn, HighestSinceBars(XOUp, H, 1),0); //find the bar that produced the Highest High
//PLPrice = IIf(XOUp, Ref(L, -PLBars), 0);
//PHPrice = IIf(XODn, Ref(H, -PHBars),0);
PLPrice = Ref(L, -PLBars);
PHPrice = Ref(H, -PHBars);

//keep track of the previous Pivot Points
PrevPLBars = Ref(BarsSince(XOUp), -1) +1;
PrevPHBars = Ref(BarsSince(XODn), -1) +1;
PrevPLPrice = Ref(PLPrice, -prevPLBars);
PrevPHPrice = Ref(PHPrice, -PrevPHBars );
PivotsCloseEnough = TickValue * parmTickMultipler;
PLDifference = MroundP(PLPrice - PRevPLPrice, ticker.TickSize);
PHDifference = MroundP(PHPrice - PrevPHPrice, ticker.TickSize);
PPTrend = IIf(XOUp AND (PLDifference > PivotsCloseEnough) AND PrevPHPrice > PrevPLPrice AND PRevPHPrice > PLPrice, 1,
IIf(XOUp AND (PLDifference < - PivotsCloseEnough) AND PRevPHPrice > PrevPLPrice AND PrevPHPrice > PLPrice, -1,
IIf(XODn AND (PHDifference > PivotsCloseEnough) AND PrevPLPrice < PrevPHprice AND PrevPLPrice < PHPrice, 1,
IIf(XODn AND (PHDifference < -PivotsCloseEnough) AND PrevPLPrice < PrevPHPrice AND PrevPLPrice < PHPrice, -1,
IIf(XOUp AND (abs(PLDifference) <= PivotsCloseEnough) AND PrevPHPrice > PrevPLPrice AND PRevPHPrice > PLPrice, 2,
IIf(XODn AND (abs(PHDifference) <= PivotsCloseEnough) AND PrevPLPrice < PrevPHPrice AND PrevPLPrice < PHPrice, -2, 0)))) ));
if(ParmDebug)
{
printf("Current PH Bar: %g% /Price: %g%\n", PHBars, PHPrice);
printf("Current PL Bar: %g% /Price: %g%\n", PLBars, PLPrice);
printf("Previous PH Bar: %g% /Price: %g%\n", PrevPHBars, PrevPHPrice);
printf("Previous PL Bar: %g% /Price: %g%\n", PrevPLBars, PrevPLPrice) ;
printf("PP Trend: %g%\n", PPTrend);
printf("PHPrice - PrevPHPrice: %g%\nPLPrice - PrevPLPrice: %g%\nPivotsCloseEnough: %g%", PHDifference, PLDifference, PivotsCloseEnough);
}
//PLot pivots as text
dist = parmPPTextOffSet * ATR(10);
//for( i = 0; i < BarCount -1; i++)
for( i = 0; i < BarCount ; i++)
{
if(XOUp[i ] == 1 AND abs(PPTrend[i]) != 2) //cross up -plot the Pivot Low
{
PlotText("PL", i - PLBars[i], PLPrice[i] - dist[i] , parmPPTextColor, IIf(PPTrend[i] == 1, parmPPTrndColorUp, IIf(PPTrend[i] == -1, parmPPTrndColorDn, colorYellow) ));
}
if(XODn[i ] == 1 AND abs(PPTrend[i]) != 2) //cross down - plot the pivot high
{
PlotText("PH", i - PHBars[i], PHPrice[i] + dist[i], parmPPTextColor, IIf(PPTrend[i] == 1, parmPPTrndColorUp, IIf(PPTrend[i] == -1, parmPPTrndColorDn, colorYellow) ));
}
if(XOUp[i ] == 1 AND (PPTrend[i]) == 2) // the Pivot Low is a W Bottom
{
PlotText("PW", i - PLBars[i], PLPrice[i] - dist[i] , parmPPTextColor, colorYellow) ;
}
if(XODn[i ] == 1 AND PPTrend[i] == -2) //cross down - pivot high is a M Top
{
PlotText("PM", i - PHBars[i], PHPrice[i] + dist[i], parmPPTextColor, colorYellow) ;
}
} //end For
_SECTION_END();


This may not be exactly the same what you are looking for but to some extent it can solve the purpose.

You may put Horizontal Lines at the PH & PL points for reference.
 

rvlv

Active Member
#6
Hi traderite

Thank you for the pivot hi-pivot lo code.

The code I am looking for has these unique qualities.
1.it uses higher timeframes based lines or combination of LTF & HTF lines.
2.it joins the resistance -or high pivots that are very close and in a range to form a zone of resistance or support. It looks as a high pivot and nearby lower level high pivot are joined as a zone.

The concept is we observe the first time a zone forms & mrk it,the next time price revisits the zone we act-measurobserve & step2 act .

In fact,a high efficiency supply or Demand zone(like the ones shown on chart posted by me) has a property that price INVARIABLY revisits that zone and we act by buying or selling on this event occurring.
so far to my knowledge, Amibroker doesnt have this kind of zone drawing ability-at least I never saw it anywhere except in MT4. This is where Amibroker is really backward when compared to MT4.

This is what I see.
Once you see my view point,hope you will let me know in case you see any such thing in Amibroker.
 
#7
Hi traderite

Thank you for the pivot hi-pivot lo code.

The code I am looking for has these unique qualities.
1.it uses higher timeframes based lines or combination of LTF & HTF lines.
2.it joins the resistance -or high pivots that are very close and in a range to form a zone of resistance or support. It looks as a high pivot and nearby lower level high pivot are joined as a zone.

The concept is we observe the first time a zone forms & mrk it,the next time price revisits the zone we act-measurobserve & step2 act .

In fact,a high efficiency supply or Demand zone(like the ones shown on chart posted by me) has a property that price INVARIABLY revisits that zone and we act by buying or selling on this event occurring.
so far to my knowledge, Amibroker doesnt have this kind of zone drawing ability-at least I never saw it anywhere except in MT4. This is where Amibroker is really backward when compared to MT4.

This is what I see.
Once you see my view point,hope you will let me know in case you see any such thing in Amibroker.





Try in Daily/Weekly timeframe only

Code:
_SECTION_BEGIN("Price ");

SetBarsRequired(10000,10000); 
GraphXSpace = 3;


SetChartBkColor(ParamColor("Background Colour",colorWhite));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

Chartscale=ParamToggle("Chart Scale","Linear|Logarithmic",0);

if( ChartScale == 0 )
	SetChartOptions(1,chartShowDates);  
else
	SetChartOptions(1,chartShowDates|chartLogarithmic ); 


/////  GFX Functions  ///////


function GetVisibleBarCount()
{
    lvb = Status( "lastvisiblebar" );
    fvb = Status( "firstvisiblebar" );

    return Min( Lvb - fvb, BarCount - fvb );
}
function GfxConvertValueToPixelY( Value )
{
    local Miny, Maxy, pxchartbottom, pxchartheight;

    Miny = Status( "axisminy" );
    Maxy = Status( "axismaxy" );

    pxchartbottom = Status( "pxchartbottom" );
    pxchartheight = Status( "pxchartheight" );

    return pxchartbottom - floor( 0.5+ ( Value - Miny ) * pxchartheight / ( Maxy - Miny ) );
}



function GfxConvertValueToPixelYlog( Value )
{
    local Miny, Maxy, pxchartbottom, pxchartheight;

    pxchartheight = Status( "pxchartheight" );
    pxchartbottom = Status( "pxchartbottom" );

    Miny = Status( "axisminy" );
    Maxy = Status( "axismaxy" );

    x = log( Value / Miny ) / log( Maxy / Miny );
    return pxchartbottom - round( pxchartheight * x);
}



_SECTION_BEGIN( "Support and Resistance" );

// AFL code by Edward Pottasch, Jan 2013
procedure alternate_proc(pk,tr,sumpk,sumtr)
{
global pkg;
global trg;

pkg=pk;trg=tr;
idxpk=0;
idxtr=0;
flgtr=0;
flgpk=0;

for(i=1;i<BarCount;i++)
{
	if(pk[i] AND sumpk[i]==1 AND !tr[i] AND flgpk==0)
	{
		idxpk=i;
		flgtr=0;
	}
	else if( (pk[i] AND sumpk[i]>1 AND !tr[i]) OR (pk[i] AND flgpk==1) )
	{
		if(H[i]>=H[idxpk])
		{
			pkg[idxpk]=0;
			idxpk=i;
			flgpk=0;
		}
		else if(H[i]<H[idxpk])
		{
			pkg[i]=0;
			flgpk=0;
		}
	}
	else if(tr[i] AND sumtr[i]==1 AND !pk[i] AND flgtr==0)
	{
		idxtr=i;
		flgpk=0;
	}
	else if( (tr[i] AND sumtr[i]>1 AND !pk[i]) OR (tr[i] AND flgtr==1) )
	{
		if(L[i]<=L[idxtr])
		{
			trg[idxtr]=0;
			idxtr=i;
			flgtr=0;
		}
		else if(L[i]>L[idxtr])
		{
			trg[i]=0;
			flgtr=0;
		}
	}
	else if(pk[i] AND tr[i])
	{
		if(sumpk[i-1]>sumtr[i-1])
		{
			pkg[i]=0;
			flgtr=1;
			idxtr=i;
		}
		else if(sumtr[i-1]>sumpk[i-1])
		{
			trg[i]=0;
			flgpk=1;
			idxpk=i;
		}
	}
}
}
procedure calculatePivots(tfrm,PivotSymmetry,nbar,CleanPivots,x)
{
TimeFrameSet(tfrm);

global tr;global pk;global px0;global px1;global px2;global ph0;global ph1;global ph2;
global trl;global pkh;global tx0;global tx1;global tx2;global tl0;global tl1;global tl2;
global fact;
if(PivotSymmetry)
{
	fc=1;
	pk=H>Ref(HHV(H,nbar*fc),-1) AND Ref(HHV(H,nbar),nbar)<=H;
	tr=L<Ref(LLV(L,nbar*fc),-1) AND Ref(LLV(L,nbar),nbar)>=L;
}
else
{
	fc=2;
	pk=H>Ref(HHV(H,nbar*fc),-1) AND Ref(HHV(H,nbar),nbar)<=H;
	tr=L<Ref(LLV(L,nbar*fc),-1) AND Ref(LLV(L,nbar),nbar)>=L;
}

px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);

sumpk=Sum(pk,BarsSince(tr));sumtr=Sum(tr,BarsSince(pk));
if(CleanPivots)
{
	alternate_proc(pk,tr,sumpk,sumtr);
	pk=pkg;
	tr=trg;
	
	px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
	px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
	px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
	px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);	
	ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
	ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
	ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);
	ph3=ValueWhen(pk,H,3); tl3=ValueWhen(tr,L,3);	
}
pkh=IIf(pk,H,Null);
trl=IIf(tr,L,Null);
TimeFrameRestore();
fact=Nz(Max(tfrm/60,Interval()/60)/(Interval()/60));
if(fact==0)fact=1;
Lkbk=Nz(tfrm/Interval());
if(Lkbk>1)
{
	pk=TimeFrameExpand(pk,tfrm,expandFirst);
	pkh=TimeFrameExpand(pkh,tfrm,expandFirst);
	pkhs=IIf(!IsEmpty(pkh),1,0);pkhs=pkhs-Ref(pkhs,-1);
	pk=pk AND H==pkh;
	cond1=Sum(pk,BarsSince(pkhs==1)+1)==1 AND pk;
	pk=pk AND cond1;
	
	tr=TimeFrameExpand(tr,tfrm,expandFirst);	
	trl=TimeFrameExpand(trl,tfrm,expandFirst);
	trls=IIf(!IsEmpty(trl),1,0);trls=trls-Ref(trls,-1);
	tr=tr AND L==trl;
	cond1=Sum(tr,BarsSince(trls==1)+1)==1 AND tr;
	tr=tr AND cond1;
	
	px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
	px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
	px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
	px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);
	ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
	ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
	ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);
	ph3=ValueWhen(pk,H,3); tl3=ValueWhen(tr,L,3);
}
}




function displayLines(pk,tr,lnColorRes,lnColorSup,lnWidthRes,lnWidthSup)
{

pxchartright=Status("pxchartright"); 
AllVisibleBars=GetVisibleBarCount();

for(i=0;i<BarCount;i++) 
{
	DisplayRes=1;
	DisplaySup=1;
	if(pk[i])
	{
	
		
			hval=H[i];
			for(j=i;j<BarCount;j++)
			{
				if(H[j]>hval)
				{
					DisplayRes=0;
					break;
				}
			}
		
		if(DisplayRes)
		{
			x0=i;
                  y0=H[i];
                  x1=BarCount;
                  y1=H[i];
			Plot(LineArray(x0,y0,x1,y1,1),"",lnColorRes,styleLine|styleNoRescale|styleNoLabel,0,0,0,0,lnWidthRes); 	

                  if(Chartscale==0) YPos=GfxConvertValueToPixelY(y1);
                  else  YPos=GfxConvertValueToPixelYLog(y1); 
                 
                  GfxSetTextAlign(0);
                  GfxSetBkColor(colorWhite);
                  GfxSelectFont("Tahoma",8,650);
                  YValue = StrRight( NumToStr( y1, 4.3,0 ), 9 );
                  GfxSetTextColor(colorLightGrey);
			//GfxTextOut(""+YValue,pxchartright-60,YPos-12);
                  RequestTimedRefresh( 0.1 );     
          
		}
	}
	if(tr[i])
	{
		
		
			lval=L[i];
			for(j=i;j<BarCount;j++)
			{
				if(L[j]<lval)
				{
					DisplaySup=0;
					break;
				}
			}
			
		if(DisplaySup)
		{	
			x0=i;
                  y0=L[i];
                  x1=BarCount;
                  y1=L[i];
			Plot(LineArray(x0,y0,x1,y1,1),"",lnColorSup,styleLine|styleNoRescale|styleNoLabel,0,0,0,0,lnWidthSup);	

                  if(Chartscale==0) YPos=GfxConvertValueToPixelY(y1);
                  else  YPos=GfxConvertValueToPixelYLog(y1); 
                  
                  GfxSetTextAlign(0);
                  GfxSetBkColor(colorWhite);
                  GfxSelectFont("Tahoma",8,650);
                  YValue = StrRight( NumToStr( y1, 4.3,0 ), 9 );
                  GfxSetTextColor(colorLightGrey);
			//GfxTextOut(""+YValue,pxchartright-60,YPos-12);
                  RequestTimedRefresh( 0.1 );                

	
		}
	}	
}
}


xx=BarIndex();
x=xx;
Lx=LastValue(x);

nbar=Param("N Pivot Bars",2,2,50,1); 
CleanPivots=ParamToggle("Use Clean Pivots","Off|On",0);
PivotSymmetry=ParamToggle("Use Symmetric Pivots","Off|On",1);

WeeklyTF=(Nz(StaticVarGet("ToggleButtonON_104")));  
weeklyLineColorRes=ParamColor("WEEKLY Line Color (resistance)",colorLightGrey); 
weeklyLineColorSup=ParamColor("WEEKLY Line Color (support)",colorLightGrey);
weeklyLineWidth=Param("WEEKLY Line Width",1,1,10,1);

// setup for weekly

calculatePivots(inWeekly,PivotSymmetry,nbar,CleanPivots,x);
displayLines(pk,tr,weeklyLineColorRes,weeklyLineColorSup,weeklyLineWidth,weeklyLineWidth);

_SECTION_END();
 
#8
Try in Daily/Weekly timeframe only

Code:
_SECTION_BEGIN("Price ");

SetBarsRequired(10000,10000); 
GraphXSpace = 3;


SetChartBkColor(ParamColor("Background Colour",colorWhite));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

Chartscale=ParamToggle("Chart Scale","Linear|Logarithmic",0);

if( ChartScale == 0 )
	SetChartOptions(1,chartShowDates);  
else
	SetChartOptions(1,chartShowDates|chartLogarithmic ); 


/////  GFX Functions  ///////


function GetVisibleBarCount()
{
    lvb = Status( "lastvisiblebar" );
    fvb = Status( "firstvisiblebar" );

    return Min( Lvb - fvb, BarCount - fvb );
}
function GfxConvertValueToPixelY( Value )
{
    local Miny, Maxy, pxchartbottom, pxchartheight;

    Miny = Status( "axisminy" );
    Maxy = Status( "axismaxy" );

    pxchartbottom = Status( "pxchartbottom" );
    pxchartheight = Status( "pxchartheight" );

    return pxchartbottom - floor( 0.5+ ( Value - Miny ) * pxchartheight / ( Maxy - Miny ) );
}



function GfxConvertValueToPixelYlog( Value )
{
    local Miny, Maxy, pxchartbottom, pxchartheight;

    pxchartheight = Status( "pxchartheight" );
    pxchartbottom = Status( "pxchartbottom" );

    Miny = Status( "axisminy" );
    Maxy = Status( "axismaxy" );

    x = log( Value / Miny ) / log( Maxy / Miny );
    return pxchartbottom - round( pxchartheight * x);
}



_SECTION_BEGIN( "Support and Resistance" );

// AFL code by Edward Pottasch, Jan 2013
procedure alternate_proc(pk,tr,sumpk,sumtr)
{
global pkg;
global trg;

pkg=pk;trg=tr;
idxpk=0;
idxtr=0;
flgtr=0;
flgpk=0;

for(i=1;i<BarCount;i++)
{
	if(pk[i] AND sumpk[i]==1 AND !tr[i] AND flgpk==0)
	{
		idxpk=i;
		flgtr=0;
	}
	else if( (pk[i] AND sumpk[i]>1 AND !tr[i]) OR (pk[i] AND flgpk==1) )
	{
		if(H[i]>=H[idxpk])
		{
			pkg[idxpk]=0;
			idxpk=i;
			flgpk=0;
		}
		else if(H[i]<H[idxpk])
		{
			pkg[i]=0;
			flgpk=0;
		}
	}
	else if(tr[i] AND sumtr[i]==1 AND !pk[i] AND flgtr==0)
	{
		idxtr=i;
		flgpk=0;
	}
	else if( (tr[i] AND sumtr[i]>1 AND !pk[i]) OR (tr[i] AND flgtr==1) )
	{
		if(L[i]<=L[idxtr])
		{
			trg[idxtr]=0;
			idxtr=i;
			flgtr=0;
		}
		else if(L[i]>L[idxtr])
		{
			trg[i]=0;
			flgtr=0;
		}
	}
	else if(pk[i] AND tr[i])
	{
		if(sumpk[i-1]>sumtr[i-1])
		{
			pkg[i]=0;
			flgtr=1;
			idxtr=i;
		}
		else if(sumtr[i-1]>sumpk[i-1])
		{
			trg[i]=0;
			flgpk=1;
			idxpk=i;
		}
	}
}
}
procedure calculatePivots(tfrm,PivotSymmetry,nbar,CleanPivots,x)
{
TimeFrameSet(tfrm);

global tr;global pk;global px0;global px1;global px2;global ph0;global ph1;global ph2;
global trl;global pkh;global tx0;global tx1;global tx2;global tl0;global tl1;global tl2;
global fact;
if(PivotSymmetry)
{
	fc=1;
	pk=H>Ref(HHV(H,nbar*fc),-1) AND Ref(HHV(H,nbar),nbar)<=H;
	tr=L<Ref(LLV(L,nbar*fc),-1) AND Ref(LLV(L,nbar),nbar)>=L;
}
else
{
	fc=2;
	pk=H>Ref(HHV(H,nbar*fc),-1) AND Ref(HHV(H,nbar),nbar)<=H;
	tr=L<Ref(LLV(L,nbar*fc),-1) AND Ref(LLV(L,nbar),nbar)>=L;
}

px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);

sumpk=Sum(pk,BarsSince(tr));sumtr=Sum(tr,BarsSince(pk));
if(CleanPivots)
{
	alternate_proc(pk,tr,sumpk,sumtr);
	pk=pkg;
	tr=trg;
	
	px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
	px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
	px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
	px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);	
	ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
	ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
	ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);
	ph3=ValueWhen(pk,H,3); tl3=ValueWhen(tr,L,3);	
}
pkh=IIf(pk,H,Null);
trl=IIf(tr,L,Null);
TimeFrameRestore();
fact=Nz(Max(tfrm/60,Interval()/60)/(Interval()/60));
if(fact==0)fact=1;
Lkbk=Nz(tfrm/Interval());
if(Lkbk>1)
{
	pk=TimeFrameExpand(pk,tfrm,expandFirst);
	pkh=TimeFrameExpand(pkh,tfrm,expandFirst);
	pkhs=IIf(!IsEmpty(pkh),1,0);pkhs=pkhs-Ref(pkhs,-1);
	pk=pk AND H==pkh;
	cond1=Sum(pk,BarsSince(pkhs==1)+1)==1 AND pk;
	pk=pk AND cond1;
	
	tr=TimeFrameExpand(tr,tfrm,expandFirst);	
	trl=TimeFrameExpand(trl,tfrm,expandFirst);
	trls=IIf(!IsEmpty(trl),1,0);trls=trls-Ref(trls,-1);
	tr=tr AND L==trl;
	cond1=Sum(tr,BarsSince(trls==1)+1)==1 AND tr;
	tr=tr AND cond1;
	
	px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
	px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
	px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
	px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);
	ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
	ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
	ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);
	ph3=ValueWhen(pk,H,3); tl3=ValueWhen(tr,L,3);
}
}




function displayLines(pk,tr,lnColorRes,lnColorSup,lnWidthRes,lnWidthSup)
{

pxchartright=Status("pxchartright"); 
AllVisibleBars=GetVisibleBarCount();

for(i=0;i<BarCount;i++) 
{
	DisplayRes=1;
	DisplaySup=1;
	if(pk[i])
	{
	
		
			hval=H[i];
			for(j=i;j<BarCount;j++)
			{
				if(H[j]>hval)
				{
					DisplayRes=0;
					break;
				}
			}
		
		if(DisplayRes)
		{
			x0=i;
                  y0=H[i];
                  x1=BarCount;
                  y1=H[i];
			Plot(LineArray(x0,y0,x1,y1,1),"",lnColorRes,styleLine|styleNoRescale|styleNoLabel,0,0,0,0,lnWidthRes); 	

                  if(Chartscale==0) YPos=GfxConvertValueToPixelY(y1);
                  else  YPos=GfxConvertValueToPixelYLog(y1); 
                 
                  GfxSetTextAlign(0);
                  GfxSetBkColor(colorWhite);
                  GfxSelectFont("Tahoma",8,650);
                  YValue = StrRight( NumToStr( y1, 4.3,0 ), 9 );
                  GfxSetTextColor(colorLightGrey);
			//GfxTextOut(""+YValue,pxchartright-60,YPos-12);
                  RequestTimedRefresh( 0.1 );     
          
		}
	}
	if(tr[i])
	{
		
		
			lval=L[i];
			for(j=i;j<BarCount;j++)
			{
				if(L[j]<lval)
				{
					DisplaySup=0;
					break;
				}
			}
			
		if(DisplaySup)
		{	
			x0=i;
                  y0=L[i];
                  x1=BarCount;
                  y1=L[i];
			Plot(LineArray(x0,y0,x1,y1,1),"",lnColorSup,styleLine|styleNoRescale|styleNoLabel,0,0,0,0,lnWidthSup);	

                  if(Chartscale==0) YPos=GfxConvertValueToPixelY(y1);
                  else  YPos=GfxConvertValueToPixelYLog(y1); 
                  
                  GfxSetTextAlign(0);
                  GfxSetBkColor(colorWhite);
                  GfxSelectFont("Tahoma",8,650);
                  YValue = StrRight( NumToStr( y1, 4.3,0 ), 9 );
                  GfxSetTextColor(colorLightGrey);
			//GfxTextOut(""+YValue,pxchartright-60,YPos-12);
                  RequestTimedRefresh( 0.1 );                

	
		}
	}	
}
}


xx=BarIndex();
x=xx;
Lx=LastValue(x);

nbar=Param("N Pivot Bars",2,2,50,1); 
CleanPivots=ParamToggle("Use Clean Pivots","Off|On",0);
PivotSymmetry=ParamToggle("Use Symmetric Pivots","Off|On",1);

WeeklyTF=(Nz(StaticVarGet("ToggleButtonON_104")));  
weeklyLineColorRes=ParamColor("WEEKLY Line Color (resistance)",colorLightGrey); 
weeklyLineColorSup=ParamColor("WEEKLY Line Color (support)",colorLightGrey);
weeklyLineWidth=Param("WEEKLY Line Width",1,1,10,1);

// setup for weekly

calculatePivots(inWeekly,PivotSymmetry,nbar,CleanPivots,x);
displayLines(pk,tr,weeklyLineColorRes,weeklyLineColorSup,weeklyLineWidth,weeklyLineWidth);

_SECTION_END();
pls keep the option for daily/weekly time frame in the code
 

hitesh

Active Member
#9
The following AFL should be helpful.


_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
GraphXSpace=10;

_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorLavender ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram ), 2 );
_SECTION_END();

/////////////////////// Support Resistance of Minitrader /////////////////
_SECTION_BEGIN("Resistance");

HaClose =EMA((O+H+L+C)/4,3);
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
Temp = Max(High, HaOpen);
Temp = Min(Low,HaOpen);


SetChartBkColor(ParamColor("Panel color ",colorWhite));
Plot(C,"",colorBlack,styleCandle);

Prd1=Param("Res_Period1",2,0,200,1);

test = TEMA ( High , Prd1 ) ;

PK = test > Ref(test,-1) AND Ref(test,1) < High;//Peak
PKV0 = ValueWhen(PK,haHigh,0);//PeakValue0
PKV1 = ValueWhen(PK,haHigh,1);//PeakValue1
PKV2 = ValueWhen(PK,haHigh,2);//PeakValue2

MPK = PKV2 < PKV1 AND PKV1 > PKV0 ;//MajorPeak

MPKV = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,1); //MajorPeakValue
MPKD = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),1); //MajorPeakDate
SD = IIf(DateNum() < LastValue(MPKD,lastmode = True ), Null, LastValue(MPKV,Lastmode = True));//SelectedDate
Plot(SD, "Resist1", colorGreen,ParamStyle("ResStyle1",styleLine|styleNoTitle,maskAll));

MPKV2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,2); //MajorPeakValue
MPKD2 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),2); //MajorPeakDate
SD2 = IIf(DateNum() < LastValue(MPKD2,lastmode = True ), Null, LastValue(MPKV2,Lastmode = True));//SelectedDate
Plot(SD2, "Resist2", colorGreen,ParamStyle("ResStyle2",styleLine|styleNoTitle,maskAll));


MPKV3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,3); //MajorPeakValue
MPKD3 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),3); //MajorPeakDate
SD3 = IIf(DateNum() < LastValue(MPKD3,lastmode = True ), Null, LastValue(MPKV3,Lastmode = True));//SelectedDate
Plot(SD3, "Resist3", colorGreen,ParamStyle("ResStyle3",styleLine|styleNoTitle,maskAll));


MPKV4 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,4); //MajorPeakValue
MPKD4 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),4); //MajorPeakDate
SD4 = IIf(DateNum() < LastValue(MPKD4,lastmode = True ), Null, LastValue(MPKV4,Lastmode = True));//SelectedDate
Plot(SD4, "Resist4", colorGreen,ParamStyle("ResStyle4",styleLine|styleNoTitle,maskAll));



MPKV5 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,5); //MajorPeakValue
MPKD5 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),5); //MajorPeakDate
SD5 = IIf(DateNum() < LastValue(MPKD5,lastmode = True ), Null, LastValue(MPKV5,Lastmode = True));//SelectedDate
Plot(SD5, "Resist5", colorGreen,ParamStyle("ResStyle5",styleLine|styleNoTitle,maskAll));


MPKV6 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, PKV1,6); //MajorPeakValue
MPKD6 = ValueWhen(Ref(MPK,-1) == 0 AND MPK == 1, DateNum(),6); //MajorPeakDate
SD6 = IIf(DateNum() < LastValue(MPKD6,lastmode = True ), Null, LastValue(MPKV6,Lastmode = True));//SelectedDate
Plot(SD6, "Resist6", colorGreen ,ParamStyle("ResStyle6",styleLine|styleNoTitle,maskAll));




_SECTION_END();

HaClose =EMA((O+H+L+C)/4,3);
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 );
HaHigh = Max( H, Max( HaClose, HaOpen ) );
HaLow = Min( L, Min( HaClose, HaOpen ) );
Temp = Max(High, HaOpen);
Temp = Min(Low,HaOpen);

_SECTION_BEGIN("Support");
//SP=L > Ref(L,-1) AND Ref(L,1) < L;//Peak

Prd2=Param("Sup_Period1",2,0,200,1);

test2 = TEMA ( Low , Prd2 ) ;

SP = Ref(test2,1) > Low AND test2 < Ref(test2,-1);//Peak
SPV0 = ValueWhen(SP,haLow,0);//PeakValue0
SPV1 = ValueWhen(SP,haLow,1);//PeakValue1
SPV2 = ValueWhen(SP,haLow,2);//PeakValue2

//PKV5 = ValueWhen(PK,haHigh,5);//PeakValue5
//PKV6 = ValueWhen(PK,haHigh,6);//PeakValue6

MSP = SPV2 > SPV1 AND SPV1 < SPV0 ;//MajorPeak

MSPV = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,1);
MSPD = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),1);
SD = IIf(DateNum() < LastValue(MSPD,lastmode = True ), Null, LastValue(MSPV,Lastmode = True));
Plot(SD,"Support1", colorBrown,ParamStyle("SupportLine1",styleLine|styleNoTitle,maskAll));



MSPV2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,2);
MSPD2 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),2);
SD2 = IIf(DateNum() < LastValue(MSPD2,lastmode = True ), Null, LastValue(MSPV2,Lastmode = True));
Plot(SD2,"Support2", colorBrown,ParamStyle("SupportLine2",styleLine|styleNoTitle,maskAll));



MSPV3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,3);
MSPD3 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),3);
SD3 = IIf(DateNum() < LastValue(MSPD3,lastmode = True ), Null, LastValue(MSPV3,Lastmode = True));
Plot(SD3,"Support3", colorBrown,ParamStyle("SupportLine3",styleLine|styleNoTitle,maskAll));


MSPV4 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,4);
MSPD4 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),4);
SD4 = IIf(DateNum() < LastValue(MSPD4,lastmode = True ), Null, LastValue(MSPV4,Lastmode = True));
Plot(SD4,"Support4", colorBrown,ParamStyle("SupportLine4",styleLine|styleNoTitle,maskAll));


MSPV5 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,5);
MSPD5 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),5);
SD5 = IIf(DateNum() < LastValue(MSPD5,lastmode = True ), Null, LastValue(MSPV5,Lastmode = True));
Plot(SD5,"Support5", colorBrown,ParamStyle("SupportLine5",styleLine|styleNoTitle,maskAll));


MSPV6 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, SPV1,6);
MSPD6 = ValueWhen(Ref(MSP,-1) == 0 AND MSP == 1, DateNum(),6);
SD6 = IIf(DateNum() < LastValue(MSPD6,lastmode = True ), Null, LastValue(MSPV6,Lastmode = True));
Plot(SD6,"Support6", colorBrown,ParamStyle("SupportLine6",styleLine|stylehidden|styleNoTitle,maskAll));
 

rvlv

Active Member
#10
Hi Friend Hitesh

Thank you for this code that is near by my objective.
Let me try and comeback with my views.

I am actually looking for somebody to post the concept and the way it got coded in MT4 .
Here is a chart and the way I look at it.



regards
rvlv
 

Similar threads