stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

More help Please
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1261
Page 1 of 1
Author:  s01 [ Sun Dec 02, 2012 11:16 pm ]
Post subject:  More help Please

EDIT-2

OK, since my last post I have sucessfully modded about 5 indicators, but I am having problems with about 5 others. So I am getting better, slowly but surely.

SHI_Channel indicator, Done!!
Slope Direction indicator, Done!!

Awaiting an answer before I go try to fix a few more, before I post them up..

Thanks George!!

Code: Select all

 
Thanks Again, Steve
Author:  SteveHopwood [ Sun Dec 02, 2012 11:35 pm ]
Post subject:  Re: More help Please

s01 wrote:If it would not be a problem, after we fix one, I could just post the next one in this same thread instead of having 5 different threads all opened at the same time??

Thanks agin in advance, Steve / s01
You can always edit your thread and so post whatever you want in post 1, then add a 'latest update to xxxxx in post 1' post. This is how I do it.

:D
Author:  Carioca [ Sun Dec 02, 2012 11:41 pm ]
Post subject:  Re: More help Please

Enters the site forexmt4.com

I think I should have a many versions of this indicator.

Carioca
Author:  gaheitman [ Mon Dec 03, 2012 12:00 am ]
Post subject:  Re: More help Please

s01 wrote:OK, since my last post I have sucessfully modded about 5 indicators, but I am having problems with about 5 others. So I am getting better, slowly but surely.

I have decided to break the big one in all indicator down into individual indicators, then once I get all the parts working I might or might not take a stab at making a all in one.

So next up is a SHI_Channel indicator, I have it displaying the correct numbers for the slope. If the clope of the channel is down the numbers are negative and if up the numbers are positve. But the color does not always change or display correctly. I have //'d in the problem areas with descriptions.

If it would not be a problem, after we fix one, I could just post the next one in this same thread instead of having 5 different threads all opened at the same time??

Thanks Again, Steve
To fix your initial test:

Code: Select all

    ///   if (DoubleToStr(-Step / Point,2) > 0) /// getting '>' - different types in comparison error
change it to:

Code: Select all

if (-Step / Point > 0) 
You don't need to convert it to a string which is what DoubleToStr() does, just leave it as a double.

I didn't run the code, but reading through it I'm guessing since it is going backwards through the bars, the UpDown you were using wasn't the most recent.

George
Author:  s01 [ Mon Dec 03, 2012 8:02 am ]
Post subject:  Re: More help Please

gaheitman wrote:
s01 wrote: So I am getting better, slowly but surely.

Thanks Again, Steve
To fix your initial test:

Code: Select all

    ///   if (DoubleToStr(-Step / Point,2) > 0) /// getting '>' - different types in comparison error
change it to:

Code: Select all

if (-Step / Point > 0) 
You don't need to convert it to a string which is what DoubleToStr() does, just leave it as a double.

I didn't run the code, but reading through it I'm guessing since it is going backwards through the bars, the UpDown you were using wasn't the most recent.

George

Thanks Geroge, that did the trick!
And going back I was able to fix another with that little tidbit of information.

So I have edited the 1st post with the next little indicator its a Slope Direction indicator, and I have it displaying the lines on the chart now, just the text is missing. This one might help me with a few others since it displays values in the data window when working correctly. And thats a problem I'm having with a couple of others. So this fix might set me up to fix a few more.

Again I have ///'d out and comented in the indicator where the problems are ....

Thanks again, Steve
Author:  gaheitman [ Mon Dec 03, 2012 9:35 am ]
Post subject:  Re: More help Please

s01 wrote:EDIT-1

OK, since my last post I have sucessfully modded about 5 indicators, but I am having problems with about 5 others. So I am getting better, slowly but surely.

SHI_Channel indicator, Done!!

