Why cannot I assign a value to an array ???

Post Reply
User avatar
lucklogic
Trader
Posts: 85
Joined: Mon Jan 23, 2012 6:26 pm
Location: On The Hoe in Plymouth, UK

Why cannot I assign a value to an array ???

Post by lucklogic »

Hi,

This is the full subset code of DeMark Trendline Trader. I want to capture the estimate of the High and Low profit zones in a buffer for external use. In the code I have already set the Array: double ExtBufferLow []; and SetIndexBuffer(3,ExtBufferLow);

I have highlighted below how the value is assigned to the array, but this does not work - but why ?


Code: Select all


string TakeProfitLowTD(int L1,int L2,int Step,int Col)/*Draw Sell TD Price Projection(s)*/
{
 int i,ii,j=0;
 string Comm="";
 double kL,LC1,LC2,LC3,k,St;
 kL=(Low[L1]-Low[L2])/(L2-L1);
 while (NormalizeDouble(Point,j)==0)j++; 
 k=0;
 for(i=L1;i>0;i--)if(Close[i]<Low[L2]+kL*(L2-i)){k=Low[L2]+kL*(L2-i);break;}
 if (k>0)
   {
    Comm=Comm+"LTD_Line ("+DoubleToStr(Low[L2]+kL*L2,j)+") broken at "+DoubleToStr(k,j)+", downtargets:\n";
    ii=Highest(NULL,0,MODE_HIGH,L2-i,i);    
    LC1=High[ii]-(Low[L2]+kL*(L2-ii));
    LC2=Close[ii]-(Low[L2]+kL*(L2-ii));
    i=Highest(NULL,0,MODE_CLOSE,L2-i,i);
    LC3=Close[ii]-(Low[L2]+kL*(L2-ii));
    St=TrendLineStyle;/*Original STYLE_SOLID*/ 
   } 
 else
   {
    k=Low[L2]+kL*L2;
    Comm=Comm+"LTD_Line ("+DoubleToStr(k,j)+"), probable downbreak targets:\n";        
    ii=Highest(NULL,0,MODE_HIGH,L2,0);    
    LC1=High[ii]-(Low[L2]+kL*(L2-ii));
	
    LC2=Close[ii]-(Low[L2]+kL*(L2-ii));
    ii=Highest(NULL,0,MODE_CLOSE,L2,0);
    LC3=Close[ii]-(Low[L2]+kL*(L2-ii));
    St=TrendLineStyle;/*Original STYLE_DASHDOT*/ 
   }
 ObjectSet("LL_"+Step,OBJPROP_STYLE,St);   
 Comm=Comm+"T1="+DoubleToStr(k-LC1,j)+" ("+DoubleToStr(LC1/Point,0)+"pts.)\n";//changed "pts.)" to "pts.)\n"
 
********************************
 ExtBufferLow [1] =  (k-LC1) ;    //here is where the value will not set onto the array ????****************************

 //Comm=Comm+" T2="+DoubleToStr(k-LC2,j)+" ("+DoubleToStr(LC2/Point,0)+"pts.)";
 //Comm=Comm+" T3="+DoubleToStr(k-LC3,j)+" ("+DoubleToStr(LC3/Point,0)+"pts.)\n";
 ObjectSet("LC1_"+Step,OBJPROP_TIME1,Time[L1]);ObjectSet("LC1_"+Step,OBJPROP_TIME2,Time[0]);
 ObjectSet("LC1_"+Step,OBJPROP_PRICE1,k-LC1);ObjectSet("LC1_"+Step,OBJPROP_PRICE2,k-LC1);
 ObjectSet("LC1_"+Step,OBJPROP_COLOR,Col);ObjectSet("LC1_"+Step,OBJPROP_STYLE,St);      
 //ObjectSet("LC2_"+Step,OBJPROP_TIME1,Time[L1]);ObjectSet("LC2_"+Step,OBJPROP_TIME2,Time[0]);
 //ObjectSet("LC2_"+Step,OBJPROP_PRICE1,k-LC2);ObjectSet("LC2_"+Step,OBJPROP_PRICE2,k-LC2);
 //ObjectSet("LC2_"+Step,OBJPROP_COLOR,Col);ObjectSet("LC2_"+Step,OBJPROP_STYLE,St);
 //ObjectSet("LC3_"+Step,OBJPROP_TIME1,Time[L1]);ObjectSet("LC3_"+Step,OBJPROP_TIME2,Time[0]);
 //ObjectSet("LC3_"+Step,OBJPROP_PRICE1,k-LC3);ObjectSet("LC3_"+Step,OBJPROP_PRICE2,k-LC3);
 //ObjectSet("LC3_"+Step,OBJPROP_COLOR,Col);ObjectSet("LC3_"+Step,OBJPROP_STYLE,St);   
 if (Step==1)
   {
    ObjectSet("LC1_"+Step,OBJPROP_WIDTH,ProjectionLinesWidth);/*Original OBJPROP_WIDTH,2*/
    ObjectSet("LC1_"+Step,OBJPROP_STYLE,ProjectionLinesStyle);/*This Line of code added from original. TD Lower Projection Line Style*/
    //ObjectSet("LC2_"+Step,OBJPROP_WIDTH,2);
    //ObjectSet("LC3_"+Step,OBJPROP_WIDTH,2);
   } 
 else
   {
    ObjectSet("LC1_"+Step,OBJPROP_WIDTH,2);
    //ObjectSet("LC2_"+Step,OBJPROP_WIDTH,2);
    //ObjectSet("LC3_"+Step,OBJPROP_WIDTH,2);
   }
 return(Comm);
}
User avatar
NeoTrader
Trader
Posts: 436
Joined: Wed Apr 04, 2012 2:52 pm
Location: small Village at Lake Chiemsee, Bavaria, Germany

