once per bar doesnt fit! You mean like this ? [alt text](
image url)
Latest posts made by zerrow
-
RE: If indicators condition met, buy just onceposted in Questions & Answers
-
If indicators condition met, buy just onceposted in Questions & Answers

EA keeps buying continuosly
-
RE: Get Custom indicator valuesposted in Questions & Answers
Thank you for answer, Here it is indicator code:
#property copyright "" #property link "" #property indicator_separate_window #property indicator_buffers 4 #property indicator_color1 Red #property indicator_color2 Blue #property indicator_color3 Gray #property indicator_color4 Gray #property indicator_levelcolor MediumOrchid //extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame to use enum enTimeFrames { tf_cu = 0, // Current time frame tf_m1 = PERIOD_M1, // 1 minute tf_m5 = PERIOD_M5, // 5 minutes tf_m15 = PERIOD_M15, // 15 minutes tf_m30 = PERIOD_M30, // 30 minutes tf_h1 = PERIOD_H1, // 1 hour tf_h4 = PERIOD_H4, // 4 hours tf_d1 = PERIOD_D1, // Daily tf_w1 = PERIOD_W1, // Weekly tf_mb1 = PERIOD_MN1, // Monthly tf_next = -1, // Automatic next time frame tf_next2 = -2 }; extern enTimeFrames TimeFrame = tf_cu; // Time frame to use //extern ENUM_TIMEFRAMES TimeFrame=PERIOD_CURRENT; extern int Processed = 2000; extern int Control_Period = 14; extern int Signal_Period = 5; extern int Signal_Method = MODE_SMA; extern int BB_Up_Period = 12; extern int BB_Up_Deviation = 2; extern int BB_Dn_Period = 12; extern int BB_Dn_Deviation = 2; extern double levelOb = 6; extern double levelOs = -6; extern double extremelevelOb = 10; extern double extremelevelOs = -10; extern bool alertsOn = false; extern bool alertsOnObOs = false; extern bool alertsOnExtremeObOs = true; extern bool alertsOnCurrent = false; extern bool alertsMessage = true; extern bool alertsSound = true; extern bool alertsEmail = false; extern bool alertsNotify = false; extern string soundfile = "alert2.wav"; extern bool arrowsVisible = true; extern string arrowsIdentifier = "vertex arrows1"; extern double arrowsUpperGap = 0.1; extern double arrowsLowerGap = 0.01; extern bool arrowsOnObOs = true; extern color arrowsObOsUpColor = LimeGreen; extern color arrowsObOsDnColor = Red; extern int arrowsObOsUpCode = 221; extern int arrowsObOsDnCode = 222; extern int arrowsObOsUpSize = 3; extern int arrowsObOsDnSize = 3; extern bool arrowsOnExtremeObOs = true; extern color arrowsExtremeObOsUpColor = DeepSkyBlue; extern color arrowsExtremeObOsDnColor = PaleVioletRed; extern int arrowsExtremeObOsUpCode = 179; extern int arrowsExtremeObOsDnCode = 179; extern int arrowsExtremeObOsUpSize = 5; extern int arrowsExtremeObOsDnSize = 5; extern bool Interpolate = true; double values[]; double signal[]; double band_up[]; double band_dn[]; double trend1[]; double trend2[]; string indicatorFileName; bool returnBars; int init() { if (TimeFrame == -1) switch(Period()) { case 1: TimeFrame = 5 ; break; case 5: TimeFrame = 15 ; break; case 15: TimeFrame = 30 ; break; case 30: TimeFrame = 60 ; break; case 60: TimeFrame = 240 ; break; case 240: TimeFrame = 1440 ; break; case 1440: TimeFrame = 10080 ; break; case 10080: TimeFrame = 43200 ; break; default : TimeFrame = Period(); } if (TimeFrame == -2) switch(Period()) { case 1: TimeFrame = 15 ; break; case 5: TimeFrame = 30 ; break; case 15: TimeFrame = 60 ; break; case 30: TimeFrame = 240 ; break; case 60: TimeFrame = 1440 ; break; case 240: TimeFrame = 10080 ; break; case 1440: TimeFrame = 43200 ; break; case 10080: TimeFrame = 43200 ; break; default : TimeFrame = Period(); } IndicatorBuffers(6); SetIndexBuffer(0, values); SetIndexBuffer(1, signal); SetIndexBuffer(2, band_up); SetIndexBuffer(3, band_dn); SetIndexBuffer(4, trend1); SetIndexBuffer(5, trend2); SetLevelValue(0,levelOb); SetLevelValue(1,levelOs); SetLevelValue(2,extremelevelOb); SetLevelValue(3,extremelevelOs); indicatorFileName = WindowExpertName(); returnBars = TimeFrame == -99; TimeFrame = MathMax(TimeFrame,_Period); return (0); } int deinit() { deleteArrows(); return(0); } // // // // // int start() { int counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; int limit=MathMin(Bars-counted_bars,Bars-1); if (returnBars) { values[0] = limit+1; return(0); } if (TimeFrame!=_Period) { limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,TimeFrame,indicatorFileName,-99,0,0)*TimeFrame/Period())); for (int i=limit; i>=0; i--) { int y = iBarShift(NULL,TimeFrame,Time[i]); values[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,Processed,Control_Period,Signal_Period,Signal_Method,BB_Up_Period,BB_Up_Deviation,BB_Dn_Period,BB_Dn_Deviation,levelOb,levelOs,extremelevelOb,extremelevelOs, alertsOn,alertsOnObOs,alertsOnExtremeObOs,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,alertsNotify,soundfile,arrowsVisible,arrowsIdentifier,arrowsUpperGap,arrowsLowerGap, arrowsOnObOs,arrowsObOsUpColor,arrowsObOsDnColor,arrowsObOsUpCode,arrowsObOsDnCode,arrowsObOsUpSize,arrowsObOsDnSize,arrowsOnExtremeObOs,arrowsExtremeObOsUpColor,arrowsExtremeObOsDnColor, arrowsExtremeObOsUpCode,arrowsExtremeObOsDnCode,arrowsExtremeObOsUpSize,arrowsExtremeObOsDnSize,0,y); signal[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,Processed,Control_Period,Signal_Period,Signal_Method,BB_Up_Period,BB_Up_Deviation,BB_Dn_Period,BB_Dn_Deviation,levelOb,levelOs,extremelevelOb,extremelevelOs, alertsOn,alertsOnObOs,alertsOnExtremeObOs,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,alertsNotify,soundfile,arrowsVisible,arrowsIdentifier,arrowsUpperGap,arrowsLowerGap, arrowsOnObOs,arrowsObOsUpColor,arrowsObOsDnColor,arrowsObOsUpCode,arrowsObOsDnCode,arrowsObOsUpSize,arrowsObOsDnSize,arrowsOnExtremeObOs,arrowsExtremeObOsUpColor,arrowsExtremeObOsDnColor, arrowsExtremeObOsUpCode,arrowsExtremeObOsDnCode,arrowsExtremeObOsUpSize,arrowsExtremeObOsDnSize,1,y); band_up[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,Processed,Control_Period,Signal_Period,Signal_Method,BB_Up_Period,BB_Up_Deviation,BB_Dn_Period,BB_Dn_Deviation,levelOb,levelOs,extremelevelOb,extremelevelOs, alertsOn,alertsOnObOs,alertsOnExtremeObOs,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,alertsNotify,soundfile,arrowsVisible,arrowsIdentifier,arrowsUpperGap,arrowsLowerGap, arrowsOnObOs,arrowsObOsUpColor,arrowsObOsDnColor,arrowsObOsUpCode,arrowsObOsDnCode,arrowsObOsUpSize,arrowsObOsDnSize,arrowsOnExtremeObOs,arrowsExtremeObOsUpColor,arrowsExtremeObOsDnColor, arrowsExtremeObOsUpCode,arrowsExtremeObOsDnCode,arrowsExtremeObOsUpSize,arrowsExtremeObOsDnSize,2,y); band_dn[i] = iCustom(NULL,TimeFrame,indicatorFileName,PERIOD_CURRENT,Processed,Control_Period,Signal_Period,Signal_Method,BB_Up_Period,BB_Up_Deviation,BB_Dn_Period,BB_Dn_Deviation,levelOb,levelOs,extremelevelOb,extremelevelOs, alertsOn,alertsOnObOs,alertsOnExtremeObOs,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,alertsNotify,soundfile,arrowsVisible,arrowsIdentifier,arrowsUpperGap,arrowsLowerGap, arrowsOnObOs,arrowsObOsUpColor,arrowsObOsDnColor,arrowsObOsUpCode,arrowsObOsDnCode,arrowsObOsUpSize,arrowsObOsDnSize,arrowsOnExtremeObOs,arrowsExtremeObOsUpColor,arrowsExtremeObOsDnColor, arrowsExtremeObOsUpCode,arrowsExtremeObOsDnCode,arrowsExtremeObOsUpSize,arrowsExtremeObOsDnSize,3,y); if (!Interpolate || y==iBarShift(NULL,TimeFrame,Time[i-1])) continue; // // // // // datetime time = iTime(NULL,TimeFrame,y); for(int n = 1; i+n < Bars && Time[i+n] >= time; n++) continue; for(int j = 1; j < n; j++) { values[i+j] = values[i] + (values[i+n] - values[i] )*j/n; signal[i+j] = signal[i] + (signal[i+n] - signal[i] )*j/n; band_up[i+j] = band_up[i] + (band_up[i+n] - band_up[i])*j/n; band_dn[i+j] = band_dn[i] + (band_dn[i+n] - band_dn[i])*j/n; } } return(0); } datetime bar_time; int idx, counter, offset, bar_shft, bar_cont; double price_high, price_close, price_low, trigger_high, trigger_low; double sum_up, sum_dn, complex_up, complex_dn; int counted = IndicatorCounted(); if (counted < 0) return (-1); if (counted > 0) counted--; limit = Bars - counted; if (limit > Processed) limit = Processed; for (idx = limit; idx >= 0; idx--) { counter = 0; complex_up = 0; complex_dn = 0; trigger_high = -999999; trigger_low = 999999; while (counter < Control_Period) { sum_up = 0; sum_dn = 0; offset = idx + counter; bar_time = iTime(Symbol(), 0, offset); bar_shft = iBarShift(Symbol(), 0, bar_time, FALSE); bar_cont = bar_shft - Period(); if (bar_cont < 0) bar_cont = 0; for (int jdx = bar_shft; jdx >= bar_cont; jdx--) { price_high = iHigh(Symbol(), 0, jdx); price_close = iClose(Symbol(), 0, jdx); price_low = iLow(Symbol(), 0, jdx); if (price_high > trigger_high) {trigger_high = price_high; sum_up += price_close;} if (price_low < trigger_low ) {trigger_low = price_low; sum_dn += price_close;} } counter++; complex_up += sum_up; complex_dn += sum_dn; } if (complex_dn != 0.0 && complex_up != 0.0) values[idx] = complex_dn / complex_up - complex_up / complex_dn; } for (idx = limit; idx >= 0; idx--) { signal[idx] = iMAOnArray(values, 0, Signal_Period, 0, Signal_Method, idx); band_up[idx] = iBandsOnArray(values, 0, BB_Up_Period, BB_Up_Deviation, 0, MODE_UPPER, idx); band_dn[idx] = iBandsOnArray(values, 0, BB_Dn_Period, BB_Dn_Deviation, 0, MODE_LOWER, idx); trend1[idx] = trend1[idx+1]; trend2[idx] = trend2[idx+1]; if (values[idx]>levelOb) trend1[idx] =-1; if (values[idx]<levelOs) trend1[idx] = 1; if (values[idx]>extremelevelOb) trend2[idx] =-1; if (values[idx]<extremelevelOs) trend2[idx] = 1; // // // // // if (arrowsVisible) { ObjectDelete(arrowsIdentifier+":1:"+Time[idx]); ObjectDelete(arrowsIdentifier+":2:"+Time[idx]); string lookFor = arrowsIdentifier+":"+Time[idx]; ObjectDelete(lookFor); if (arrowsOnObOs && trend1[idx] != trend1[idx+1]) { if (trend1[idx] == 1) drawArrow("1",0.5,idx,arrowsObOsUpColor,arrowsObOsUpCode,arrowsObOsUpSize,false); if (trend1[idx] ==-1) drawArrow("1",0.5,idx,arrowsObOsDnColor,arrowsObOsDnCode,arrowsObOsDnSize, true); } if (arrowsOnExtremeObOs && trend2[idx] != trend2[idx+1]) { if (trend2[idx] == 1) drawArrow("2",1,idx,arrowsExtremeObOsUpColor,arrowsExtremeObOsUpCode,arrowsExtremeObOsUpSize,false); if (trend2[idx] ==-1) drawArrow("2",1,idx,arrowsExtremeObOsDnColor,arrowsExtremeObOsDnCode,arrowsExtremeObOsDnSize, true); } } } // // // // // if (alertsOn) { if (alertsOnCurrent) int whichBar = 0; else whichBar = 1; // // // // // static datetime time1 = 0; static string mess1 = ""; if (alertsOnObOs && trend1[whichBar] != trend1[whichBar+1]) { if (trend1[whichBar] == 1) doAlert(time1,mess1,whichBar,"crossing oversold"); if (trend1[whichBar] == -1) doAlert(time1,mess1,whichBar,"crossing overbought"); } static datetime time2 = 0; static string mess2 = ""; if (alertsOnExtremeObOs && trend2[whichBar] != trend2[whichBar+1]) { if (trend2[whichBar] == 1) doAlert(time2,mess2,whichBar,"crossing extreme oversold"); if (trend2[whichBar] == -1) doAlert(time2,mess2,whichBar,"crossing extreme overbought"); } } return (0); } // // // // // void drawArrow(string nameAdd, double gapMul, int i,color theColor,int theCode,int theWidth,bool up) { string name = arrowsIdentifier+":"+nameAdd+":"+Time[i]; double gap = iATR(NULL,0,20,i)*gapMul; // // // // // ObjectCreate(name,OBJ_ARROW,0,Time[i],0); ObjectSet(name,OBJPROP_ARROWCODE,theCode); ObjectSet(name,OBJPROP_COLOR,theColor); ObjectSet(name,OBJPROP_WIDTH,theWidth); if (up) ObjectSet(name,OBJPROP_PRICE1,High[i] + arrowsUpperGap * gap); else ObjectSet(name,OBJPROP_PRICE1,Low[i] - arrowsLowerGap * gap); } // // // // // void deleteArrows() { string lookFor = arrowsIdentifier+":"; int lookForLength = StringLen(lookFor); for (int i=ObjectsTotal()-1; i>=0; i--) { string objectName = ObjectName(i); if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName); } } // // // // // void doAlert(datetime& previousTime, string& previousAlert, int forBar, string doWhat) { string message; if (previousAlert != doWhat || previousTime != Time[forBar]) { previousAlert = doWhat; previousTime = Time[forBar]; // // // // // message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," Vertex ",doWhat); if (alertsMessage) Alert(message); if (alertsNotify) SendNotification(message); if (alertsEmail) SendMail(StringConcatenate(Symbol()," Vertex "),message); if (alertsSound) PlaySound(soundfile); } } -
Get Custom indicator valuesposted in Questions & Answers
Hello,
I have this in custom indicator code:Insert Code Here //extern ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT; // Time frame to use enum enTimeFrames { tf_cu = 0, // Current time frame tf_m1 = PERIOD_M1, // 1 minute tf_m5 = PERIOD_M5, // 5 minutes tf_m15 = PERIOD_M15, // 15 minutes tf_m30 = PERIOD_M30, // 30 minutes tf_h1 = PERIOD_H1, // 1 hour tf_h4 = PERIOD_H4, // 4 hours tf_d1 = PERIOD_D1, // Daily tf_w1 = PERIOD_W1, // Weekly tf_mb1 = PERIOD_MN1, // Monthly tf_next = -1, // Automatic next time frame tf_next2 = -2 }; extern enTimeFrames TimeFrame = tf_cu; // Time frame to usefxdreema cant recognise:
" extern enTimeFrames TimeFrame = tf_cu; // Time frame to use"tf_cu and i HAVE ERRORS when compiling


