評価: Empty Star Empty Star Empty Star Empty Star Empty Star
Help please for a custom Indicator
1448giorgio

会員 Mar 02, 2011  9 件の投稿 Giorgio (1448giorgio) Mar 15 2011 at 22:06
Hello


I wrote these lines of code and I would like to get it working properly .
I use it in an EA and it seems correct ...unfortunately messagge in journal says : cannot resize the array.
Can anybody please correct the bug or the syntax ?

Thanks

Giorgio


//+------------------------------------------------------------------+
//| Ratio.mq4 |
//| Copyright © 2010, Giorgio Guglielmo. |
//|
//+------------------------------------------------------------------+
#property copyright 'Copyright © 2010, Giorgio Guglielmo.'

//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue

#property indicator_minimum -800000
#property indicator_maximum 800000
//---- indicator parameters
extern int periodAv=25;
extern int period=5;

//---- indicator buffers
double GainBuffer[];//Gain
double RatioBuffer[];//Ratio
double ReturnBuffer[];//Return

double MyPlotBuffer[];
double AVMyPlotBuffer[];
double AV1MyPlotBuffer[];
double SmoothedAV1MyPlotBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(2);//controllare !!!!!
//---- drawing settings

   IndicatorDigits(Digits+2);
//---- 6 indicator buffers mapping

   //SetIndexBuffer(0,GainBuffer);//Gold
   //SetIndexBuffer(1,RatioBuffer);//Silver
   //SetIndexBuffer(2,ReturnBuffer);//Black
   //SetIndexBuffer(3,MyPlotBuffer);//Green
   SetIndexBuffer(0,AV1MyPlotBuffer);//Red
   SetIndexBuffer(1,SmoothedAV1MyPlotBuffer);//Blue
   
   //SetIndexStyle(0,DRAW_LINE);//Gold
   //SetIndexStyle(1,DRAW_LINE);//Silver
   //SetIndexStyle(2,DRAW_LINE);//Black
  // SetIndexStyle(3,DRAW_LINE);//Green
  // SetIndexStyle(4,DRAW_LINE);//Red
   SetIndexStyle(0,DRAW_LINE);//Blue
   SetIndexStyle(1,DRAW_LINE);//Blue
  
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName('Ratio('+period+','+periodAv+')');
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| declare arrays |
//+------------------------------------------------------------------+
int start()
  {
  if(Bars<MathMax(period,periodAv))
  return(0);
   int count,i,MaxBar,usedBar,bar,newSize;
   int counted_bars=IndicatorCounted();
   double MyArray0[]; //declare an array
   double MyArray1[]; //declare an array
   double MyArray2[]; //declare an array
   double MyArray3[]; //declare an array
   double MyArray4[]; //declare an array
   double MyArray5[]; //declare an array
   //double bbMacd[];

   if(counted_bars<0)
   return(-1);
 // ****************************************************************/

   if(counted_bars>0) counted_bars--;
   usedBar=MathMax(period,periodAv);
   count=Bars-counted_bars;
   MaxBar=Bars-1-usedBar;
   /****************************************************************/
   newSize=iBars(NULL,0);
   if(ArraySize(MyArray0)<newSize)
   {
   ArraySetAsSeries(MyArray0,false);
   ArraySetAsSeries(MyArray1,false);
   ArraySetAsSeries(MyArray2,false);
   ArraySetAsSeries(MyArray3,false);
   ArraySetAsSeries(MyArray4,false);
   ArraySetAsSeries(MyArray5,false);
   ArraySetAsSeries(GainBuffer,false);
   ArraySetAsSeries(RatioBuffer,false);
   ArraySetAsSeries(ReturnBuffer,false);
   ArraySetAsSeries(MyPlotBuffer,false);
   ArraySetAsSeries(AVMyPlotBuffer,false);
   ArraySetAsSeries(AV1MyPlotBuffer,false);
   ArraySetAsSeries(SmoothedAV1MyPlotBuffer,false);
   
   ArrayResize(MyArray0,newSize);
   ArrayResize(MyArray1,newSize);
   ArrayResize(MyArray2,newSize);
   ArrayResize(MyArray3,newSize);
   ArrayResize(MyArray4,newSize);
   ArrayResize(MyArray5,newSize);
   ArrayResize(GainBuffer,newSize);
   ArrayResize(RatioBuffer,newSize);
   ArrayResize(ReturnBuffer,newSize);
   ArrayResize(MyPlotBuffer,newSize);
   ArrayResize(AVMyPlotBuffer,newSize);
   ArrayResize(AV1MyPlotBuffer,newSize);
   ArrayResize(SmoothedAV1MyPlotBuffer,newSize);
   
   ArraySetAsSeries(MyArray0,true);
   ArraySetAsSeries(MyArray1,true);
   ArraySetAsSeries(MyArray2,true);
   ArraySetAsSeries(MyArray3,true);
   ArraySetAsSeries(MyArray4,true);
   ArraySetAsSeries(MyArray5,true);
   ArraySetAsSeries(GainBuffer,true);
   ArraySetAsSeries(RatioBuffer,true);
   ArraySetAsSeries(ReturnBuffer,true);
   ArraySetAsSeries(MyPlotBuffer,true);
   ArraySetAsSeries(AVMyPlotBuffer,true);
   ArraySetAsSeries(AV1MyPlotBuffer,true);
   ArraySetAsSeries(SmoothedAV1MyPlotBuffer,true);
   }
   /**********************************************************************************/
   if(count>MaxBar)
   {
   count=MaxBar;
   for(bar=Bars -1;bar>=MaxBar;bar--)
   {
   MyArray0[bar] = 0.0;
   MyArray1[bar] = 0.0;
   MyArray2[bar] = 0.0;
   MyArray3[bar] = 0.0;
   MyArray4[bar] = 0.0;
   MyArray5[bar] = 0.0;
   }
   }
   //******************************************************************************/
  
   //*******************************************************************************/
   for(i=count; i>=1; i--)
       {
         MyArray0[i] =(iClose(NULL,0,i)-iClose(NULL,0,period))*100/(iClose(NULL,0,period));
       }

   for( i=count; i>=1; i--)
   {
   GainBuffer[i]=MyArray0[i];
   }
   
    for( i=count; i>=1; i--)
       {
         MyArray1[i] = MathAbs(iMomentum(NULL,0,period,PRICE_CLOSE,i))/iATR(NULL,0,period,i);
       }
       //for(i=0; i<limit; i++)
       for( i=count; i>=1; i--)
       {
         RatioBuffer[i]= iMAOnArray(MyArray1,Bars,period+periodAv,0,MODE_SMA,i);//divide for 10 ??
       }
       
       for( i=count; i>=1; i--)
       {
         MyArray2[i] =RatioBuffer[i] ;
       }

    // for( i=0; i<limit; i++)
    for( i=count; i>=1; i--)
      {
      ReturnBuffer[i]=iMAOnArray(MyArray2,Bars,periodAv+period,0,MODE_SMA,i);
      }
     
    
    for( i=count; i>=1; i--)
     {
    MyArray4[i]=ReturnBuffer[i]*GainBuffer[i]*10;//multiply for 100
    
     }
   
   for( i=count; i>=1; i--)
    {
    MyPlotBuffer[i]=MyArray4[i];
    }
  
 
    
    for(i=count; i>=1; i--)
    {
    AV1MyPlotBuffer[i]=iMAOnArray(MyArray4,Bars,period,0,MODE_SMA,i);
    }
    
    for(i=count; i>=1; i--)
    {
    MyArray5[i]=AV1MyPlotBuffer[i]*0.9+MyArray4[i]*0.1;
    }
   
    for(i=count; i>=1; i--)
    {
    SmoothedAV1MyPlotBuffer[i]=iMAOnArray(MyArray5,Bars,period,0,MODE_SMA,i);
    }
   
   
   return(0);
  }