Next up is a Slope Direction indicator.
A couple of points. The value of x in your test section is always -1, since that is what causes it to drop out of the earlier loop. Generally, it's a bad idea to use the variable that drives a for loop outside of the for loop since its value is more of a side-effect of the loop processing and wasn't explicitly set. What you really want is the last value (value 0) of the array.

Also, the values are either 1 or -1, not 1 or 2, so your code should be:

Code: Select all

   if (ShowText)

   {                     

      if ( trend[0] == 1 ) 
                           
      {

         ObjectCreate   ( "54", OBJ_LABEL, 0, 0, 0 );
         ObjectSet      ( "54", OBJPROP_XDISTANCE, 1440 );
         ObjectSet      ( "54", OBJPROP_YDISTANCE, 220 );
         ObjectSet      ( "54", OBJPROP_BACK, false );
         ObjectSetText  ( "54","UP /", 10, "Arial Bold", Lime);
      }
      
     if ( trend[0] == -1 ) 
                          
      {
         ObjectCreate   ( "54", OBJ_LABEL, 0, 0, 0 );
         ObjectSet      ( "54", OBJPROP_XDISTANCE, 1440 );
         ObjectSet      ( "54", OBJPROP_YDISTANCE, 220 );
         ObjectSet      ( "54", OBJPROP_BACK, false );
         ObjectSetText  ( "54","DN /", 10, "Arial Bold", Red);

      }
   }
Also, I noticed you are trying to delete the objects named "DN /" and "UP /" in deinit(). These objects don't exist, you only need to delete the object named "55".

George
Author:  s01 [ Mon Dec 03, 2012 10:09 am ]
Post subject:  Re: More help Please

gaheitman wrote:
A couple of points. The value of x in your test section is always -1, since that is what causes it to drop out of the earlier loop. Generally, it's a bad idea to use the variable that drives a for loop outside of the for loop since its value is more of a side-effect of the loop processing and wasn't explicitly set. What you really want is the last value (value 0) of the array.

Also, the values are either 1 or -1, not 1 or 2, so your code should be:

Code: Select all

   if (ShowText)

   {                     

      if ( trend[0] == 1 ) 
                           
      {

         ObjectCreate   ( "54", OBJ_LABEL, 0, 0, 0 );
         ObjectSet      ( "54", OBJPROP_XDISTANCE, 1440 );
         ObjectSet      ( "54", OBJPROP_YDISTANCE, 220 );
         ObjectSet      ( "54", OBJPROP_BACK, false );
         ObjectSetText  ( "54","UP /", 10, "Arial Bold", Lime);
      }
      
     if ( trend[0] == -1 ) 
                          
      {
         ObjectCreate   ( "54", OBJ_LABEL, 0, 0, 0 );
         ObjectSet      ( "54", OBJPROP_XDISTANCE, 1440 );
         ObjectSet      ( "54", OBJPROP_YDISTANCE, 220 );
         ObjectSet      ( "54", OBJPROP_BACK, false );
         ObjectSetText  ( "54","DN /", 10, "Arial Bold", Red);

      }
   }
Also, I noticed you are trying to delete the objects named "DN /" and "UP /" in deinit(). These objects don't exist, you only need to delete the object named "55".

George
And that did the trick, it now works as it should ... and I understand why UP & DN do not have to be deleted ... filed away in my notes.

Question: I'm a bit confused now, the values that are displayed on the lines on screen mean nothing then, how do you decide how to find the values if there are more than 3 or 6? Is it a progressive thing were the first two values since x is always -1 would be 1 & -1 the next would be 2 or -2?

Steve
Author:  gaheitman [ Mon Dec 03, 2012 10:38 am ]
Post subject:  Re: More help Please

s01 wrote:Question: I'm a bit confused now, the values that are displayed on the lines on screen mean nothing then, how do you decide how to find the values if there are more than 3 or 6? Is it a progressive thing were the first two values since x is always -1 would be 1 & -1 the next would be 2 or -2?

