Experts: Safe Trend Scalp - page 7

 
LONNV #: you open the light for me.thanks. Can use this style of calculation in both positive and negative slope? because trendline frequently change from positive to negative slope vise versa.

Yes, obviously! It does not matter the slope as long as you clearly define the values for First and Last point.

Here is an example:

Given:

Price at Index 11 is 100 (12th bar)
Price at Index 1 is 105 (2nd bar)

Therefore:

m = Δy / Δx = (100 - 105) / ( 11 - 1 ) = -5 / 10 = -0.5

c = y - m * x = 100 - m * 11 = 105 - m * 1 = 105.5

Equation:

y = -0.5 * x + 105.5

[price] = -0.5 * [index] + 105.5

Example:

What is trend-line price at bar index 5?

[price @ 5] = -0.5 * 5 + 105.5 = 103

 
Fernando Carreiro #:

Yes, obviously! It does not matter the slope as long as you clearly define the values for First and Last point.

Here is an example:

Given:

Price at Index 11 is 100 (12th bar)
Price at Index 1 is 105 (2nd bar)

Therefore:

m = Δy / Δx = (100 - 105) / ( 11 - 1 ) = -5 / 10 = -0.5

c = y - m * x = 100 - m * 11 = 105 - m * 1 = 105.5

Equation:

y = -0.5 * x + 105.5

[price] = -0.5 * [index] + 105.5

Example:

What is trend-line price at bar index 5?

[price @ 5] = -0.5 * 5 + 105.5 = 103

when I apply in this EA code

 DrawLine = true;
 First_Low_Candel=LLastBar;  Secund_Low_Candel=Lbar;
 First_High_Candel=HLastBar; Secund_High_Candel=Hbar;
 MODE = "none";
   
 if ( (highcount > 2) && (DrawLine == true))
 {
 
double mNumerator   = ZigZagHigh[Secund_High_Candel] - ZigZagHigh[First_High_Candel];
double mDenominator = Secund_High_Candel-First_High_Candel; 

double m            = mNumerator / mDenominator;

double b            = ZigZagHigh[Secund_High_Candel] - m  *  Secund_High_Candel;  

int x               = First_High_Candel;  
 
   gl_LineValHigh  = (m * x) + b;
 
  
   
   ObjectDelete("FXNODE.HighLine");
 
   ObjectCreate("FXNODE.HighLine", OBJ_TREND, 0, Time[ZigHCandel[Secund_High_Candel]],ZigZagHigh[Secund_High_Candel],Time[ZigHCandel[First_High_Candel]],ZigZagHigh[First_High_Candel]);
   ObjectSet   ("FXNODE.HighLine", OBJPROP_COLOR, Color_UPLine);
   ObjectSet   ("FXNODE.HighLine", OBJPROP_STYLE, STYLE_DASH);
   ObjectSet   ("FXNODE.HighLine", OBJPROP_WIDTH, 1);
   ObjectSet   ("FXNODE.HighLine", OBJPROP_RAY,   true);
   ObjectSet   ("FXNODE.HighLine", OBJPROP_BACK,  true);
 }
 if ( (lowcount > 2) && (DrawLine == true))
 {
 

double mNumerator   = ZigZagLow[Secund_Low_Candel] - ZigZagLow[First_Low_Candel];
double mDenominator = Secund_Low_Candel-First_Low_Candel; 

double m            = mNumerator / mDenominator;

double b            = ZigZagLow[Secund_Low_Candel] - m  *  Secund_Low_Candel;  

int x               = First_Low_Candel;  // This value should be a candle index. In a trendline, it would be the candle index of OBJPROP_TIME1
 
   gl_LineValLow  = (m * x) + b;
   
   

  
   ObjectDelete("FXNODE.LowLine");
 
   ObjectCreate("FXNODE.LowLine", OBJ_TREND, 0, Time[ZigLCandel[Secund_Low_Candel]],ZigZagLow[Secund_Low_Candel],Time[ZigLCandel[First_Low_Candel]],ZigZagLow[First_Low_Candel]);
   ObjectSet   ("FXNODE.LowLine", OBJPROP_COLOR, Color_DWLine);
   ObjectSet   ("FXNODE.LowLine", OBJPROP_STYLE, STYLE_DASH);
   ObjectSet   ("FXNODE.LowLine", OBJPROP_WIDTH, 1);
   ObjectSet   ("FXNODE.LowLine", OBJPROP_RAY,   true);
   ObjectSet   ("FXNODE.LowLine", OBJPROP_BACK,  true);
 }
 
 
 
}