//+------------------------------------------------------------------+

aj90151

会員 Mar 07, 2010  56 件の投稿 aj90151 Mar 16 2011 at 11:53
I think you're trying to re-size the array to the same size.

Try adding this check:

if(ArraySize(MyArray0) != newSize) ArrayResize(MyArray0, newSize);

...
compuforexpamm

会員 Aug 20, 2009  202 件の投稿 kennyhubbard (compuforexpamm) Mar 16 2011 at 14:38
Giorgio,

You cannot resize indicator buffers, nor should you be trying to. An indicator buffer is is a special kind of an array and should not be treated like a normal one.

Wealth Creation Through Technology
1448giorgio

会員 Mar 02, 2011  9 件の投稿 Giorgio (1448giorgio) Mar 16 2011 at 15:21
Hi aj90151 and kennyhubbard

Thanks a lot for your help I'll try your suggest .....either have introduced myself in to new issues to think of.
I am learning and I am very grateful to you

Regards

Giorgio

James_Bond

会員 Jan 14, 2010  554 件の投稿 James_Bond Mar 16 2011 at 16:22

1448giorgio posted:
    Hi aj90151 and kennyhubbard

Thanks a lot for your help I'll try your suggest .....either have introduced myself in to new issues to think of.
I am learning and I am very grateful to you

