not to answer without looking at the code.
but i assume there is some calculations error inside the loop
not to answer without looking at the code.
but i assume there is some calculations error inside the loop
Hope it helps
Thanks
#property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Green #property indicator_color2 Red //---- BBands_Stop_v2 input parameters extern int BB_Length=20; // Bollinger Bands Period extern double BB_Deviation=2.0; // Deviation extern double BB_MoneyRisk=1.0; // Offset Factor //---- double UP_Trend[]; double DOWN_Trend[]; double UP_Trend_Beggining[]; double DOWN_Trend_Beggining[]; double BuyTrailingStop[]; double SellTrailingStop[]; //---- //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(6); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexBuffer(0,UP_Trend); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexBuffer(1,DOWN_Trend); SetIndexStyle(2,DRAW_NONE); SetIndexBuffer(2,UP_Trend_Beggining); SetIndexStyle(3,DRAW_NONE); SetIndexBuffer(3,DOWN_Trend_Beggining); SetIndexStyle(4,DRAW_NONE); SetIndexBuffer(4,BuyTrailingStop); SetIndexStyle(5,DRAW_NONE); SetIndexBuffer(5,SellTrailingStop); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); //---- int limit; int UpShift=0; int DownShift=0; //---- Data ckecking ----// if (counted_bars==0) { limit=Bars-1; } if (counted_bars>0) { limit=Bars-counted_bars; } for(int i=limit;i>=0;i--) // Count down for one pass { BuyTrailingStop[i]= iCustom(Symbol(), 0, "BBands_Stop_v2", BB_Length, BB_Deviation, BB_MoneyRisk, 4, i); SellTrailingStop[i]=iCustom(Symbol(), 0, "BBands_Stop_v2", BB_Length,BB_Deviation, BB_MoneyRisk, 5, i); //--------------------------------------------------------------------------------------------------------// // Inicio dos calculos - FLAG // //--------------------------------------------------------------------------------------------------------// if(Close[i+1]<=BuyTrailingStop[i+1] && Close[i]>BuyTrailingStop[i]) { UP_Trend_Beggining[i]=Time[i]; // Buy TIME Flag UpShift=i; } if(Close[i+1]>=BuyTrailingStop[i+1] && Close[i]<BuyTrailingStop[i]) { DOWN_Trend_Beggining[i]=Time[i]; // Sell TIME Flag DownShift=i; } //-------------------------------------------------------------------------------------------------------// // Cálculo da % //------------------------------------------------------------------------------------------------------// if(Close[i]>=BuyTrailingStop[i]) { UP_Trend[i]=(Close[i]-iClose(NULL,0,UpShift))/iClose(NULL,0,UpShift)*100; } if(Close[i]<=BuyTrailingStop[i]) { DOWN_Trend[i]=(iClose(NULL,0,DownShift)-Close[i])/iClose(NULL,0,DownShift)*100; } } //---- return(0); } //+------------------------------------------------------------------+
The problem is : I don’t know why this indicator change when I compile it. I tried to create a flag showing when a new trend started. Once appears the flag, the indicator has to show the difference between the actual price and the price at flag moment. It would offer me how much the price is above or below the flag (the start of a new trend).
I did it in other format, but the indicator still wrong.
It will appreciate your help if you know how to correct this error
//-------------------------------------------------------------------------------------------------------// // Cálculo da % //------------------------------------------------------------------------------------------------------// if(Close[i]>=BuyTrailingStop[i]) { UP_Trend[i]=(Close[i]- iClose(NULL,0, iBarShift(NULL,0,DOWN_Trend_Beggining[i],false)))/ iClose(NULL,0, iBarShift(NULL,0,DOWN_Trend_Beggining[i],false))*100; } if(Close[i]<=BuyTrailingStop[i]) { DOWN_Trend[i]=(iClose(NULL,0, iBarShift(NULL,0,DOWN_Trend_Beggining[i],false)) -Close[i])/ iClose(NULL,0, iBarShift(NULL,0,DOWN_Trend_Beggining[i],false))*100; }
change
limit=Bars-counted_bars;
to:
limit=Bars-counted_bars-1;
Didn't change.... the problem still there.
UpShift and DownShift is showing = 0, all time... So... I'm not doing reference to the point where the trend started... I'm doing reference to the present bar.
How can I change my looping to find the exact point where my flag apppeared?
New modification to try to find the number of bars to the Flag... But I still with the same error- please help me!
//--------------------------------------------------------------------------------------------------------// // Inicio dos calculos - FLAG // //--------------------------------------------------------------------------------------------------------// if(Close[i+1]<=BuyTrailingStop[i+1] && Close[i]>BuyTrailingStop[i]) { UP_Trend_Beggining[i]=1; // Buy TIME Flag UpShift=1; } else { UpShift++; } Print("UpShift = ",UpShift); if(Close[i+1]>=BuyTrailingStop[i+1] && Close[i]<BuyTrailingStop[i]) { DOWN_Trend_Beggining[i]=1; // Sell TIME Flag DownShift=1; } else { DownShift++; } Print("DownShift = ",DownShift); //-------------------------------------------------------------------------------------------------------// // Cálculo da % //------------------------------------------------------------------------------------------------------// if(Close[i]>=BuyTrailingStop[i]) { UP_Trend[i]=(Close[i]-iClose(NULL,0,UpShift))/iClose(NULL,0,UpShift)*100; } if(Close[i]<=BuyTrailingStop[i]) { DOWN_Trend[i]=(iClose(NULL,0,DownShift)-Close[i])/iClose(NULL,0,DownShift)*100; } }
try changing
int limit; int UpShift=0; int DownShift=0;
to:
int limit; static int UpShift=0; static int DownShift=0;
zzueg !! worked well.
Could you explain why?
To me, if I classify UpShift and DownShift to static int =0, it never would have a value different than zero.
Could you explain your logic?
Thanks a lot for your help!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi friends,
I’ve been trying to solve a problem in one of my indicator but I cannot solve it for while.
When I plot the indicator It shows past results correctly. The problem occurs in real time, since the indicator does not plot on the screen any other signal until I click on the compile (metatrader formula builder). When I click on the compile, it recalculates the past and shows some signals that would be showed…. So I can only see the past and not the present…. Any idea about what’s happening?
Thanks
Rodrigosm