I not take time value , use index value ,

when compare trendline object values and formula value .

there is a little variation, is it normal?


or am I still missing some ?

 
LONNV #: when I apply in this EA code I not take time value , use index value, when compare trendline object values and formula value. there is a little variation, is it normal? or am I still missing some ?

Your code is incomplete. We are not able to test it. You are not showing the rest of it and how you are printing your values. Provide sample code that can actually be compiled and tested.

Also, I'm unsure because we cannot see the rest of the code, but maybe you meant this?

ObjectCreate("FXNODE.HighLine", OBJ_TREND, 0, Time[Secund_High_Candel],ZigZagHigh[Secund_High_Candel],Time[First_High_Candel],ZigZagHigh[First_High_Candel]);
 
Fernando Carreiro #:

Your code is incomplete. We are not able to test it. You are not showing the rest of it and how you are printing your values. Provide sample code that can actually be compiled and tested.

Also, I'm unsure because we cannot see the rest of the code, but maybe you meant this?

here is complete codes

void TrendLine()
  {
   ArrayResize(ZigZagHigh,ZigZagNum,1);
   ArrayResize(ZigZagLow,ZigZagNum,1);
   ArrayResize(ZigHCandel,ZigZagNum,1);
   ArrayResize(ZigLCandel,ZigZagNum,1);
   double high = -1, low = -1;
   double data=0;
   int    lowcount = 0, highcount = 0;

   for(int i = 0; i < 200; i++)
     {
      high = iCustom(Symbol(),TimeFrame, "ZigZag", InpDepth,InpDeviation,InpBackstep, 1, i);
      if((high > 0) && (high == iCustom(Symbol(),TimeFrame, "ZigZag", InpDepth,InpDeviation,InpBackstep, 0, i)))
        {
         ZigZagHigh[highcount] = high;
         ZigHCandel[highcount] = i;
         highcount++;
        }
      high = -1;
      if(highcount == ZigZagNum)
         break;
     }

  
  
   for(int i = 0; i < 200; i++)
     {
      low = iCustom(Symbol(),TimeFrame, "ZigZag", InpDepth,InpDeviation,InpBackstep, 2, i);
      if((low > 0) && (low == iCustom(Symbol(),TimeFrame, "ZigZag", InpDepth,InpDeviation,InpBackstep, 0, i)))
        {
         ZigZagLow[lowcount] = low;
         ZigLCandel[lowcount] = i;
         lowcount++;
        }
      low = -1;
      if(lowcount == ZigZagNum)
         break;
     }


   if (drawarrow == true)
   {
   for(int j = 0; j <= ZigZagNum-1; j++)
     {
      if(ObjectFind(0,"FXNODE.ZigZagHigh") < 0)
        {
         ObjectDelete("FXNODE.ZigZagHigh."+IntegerToString(j));
         ObjectCreate(0,"FXNODE.ZigZagHigh."+IntegerToString(j),OBJ_ARROW,0,0,0,0,0);          // Create an arrow
         ObjectSetInteger(0,"FXNODE.ZigZagHigh."+IntegerToString(j),OBJPROP_ARROWCODE,238);    // Set the arrow code
         ObjectSetInteger(0,"FXNODE.ZigZagHigh."+IntegerToString(j),OBJPROP_COLOR,clrCrimson);
        }
      ObjectSetInteger(0,"FXNODE.ZigZagHigh."+IntegerToString(j),OBJPROP_TIME,Time[ZigHCandel[j]]);        // Set time
      ObjectSetDouble(0,"FXNODE.ZigZagHigh."+IntegerToString(j),OBJPROP_PRICE,ZigZagHigh[j]+(10+(Period()/100))*Point);// Set price
     }

   for(int j = 0; j <= ZigZagNum-1; j++)
     {
      if(ObjectFind(0,"FXNODE.ZigZagLow") < 0)
        {
         ObjectDelete("FXNODE.ZigZagLow."+IntegerToString(j));
         ObjectCreate(0,"FXNODE.ZigZagLow."+IntegerToString(j),OBJ_ARROW,0,0,0,0,0);          // Create an arrow
         ObjectSetInteger(0,"FXNODE.ZigZagLow."+IntegerToString(j),OBJPROP_ARROWCODE,236);    // Set the arrow code
         ObjectSetInteger(0,"FXNODE.ZigZagLow."+IntegerToString(j),OBJPROP_COLOR,clrOliveDrab);
        }
      ObjectSetInteger(0,"FXNODE.ZigZagLow."+IntegerToString(j),OBJPROP_TIME,Time[ZigLCandel[j]]);        // Set time
      ObjectSetDouble(0,"FXNODE.ZigZagLow."+IntegerToString(j),OBJPROP_PRICE,ZigZagLow[j]-(10+(Period()/250))*Point);// Set price
     }
   }
  
   DrawTrend = true;
   First_Low_Candel=0;
   Secund_Low_Candel=3;
   First_High_Candel=0;
   Secund_High_Candel=3;
   MODE = "none";


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

   if((highcount > 2) && (DrawTrend == true))
     {

double mNumerator   = ZigZagHigh[Secund_High_Candel] - ZigZagHigh[First_High_Candel];
double mDenominator = Secund_High_Candel-First_High_Candel; 

double m            = mNumerator / mDenominator;

double b            = ZigZagHigh[Secund_High_Candel] - m  *  Secund_High_Candel;  

int x               = First_High_Candel;  
 
   gl_LineValHigh  = (m * x) + b;
 
      //DrawLine("FXNODE.HighLine",Time[ZigHCandel[Secund_High_Candel]],ZigZagHigh[Secund_High_Candel],Time[ZigHCandel[First_High_Candel]],ZigZagHigh[First_High_Candel],clrBlack,1);
      ObjectDelete("FXNODE.HighLine");
      ObjectCreate("FXNODE.HighLine", OBJ_TREND, 0, Time[ZigHCandel[Secund_High_Candel]],ZigZagHigh[Secund_High_Candel],Time[ZigHCandel[First_High_Candel]],ZigZagHigh[First_High_Candel]);
      ObjectSet("FXNODE.HighLine", OBJPROP_COLOR, clrChocolate);
      ObjectSet("FXNODE.HighLine", OBJPROP_STYLE, STYLE_DASH);
      ObjectSetInteger(0, "FXNODE.HighLine", OBJPROP_HIDDEN,false);
     }
   if((lowcount > 2) && (DrawTrend == true))
     {

double mNumerator   = ZigZagLow[Secund_Low_Candel] - ZigZagLow[First_Low_Candel];
double mDenominator = Secund_Low_Candel-First_Low_Candel; 

double m            = mNumerator / mDenominator;

double b            = ZigZagLow[Secund_Low_Candel] - m  *  Secund_Low_Candel;  

int x               = First_Low_Candel;  // This value should be a candle index. In a trendline, it would be the candle index of OBJPROP_TIME1
 
   gl_LineValLow  = (m * x) + b;
   
   
      //DrawLine("FXNODE.LowLine",Time[ZigLCandel[Secund_Low_Candel]],ZigZagLow[Secund_Low_Candel],Time[ZigLCandel[First_Low_Candel]],ZigZagLow[First_Low_Candel],clrBlack,1);
      ObjectDelete("FXNODE.LowLine");
      ObjectCreate("FXNODE.LowLine", OBJ_TREND, 0, Time[ZigLCandel[Secund_Low_Candel]],ZigZagLow[Secund_Low_Candel],Time[ZigLCandel[First_Low_Candel]],ZigZagLow[First_Low_Candel]);
      ObjectSet("FXNODE.LowLine", OBJPROP_COLOR, clrSpringGreen);
      ObjectSet("FXNODE.LowLine", OBJPROP_STYLE, STYLE_DASH);
      ObjectSet("FXNODE.LowLine", OBJPROP_WIDTH, 1);
      ObjectSetInteger(0, "FXNODE.LowLine", OBJPROP_HIDDEN,false);
     }
  }