Regards

Giorgio


Were you able to sort it out?

1448giorgio

会員 Mar 02, 2011  9 件の投稿 Giorgio (1448giorgio) Mar 16 2011 at 17:53
Hi

Unfortunately not yet

All suggests I had seems to me right but not solve the problem.

The strange thing is that the indicator as it is ....works in EA and is painted in separate window chart as well.

when I modify or check as you said ....the indicator is painted as a line == 0 and of course it does not work in EA

Thanks Giorgio

1448giorgio

会員 Mar 02, 2011  9 件の投稿 Giorgio (1448giorgio) Mar 16 2011 at 20:58
Hi wilkinson and all

Thanks for your interest

I am on the ground

Any idea ?

Giorgio


James_Bond

会員 Jan 14, 2010  554 件の投稿 James_Bond Mar 17 2011 at 08:54

1448giorgio posted:
    Hi

Unfortunately not yet

All suggests I had seems to me right but not solve the problem.

The strange thing is that the indicator as it is ....works in EA and is painted in separate window chart as well.

when I modify or check as you said ....the indicator is painted as a line == 0 and of course it does not work in EA

Thanks Giorgio


Have you tried debugging the issue? Print all variables and you'll quickly find the error.

1448giorgio

会員 Mar 02, 2011  9 件の投稿 Giorgio (1448giorgio) Mar 17 2011 at 11:10
Hello wilkinson

Yes I printed variables and reported values seem to be reported in right way .(message always : cannot resize array but EA reads values from indicator)

Any way as soon as I do not resize buffers .....buffers are all ==0 and EA does not work.

EA should read two buffers from this indicator

If this matter has be solved throught a fee I am ready to pay any coder willing to help to do the job ...I mean $50 throught PayPal as soon as work is done

Is it an adequate reward for this issue ?

Thanks Giorgio

1448giorgio

会員 Mar 02, 2011  9 件の投稿 Giorgio (1448giorgio) Mar 17 2011 at 17:49
Hi all

I sorted it out

Thanks to all and in particular Kennyhubbard who suggested the right road

Giorgio

コメントするにはログインしてください。
Consumer Confidence Index (23 min)
AUDUSD – Slide Continues as Aussie Consumer C...(39 min ago)
EURUSD 1.29244 GBPUSD 1.50984
USDJPY 103.054 USDCAD 1.03098
ツール コミュニティ レビュー プラットフォーム 会社 サポート
経済カレンダー コミュニティ ブローカー ウィジェット について よくある質問(FAQ)
Forex Market システム エキスパートアドバイザー 特長 ブログ ヘルプ
Forex Volatility Most Popular Systems シグナルプロバイダー API Twitter 連絡先
Forex Correlation 戦略 VPS Services モバイル Facebook バグを報告する
Forex Broker Spreads コンテスト EA Programming 翻訳    
Forex Broker Quotes Forex Charts PAMM Brokers RSS    
Forex Broker Swaps コミュニティのOutlook Rebate Programs      
Forexのニュースをストリーミング   Trading Platforms      
Forex Broker Volume          
COT Data New          

サイトマップ  |   Terms & Conditions  |   プライバシーポリシー
©2012 Myfxbook Ltd. All Rights Reserved.
HIGH RISK WARNING: Foreign exchange trading carries a high level of risk that may not be suitable for all investors. Leverage creates additional risk and loss exposure. Before you decide to trade foreign exchange, carefully consider your investment objectives, experience level, and risk tolerance. You could lose some or all of your initial investment; do not invest money that you cannot afford to lose. Educate yourself on the risks associated with foreign exchange trading, and seek advice from an independent financial or tax advisor if you have any questions. Any data and information is provided 'as is' solely for informational purposes, and is not intended for trading purposes or advice.