Re: Why cannot I assign a value to an array ???

Post by NeoTrader »

hi lucklogic,

have you tried to print the value of "(k-LC1)" and looked what it shows?

And with ExtBufferLow [1] you know that you always overwrite the Buffer...have you tried to use [0] instead of [1]....

just my 2 pips...

happy trading,

NeoTrader
garyfritz

Re: Why cannot I assign a value to an array ???

Post by garyfritz »

lucklogic, how does it fail? What error do you get -- compile error, or runtime error, or does it work without error but you just don't get the value displayed in the indicator, or...?

Did you just declare it as

Code: Select all

double ExtBufferLow [];
SetIndexBuffer(3,ExtBufferLow);[/quote]
?  Did you declare it in the global context?

Do your other buffer declarations & assignments work?
User avatar
lucklogic
Trader
Posts: 85
Joined: Mon Jan 23, 2012 6:26 pm
Location: On The Hoe in Plymouth, UK

Re: Why cannot I assign a value to an array ???

Post by lucklogic »

garyfritz wrote:lucklogic, how does it fail? What error do you get -- compile error, or runtime error, or does it work without error but you just don't get the value displayed in the indicator, or...?

Did you just declare it as

Code: Select all

double ExtBufferLow [];
SetIndexBuffer(3,ExtBufferLow);[/quote]
?  Did you declare it in the global context?

Do your other buffer declarations & assignments work?[/quote]


Thank you for all of your idea's, I had actually done most of them 

It turned out to be  that I had failed to increase  the #property indicator_buffers  from declared 2 to the modified indicator's  need for 4 ie. #property indicator_buffers 4

 :lol:
User avatar
NeoTrader
Trader
Posts: 436
Joined: Wed Apr 04, 2012 2:52 pm
Location: small Village at Lake Chiemsee, Bavaria, Germany

Re: Why cannot I assign a value to an array ???

Post by NeoTrader »

hi lucklogic,
lucklogic wrote:It turned out to be that I had failed to increase the #property indicator_buffers from declared 2 to the modified indicator's need for 4 ie. #property indicator_buffers 4
hehe...I also had the same *bug* when I first started to mess around indicators.. ;)

happy trading,

NeoTrader

-
Post Reply

Return to “Coders Hangout”