gl_LineValLow  and gl_LineValHigh are global variables.

here I called trendline values by

void signal(){


  double LineValHigh = NormalizeDouble(ObjectGetValueByShift("FXNODE.HighLine", 0),Digits );
  double LineValLow   = NormalizeDouble(ObjectGetValueByShift("FXNODE.LowLine", 0),Digits );

  double     LineValHighz = NormalizeDouble(gl_LineValHigh,Digits);
  double    LineValLowz = NormalizeDouble(gl_LineValLow,Digits); 
      
  Print("value low "+LineValLow+"");
  Print("formula low " + LineValLowz+"");
  
  Print("value high "+LineValHigh+"");
  Print("formula high" + LineValHighz+"");
     
  
}

I printed these two values ,


a little variation occurs,


Please check if I wrong.

thanks you

 
LONNV #: here is complete codes gl_LineValLow  and gl_LineValHigh are global variables. here I called trendline values by I printed these two values , a little variation occurs, Please check if I wrong. thanks you

How to do expect to get equivalent results when you are using different shifts for the two methods?

int x = First_High_Candel;  
gl_LineValHigh = (m * x) + b;
...
ObjectGetValueByShift("FXNODE.HighLine", 0)
...
 
Fernando Carreiro #:

How to do expect to get equivalent results when you are using different shifts for the two methods?