-
RE: Indicator buffer valuesposted in Questions & Answers
We have just two output buffers I need:
double up[], dn[]
and condition 1:
if ( dn[1] != 0 ) and
condition 2 :
if ( up[1] != 0 )
In condition block:
left side: My indicators/my indicator/Indicator mode (buffer) value 0:Downpinbar
right side: != Value/numeric/=0EA doesnt pick up indicator values.
The code is pretty simple :
#property copyright "smjones" #property link "" #property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 Red #property indicator_color2 Aqua #property indicator_color3 White #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 1 extern bool AlertOn = true; extern int Offset = 10; extern double PBRatio = 0.8; //extern double PBTail = 0.25; //extern int TailBarsBack = 2; extern double Entry = 0.50; datetime alertonce = 0; double up[], dn[], ExtMapBuffer1[]; int mult = 1; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators if (Digits == 3 || Digits == 5) mult = 10; SetIndexBuffer(0,dn); SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0, 234); SetIndexLabel(0,"Down PinBar"); SetIndexBuffer(1,up); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1, 233); SetIndexLabel(1,"UP PinBAR"); SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,119); SetIndexBuffer(2,ExtMapBuffer1); SetIndexLabel(2,"EntryPoint"+DoubleToStr(Entry*100,2)+"%"); //---- return(0); } //+----------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- Comment(""); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { double range,pb,tail; int limit; int counted_bars=IndicatorCounted(); //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(int i=0; i<limit; i++) { up[i] = 0; dn[i] = 0; ExtMapBuffer1[i] = 0; } for( i=0; i<limit; i++) { range = High[i+1]-Low[i+1]; pb = range * PBRatio; //tail = range * PBTail; if ( Open[i+1] >= High[i+1]-pb && Close[i+1] >= High[i+1]-pb) // && Low[i+2] > Low[i+1]+tail && Low[i+1] < Low[iLowest(NULL,0,MODE_LOW,TailBarsBack,i+2)] ) { up[i+1] = Low[i+1] - Offset*Point*mult; ExtMapBuffer1[i+1] = High[i+1]-((High[i+1] - Low[i+1]) * Entry); } if ( Open[i+1] <= High[i+1]-(range-pb) && Close[i+1] <= High[i+1]-(range-pb)) // && High[i+2] < High[i+1]-tail && High[i+1] > High[iHighest(NULL,0,MODE_HIGH,TailBarsBack,i+2)] ) { dn[i+1] = High[i+1] + Offset*Point*mult; ExtMapBuffer1[i+1] = ((High[i+1] - Low[i+1]) * Entry) + Low[i+1]; } } if ( AlertOn && alertonce!= Time[0] ) { if ( dn[1] != 0 ) { Alert(Symbol(), " M",Period()," Sell Pin Bar @ ", DoubleToStr((High[1]-Low[1])*Entry+Low[1],Digits), " ", TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS) ); alertonce = Time[0]; } if ( up[1] != 0 ) { Alert(Symbol(), " M",Period()," Buy Pin Bar @ ", DoubleToStr(High[1]-((High[1]-Low[1])*Entry),Digits), " ", TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS) ); alertonce = Time[0]; } } //---- //---- return(0); } //+------------------------------------------------------------------+ -
RE: Indicator buffer valuesposted in Questions & Answers
Hi, I use indicator from My indicators. The indicators test shows two out put buffers. Indicator values are double: 0 and 1. In condition block I use indicator value 0 and on the right side value == 0. I put ea on testing and add indicator with the same values as EA. Indicator works as I should, bet ea probably didnt pick up this value from indicator. Anu help please.