Steve
In this particular indicator, there are 5 buffers being used. Three are being handled "naturally" and 2 are done with normal arrays that are modified to look like series arrays via the ArraySetAsSeries() function.

I'll try to walk through the buffer logic for this indicator. The properties section defines 2 buffers via the statement

Code: Select all

#property indicator_buffers 2 
This tells Empty4 that we will be drawing two "lines" on the chart.

Later, in the init() function, we make the following calls:

Code: Select all

    IndicatorBuffers(3);                 // orig 3 
    SetIndexBuffer(0, Uptrend); 
 //   ArraySetAsSeries(Uptrend, true);   // orig was //'d out 
    SetIndexBuffer(1, Dntrend); 
 //   ArraySetAsSeries(Dntrend, true);   // orig was //'d out
    SetIndexBuffer(2, ExtMapBuffer); 
    ArraySetAsSeries(ExtMapBuffer, true); 
The call to IndicatorBuffers() tells Empty4 to actually reserve memory to track three buffers. Since we are only able to display 2 buffers on the chart (because of our setting indicator_buffers to 2), the third buffer will be hidden (it won't even appear in the data window) but Empty4 will deal with resizing it as new bars are formed.

The two buffers Uptrend[] and Dntrend[] are really only displaying a single line. We use two buffers because we want to display them in the appropriate color depending on whether it is in an up trend or a down trend. Metrader isn't smart enough to allow us to switch colors on the fly.

In start(), we have the following code to create two additional buffers for our calculations:

Code: Select all

    double vect[], trend[]; 
    
    if(e > Bars) 
        e = Bars;    

    ArrayResize(vect, e); 
    ArraySetAsSeries(vect, true);
    ArrayResize(trend, e); 
    ArraySetAsSeries(trend, true); 
When using our own arrays (not those specified as indicator buffers via the SetIndexBuffer() function) we have to deal with sizing them correctly and usually calling the ArraySetAsSeries() function. The ASAS() function reverses the order we access the array so that it is logically aligned with the way indicator buffers are accessed (the last element in the array has index 0).

Next, we have three loops. The first prefills our vect[] array:

Code: Select all

    for(x = 0; x < e; x++) 
    { 
        vect[x] = 2*WMA(x, period/2) - WMA(x, period);        
 //       Print("Bar date/time: ", TimeToStr(Time[x]), " close: ", Close[x], " vect[", x, "] = ", vect[x],  // orig  was //'d out
 //       " 2*WMA(p/2) = ", 2*WMA(x, period/2), " WMA(p) = ",  WMA(x, period));                             // orig was //'d out
    } 
The next loops fills our third "natural" buffer (the invisible one) with a smoothed version of vect[]

Code: Select all

    for(x = 0; x < e-period; x++)
     
        ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x);        
And finally, in our third loop we calculate the trend (is our smoothed value in ExtManBuffer[] rising or falling) and set the appropriate visible indicator buffer value.

Code: Select all

    for(x = e-period; x >= 0; x--)
    {     
        trend[x] = trend[x+1];
        if (ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1;
        if (ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1;
    
    if (trend[x]>0)
    { Uptrend[x] = ExtMapBuffer[x]; 
      if (trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1];
      Dntrend[x] = EMPTY_VALUE;
    }
    else              
    if (trend[x]<0)
    { 
      Dntrend[x] = ExtMapBuffer[x]; 
      if (trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1];
      Uptrend[x] = EMPTY_VALUE;
    }              
I'm not sure why the original author didn't use "natural" buffers throughout the program. Since we are allowed to have 8, the two additional ones shouldn't have been an issue.

George
Author:  s01 [ Mon Dec 03, 2012 2:12 pm ]
Post subject:  Re: More help Please

OK, got that indicator printed out and that stuff highlighted, along with your notes ... gonna go take a crack at a harder one.

Thanks again, George

I'm sure I'll be back .. lol
All times are UTC Page 1 of 1