I don't think you have shown enough code for anyone to draw any conclusions here. ..
phy:
Thanks for the response,I don't think you have shown enough code for anyone to draw any conclusions here. ..
The code I've shown is where the issue is, as the indicator itself is working perfectly in a separate_window.
The arrows themselves show on the chart window, but disappear as soon as I change the timeframe (refresh the chart).....
What I'm trying to do is ensure that when I change the time-frame, as I change it back, the arrows are still in place.
Should I have anything in init();
At the moment everything is in calculations.. maybe that's where my problem is
At the moment everything is in calculations.. maybe that's where my problem is
Show your code
Okay hope it's not too messy
When you click 5min then go back to 1min, the arrows have disappeared!
Really really appreciate your time and help.
//+------------------------------------------------------------------+ //| Louw Coetzer aka FX Sniper | //| Copyright © 2004, MetaQuotes Software Corp. | //| https://www.metaquotes.net// | //+------------------------------------------------------------------+ #property copyright "Copyright © 2004, Fx Sniper." #property link "http://www.dunno.net/" //---- indicator settings #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Gold #property indicator_color2 White // Ergo Variables extern int pq =2; extern int pr = 10; extern int ps = 5; extern int trigger =3; static int arrowCount; double alertTag; extern bool EnableAlert = true; //---- indicator buffers string signal; string lastsignal; int hasbeen; double mtm[]; double absmtm[]; double ErgoCCI[]; double MainCCI[]; double var1[]; double var2[]; double var2a[]; double var2b[]; //double valor1[]; //double valor2[]; //double extvar[]; //double cciSignal[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- 2 additional buffers are used for counting. IndicatorBuffers(8); //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3,Blue); SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,3,DarkOrange); SetIndexBuffer(0,ErgoCCI); SetIndexLabel(0,"Ergodic CCI"); SetIndexBuffer(1,MainCCI); SetIndexLabel(1,"Trigger Line"); SetIndexBuffer(2,mtm); SetIndexBuffer(3,var1); SetIndexBuffer(4,var2); SetIndexBuffer(5,absmtm); SetIndexBuffer(6,var2a); SetIndexBuffer(7,var2b); //---- name for DataWindow and indicator subwindow label //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Calculations | //+------------------------------------------------------------------+ void AlertOnce(string alert_msg, int ref) { if (ref > 10) return; ref--; static int LastAlert[10]; if( LastAlert[ref] == 0 || LastAlert[ref] < Bars) { if (EnableAlert == true) { PlaySound("alert2.wav"); Alert(alert_msg); } LastAlert[ref] = Bars; arrowCount++; ObjectCreate("Sniper ArrowDown"+Symbol()+arrowCount, OBJ_ARROW, 0, TimeCurrent(),Bid); ObjectSet("Sniper ArrowDown"+Symbol()+arrowCount,OBJPROP_ARROWCODE,242); ObjectSet("Sniper ArrowDown"+Symbol()+arrowCount, OBJPROP_COLOR,Maroon); ObjectSet("Sniper ArrowDown"+Symbol()+arrowCount, OBJPROP_STYLE, STYLE_SOLID); ObjectSet("Sniper ArrowDown"+Symbol()+arrowCount, OBJPROP_WIDTH, 3); Print("arrowCount: ",arrowCount); } } void AlertOnce2(string alert_msg, int ref2) { if (ref2 > 10) return; ref2--; static int LastAlert2[10]; if( LastAlert2[ref2] == 0 || LastAlert2[ref2] < Bars) { if (EnableAlert == true) { PlaySound("alert2.wav"); Alert(alert_msg); } LastAlert2[ref2] = Bars; ObjectCreate("Sniper ArrowUp"+Symbol()+arrowCount, OBJ_ARROW, 0, TimeCurrent(),Bid); ObjectSet("Sniper ArrowUp"+Symbol()+arrowCount,OBJPROP_ARROWCODE,241); ObjectSet("Sniper ArrowUp"+Symbol()+arrowCount,OBJPROP_COLOR,Blue); ObjectSet("Sniper ArrowUp"+Symbol()+arrowCount,OBJPROP_STYLE, STYLE_SOLID); ObjectSet("Sniper ArrowUp"+Symbol()+arrowCount,OBJPROP_WIDTH, 3); arrowCount++; } } int start() { int limit; int i; int r; int counted_bars=IndicatorCounted(); double latestmain; double latestergo; double latestlatestmain; double latestlatestergo; double backmain; double backergo; double threeback; int timepassed; //---- check for possible errors if(counted_bars<0) return(-1); //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; //---- main loop //---- done for(i=0; i <= Bars; i++) { mtm[i]= Close[i]- Close[i +1]; } for(i=0; i <= Bars-1; i++) { absmtm[i] = MathAbs(mtm[i]); } for(i=0; i <= Bars-1; i++) { var1[i]= iMAOnArray(mtm,0,pq,0,MODE_EMA,i); } for(i=0; i <= Bars-1; i++) { var2[i]= iMAOnArray(var1,Bars,pr,0,MODE_EMA,i); } for(i=0; i <= Bars-1; i++) { var2a[i]= iMAOnArray(absmtm,0,pq,0,MODE_EMA,i); } for(i=0; i <= Bars-1; i++) { var2b[i]= iMAOnArray(var2a,0,pr,0,MODE_EMA,i); } for(i=0; i <= Bars-1; i++) { ErgoCCI[i] = (500 * iMAOnArray(var2,0,ps,0,MODE_EMA,i))/(iMAOnArray(var2b,0,ps,0,MODE_EMA,i)); //var2a[i]/var2b[i]; latestergo = (500 * iMAOnArray(var2,0,ps,0,MODE_EMA,1))/(iMAOnArray(var2b,0,ps,0,MODE_EMA,0)); latestlatestergo = (500 * iMAOnArray(var2,0,ps,0,MODE_EMA,1))/(iMAOnArray(var2b,0,ps,0,MODE_EMA,1)); backergo = (500 * iMAOnArray(var2,0,ps,0,MODE_EMA,1))/(iMAOnArray(var2b,0,ps,0,MODE_EMA,2)); } for(i=0; i<=Bars; i++) { MainCCI[i]=iMAOnArray(ErgoCCI,0,trigger,0,MODE_EMA,i); latestmain = iMAOnArray(ErgoCCI,0,trigger,0,MODE_EMA,0); latestlatestmain = iMAOnArray(ErgoCCI,0,trigger,0,MODE_EMA,1); backmain = iMAOnArray(ErgoCCI,0,trigger,0,MODE_EMA,2); threeback = iMAOnArray(ErgoCCI,0,trigger,0,MODE_EMA,3); } for(i=0; i<=Bars; i++) { if(MainCCI[i] > ErgoCCI[i]){ {signal = "SHORT"; if ((latestlatestmain > 0) && (latestmain < 0) && (latestergo < latestmain)) { AlertOnce("Sniper going SHORT on "+Symbol(),3); } if ((threeback < backmain) && (latestmain < latestlatestmain) && (latestergo < (latestmain-3)) && (threeback < 0) && (latestmain < 0)) { AlertOnce("Sniper going SHORT Further on "+Symbol(),3); } // Print("Bar Back: ",latestmain," Two Bars Back: ",latestlatestmain," Bar Back Ergo: ",latestergo," Two Bars Back Ergo: ",latestlatestergo); // Print("LastBar: ",Close[1],"This Bar:", MainCCI[i]); } if(lastsignal != signal && alertTag!=Time[0]){ // Alert("Sniper going Short on "+Symbol()" i= ",i); alertTag = Time[0]; lastsignal=signal; } } if (MainCCI[i] < ErgoCCI[i]){ {signal = "LONG"; if ((latestlatestmain < 0) && (latestmain > 0) && (latestergo > latestmain)) { AlertOnce2("Sniper going LONG on "+Symbol(),3); } if ((threeback > backmain) && (latestmain > latestlatestmain) && (latestergo > (latestmain+3)) && (threeback > 0) && (latestmain > 0)) { AlertOnce2("Sniper going LONG Further on "+Symbol(),3); } // Print("Bar Back: ",latestmain," Two Bars Back: ",latestlatestmain," Bar Back Ergo: ",latestergo," Two Bars Back Ergo: ",latestlatestergo); } if(lastsignal != signal && alertTag!=Time[0]){ //Alert("FX Sniper going LONG on ",Symbol()); alertTag = Time[0]; lastsignal=signal; }} if (MainCCI[i] == ErgoCCI[i]) {signal = "NEUTRAL";} IndicatorShortName("FX Sniper: "+signal); return(0); } } //+------------------------------------------------------------------+The main Alert and arrow position occurs when it hits the first blue bar of a direction change. The arrow positions itself on the chart.
When you click 5min then go back to 1min, the arrows have disappeared!
Really really appreciate your time and help.
The code works here for a single arrow on chart.
Put it on a chart, waited for signal arrow, changed timeframes up and down.
Arrow remains on chart.
There is no ObjectDelete() in the code so your arrows shouldn't disappear.
phy,
You inadvertedly helped me find the solution...
In the last indicator I made, I put ObjectsDeleteAll(); which had an affect on this indicator.
Cheers bro, I'll helped out around here when I can :)
Appreciate it.
You inadvertedly helped me find the solution...
In the last indicator I made, I put ObjectsDeleteAll(); which had an affect on this indicator.
Cheers bro, I'll helped out around here when I can :)
Appreciate it.
Yup.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Let's say 3 arrows have popped up on the 1 min chart, and then I click on 5min and back to 1min..... the arrows have disappeared!!!
Is this a variable storage problem? Here's some code...
(above) extern int arrowCount = 1;
Any ideas??