thanks but 

First_High_Candel
value is also zero
 
LONNV #:thanks but value is also zero

You are confusing the array index with a bar shift. They are not the same thing.

int x = ZigHCandel[ First_High_Candel ];
gl_LineValHigh = (m * x) + b;
...
ObjectGetValueByShift("FXNODE.HighLine", ZigHCandel[ First_High_Candel ])
...
 
Fernando Carreiro #:

You are confusing the array index with a bar shift. They are not the same thing.

how can get this array index in this place

ObjectGetValueByShift("FXNODE.HighLine", ZigHCandel[ First_High_Candel ])

this array index is in external function ,

can you show more clearly .

ObjectGetValueByShift take trendline value from current index ,

if so how can design in formula.

double mNumerator   = ZigZagLow[Secund_Low_Candel] - ZigZagLow[First_Low_Candel];
double mDenominator = Secund_Low_Candel-First_Low_Candel; 

double m            = mNumerator / mDenominator;

double b            = ZigZagLow[Secund_Low_Candel] - m  *  Secund_Low_Candel;  

int x               = First_Low_Candel;  // This value should be a candle index. In a trendline, it would be the candle index of OBJPROP_TIME1
 
   gl_LineValLow  = (m * x) + b;

Shift is bar index , if not array index value not same , mDenominator also wrong , it use only index value.

and also b value wrong , it use only index value.

and x value also wrong.

So how replace with array index value ?

it cannot be possible

ObjectGetValueByShift("FXNODE.HighLine", ZigHCandel[ First_High_Candel ])

ZigHCandel is not global variable , cannot replace in this place.


Please help  how should be

 
LONNV #: how can get this array index in this place. this array index is in external function, can you show more clearly. ObjectGetValueByShift take trendline value from current index, if so how can design in formula.

Shift is bar index , if not array index value not same , mDenominator also wrong , it use only index value. and also b value wrong , it use only index value. and x value also wrong. So how replace with array index value ?

it cannot be possible ZigHCandel is not global variable , cannot replace in this place. Please help  how should be

Yes, I know that my sample code will not work as it is now. It was just an example to illustrate my point, and to show you that you are mixing concepts and that you need to use the same data for both methods.

For both methods you have to use "price" and "bar shift", not array index. So, you have to change your code accordingly. It is up to you to implement it. You can't expect us to rewrite your code for you.

All I can do here, is guide you by pointing out where you should look, and then you must analyse it and implement it as best you can.

 
Fernando Carreiro #:

Yes, I know that my sample code will not work as it is now. It was just an example to illustrate my point, and to show you that you are mixing concepts and that you need to use the same data for both methods.

For both methods you have to use "price" and "bar shift", not array index. So, you have to change your code accordingly. It is up to you to implement it. You can't expect us to rewrite your code for you.

All I can do here, is guide you by pointing out where you should look, and then you must analyse it and implement it as best you can.

this is because object trendline value take from barshift 0 ,

but in formula value , index value take from 2nd coordinate point.

if index value in formula value zero ,

they will be nearly same.

Reason: