Coding help - page 352

 
freakout:
hello,

dear mladen, I have a small request to You - could you turn off all the info that indicator attached below shows in the left upper corner?

thanks in advance ;-)

Made an option to turn comments on/off.

Files:
 
paradise77:
Hi,

i am new here. I would like to update a rectangle object, but do not know how. The code below i used to create object rectangles, if EMAs crossed. These rectangle must be end if the price retrace back and touch it. How to do it ?

Thanks in advance.

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 clrLime

#property indicator_width1 2

#property indicator_color2 clrMagenta

#property indicator_width2 2

extern int EMA1 = 3;

extern int EMA2 = 21;

extern int EMA3 = 63;

extern double arrowDistance = 0.0003;

extern color upRectColor = clrYellow;

extern color dnRectColor = clrDodgerBlue;

extern color touchRectColor = clrDarkGray;

//---

extern double rectHigh = 0.0001;

extern int rectDays = 3;

extern int bars_limit = 2000;

extern bool showRectangle = true;

double upArrow[];

double dnArrow[];

double prev2EMA1, prev2EMA2, prev2EMA3;

double prevEMA1, prevEMA2, prevEMA3;

double curEMA1, curEMA2, curEMA3;

double prevOpenPrc, prevClosePrc, prevLowPrc, prevHighPrc;

string objRectName;

string rectArray[];

string indiName = "Emac";

int rectValidity = 0;

int arrayMaxAmounts = 99999;

int arrayCurAmount = 0;

int arrayLastAmount = 0;

//+------------------------------------------------------------------+

//| INIT() |

//+------------------------------------------------------------------+

int init() {

if (Period() != PERIOD_H1) {

Alert("Use only @ TF: H1");

return(0);

}

ArrayResize(rectArray,arrayMaxAmounts,arrayMaxAmounts);

IndicatorBuffers(2);

SetIndexBuffer(0,upArrow);

SetIndexBuffer(1,dnArrow);

SetIndexStyle(0,DRAW_ARROW);

SetIndexStyle(1,DRAW_ARROW);

SetIndexArrow(0,233);

SetIndexArrow(1,234);

SetIndexEmptyValue(0,0.0);

SetIndexEmptyValue(1,0.0);

SetIndexLabel(0,"Up");

SetIndexLabel(1,"Dn");

return(0);

}

//+------------------------------------------------------------------+

//| DEINIT() |

//+------------------------------------------------------------------+

int deinit() {

int k=0;

while (k<ObjectsTotal()) {

string objname = ObjectName(k);

if (StringSubstr(objname,0,StringLen("Emac")) == "Emac")

ObjectDelete(objname);

else

k++;

}

return(0);

}

//+------------------------------------------------------------------+

//| START() |

//+------------------------------------------------------------------+

int start() {

if (Period() != PERIOD_H1) {

Alert("Use only @ TF: H1");

return(0);

}

int limit,i,k;

int counted_bars=IndicatorCounted();

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//---

if (limit>bars_limit-1 && bars_limit!=0) limit=bars_limit-1;

if (Bars<EMA1 || Bars<EMA2 || Bars0 && bars_limit0 && bars_limit0 && bars_limit<EMA3)) {

Alert("Adjust limit settings or put more bars on your chart!");

return(0);

}

//---

for (i=0; i<limit; i++) {

prev2EMA1 = iMA(NULL,0,EMA1,0,MODE_EMA,PRICE_CLOSE,i+2);

prev2EMA2 = iMA(NULL,0,EMA2,0,MODE_EMA,PRICE_CLOSE,i+2);

prev2EMA3 = iMA(NULL,0,EMA3,0,MODE_EMA,PRICE_CLOSE,i+2);

prevEMA1 = iMA(NULL,0,EMA1,0,MODE_EMA,PRICE_CLOSE,i+1);

prevEMA2 = iMA(NULL,0,EMA2,0,MODE_EMA,PRICE_CLOSE,i+1);

prevEMA3 = iMA(NULL,0,EMA3,0,MODE_EMA,PRICE_CLOSE,i+1);

curEMA1 = iMA(NULL,0,EMA1,0,MODE_EMA,PRICE_CLOSE,i);

curEMA2 = iMA(NULL,0,EMA2,0,MODE_EMA,PRICE_CLOSE,i);

curEMA3 = iMA(NULL,0,EMA3,0,MODE_EMA,PRICE_CLOSE,i);

prevOpenPrc = iOpen(NULL,0,i+1);

prevClosePrc = iClose(NULL,0,i+1);

prevLowPrc = iLow(NULL,0,i+1);

prevHighPrc = iHigh(NULL,0,i+1);

rectValidity = rectDays*86400;

if ( (prev2EMA1=prevEMA2)&&(curEMA1>curEMA2)&&(prevEMA2>=prevEMA3)&&(curEMA2>curEMA3) ) { // up

upArrow = prevLowPrc - arrowDistance;

if (showRectangle == true) {

//----------------------- Draw Rectangle ----------------------

objRectName = StringConcatenate(indiName,"_",FuncPeriodToStr(Period()),"_",DoubleToStr(Time,0));

if (ObjectFind(objRectName) == -1) { // not exists

ObjectCreate(objRectName, OBJ_RECTANGLE, 0,Time,prevLowPrc,Time+rectValidity,prevLowPrc+rectHigh);

ObjectSet(objRectName, OBJPROP_COLOR, upRectColor);

ObjectSet(objRectName, OBJPROP_WIDTH, 0);

ObjectSet(objRectName, OBJPROP_STYLE, STYLE_SOLID);

//--- put information to Array ---

arrayCurAmount = ArraySize(rectArray);

rectArray[arrayCurAmount] = StringConcatenate(objRectName,"$up$",Time,"$",prevClosePrc,"$0"); // 0=new, not yet touched

} // if

} // if

} // if

if ( (prev2EMA1>prev2EMA2)&&(prevEMA1<=prevEMA2)&&(curEMA1<curEMA2)&&(prevEMA2<=prevEMA3)&&(curEMA2<curEMA3) ) { // down

dnArrow = prevHighPrc + arrowDistance;

if (showRectangle == true) {

//----------------------- Draw Rectangle ----------------------

objRectName = StringConcatenate(indiName,"_",FuncPeriodToStr(Period()),"_",DoubleToStr(Time,0));

if (ObjectFind(objRectName) == -1) { // not exists

ObjectCreate(objRectName, OBJ_RECTANGLE, 0, Time,prevHighPrc,Time+rectValidity,prevHighPrc-rectHigh);

ObjectSet(objRectName, OBJPROP_COLOR, dnRectColor);

ObjectSet(objRectName, OBJPROP_WIDTH, 0);

ObjectSet(objRectName, OBJPROP_STYLE, STYLE_SOLID);

//--- put information to Array ---

arrayCurAmount = ArraySize(rectArray);

rectArray[arrayCurAmount] = StringConcatenate(objRectName,"$dn$",Time,"$",prevClosePrc,"$0"); // 0=new, not yet touched

} // if

} // if

} // if

} // for

//----------------------- Edit Rectangle, change time2 & color, if price touched ----------------------

return(0);

} // start

//+------------------------------------------------------------------+

void DelObjects(string id) {

int ot1=ObjectsTotal();

while(ot1>=0) {

if (StringFind(ObjectName(ot1),id,0)>-1) {

ObjectDelete(ObjectName(ot1));

}

ot1--;

}

return;

}

//+------------------------------------------------------------------+

string FuncPeriodToStr(int thePeriod) {

switch(thePeriod) {

case 1: return("M1");

case 5: return("M5");

case 15: return("M15");

case 30: return("M30");

case 60: return("H1");

case 240: return("H4");

case 1440: return("D1");

case 10080: return("W1");

case 43200: return("MN1");

default: return("MN1");

}

}

//+------------------------------------------------------------------+

@Mladen,

Could you please help me to give a clue about editing the rectangle ?

I found this :

*) Object Types - MQL4 Documentation

*) Object Properties - MQL4 Documentation

i can get the rectangle properties (time1, price1, time2, price2, color), then compare the price1 or price2 to current Ask/Bid price. If Ask/Bid price touch the price1 or price2, then must do following :

a) I do not need Array, but just looking at each rectangle object.

Delete the object, create it again using new time2 and newcolor.

b) How to know the candle position at OBJPROP_PRICE1 ? We are normally using "for" loop like

for (i=limit; i>0; i--)

how can we get the "i" of the bar that has price1 ?

c) If i do not delete and recreate the rectangle, can i just use ObjectSet to change the rectangle time2 and color ?

Thank you.

 
paradise77:
@Mladen,

Could you please help me to give a clue about editing the rectangle ?

I found this :

*) Object Types - MQL4 Documentation

*) Object Properties - MQL4 Documentation

i can get the rectangle properties (time1, price1, time2, price2, color), then compare the price1 or price2 to current Ask/Bid price. If Ask/Bid price touch the price1 or price2, then must do following :

a) I do not need Array, but just looking at each rectangle object.

Delete the object, create it again using new time2 and newcolor.

b) How to know the candle position at OBJPROP_PRICE1 ? We are normally using "for" loop like

how can we get the "i" of the bar that has price1 ?

c) If i do not delete and recreate the rectangle, can i just use ObjectSet to change the rectangle time2 and color ?

Thank you.

In your case your prices are OK. You have to use times to limit the boxes from left and right

 

Cosmiclifeform,

Thank you for this piece, actually I used instaforex demo.I downloaded the 1M prices fiest as the normal method.I then do the setting, using EURUSD, see the screenshorts below of the report tab and the log..

//reports, noting but zerp, why?

cosmiclifeform:
Hi Mastercash,

I ran the EA on a FXDD demo account...and did nothing special...just ran the EA in the Strategy Tester with default settings.

Wish I could help more...but without specific clues to track down (error logs, screen shots, and other conditions) it will be impossible to find out why you are getting blank results.

All I can recommend is...

First try a good EA in the tester that you know works fine.

This will establish that both your demo accounts and your procedures are OK.

Get your confidence first that everything works the way it is supposed to.

Then try your Nice TraderEA...and write down exactly what happens. Even a blank screen should have logs to check.

Try add PRINT and COMMENT statements everywhere...then check your logs again...both the EA tab and the Journal tab...

Also your COMMENT's will show up on the screen...so you should actually see your EA working or not.

The bottom line in getting good coding help...

Is to provide the most clues you can find to what is happening with your EA...

Keep trying everything possible...and let us know the results.

Take care,

Robert
Files:
backtest1.png  14 kb
backtest2.png  3 kb
 
mladen:
In your case your prices are OK. You have to use times to limit the boxes from left and right

Thanks mladen. Do you mean i must use the Time2 dynamically ? Time1, price1 & price2 is fixed. But Time2 is depend on current bar (i), and is moving, until the price touch rectangle, or it is more than default rectangle setting time.

In other words, it is impossible to change the color & time2 of a rectangle ?

Thanks

 
paradise77:
Thanks mladen. Do you mean i must use the Time2 dynamically ? Time1, price1 & price2 is fixed. But Time2 is depend on current bar (i), and is moving, until the price touch rectangle, or it is more than default rectangle setting time.

In other words, it is impossible to change the color & time2 of a rectangle ?

Thanks

paradise77

Yes, you must

That way you will always adjust the right border of the box (if it needs adjustment, of course)

 

Hello Mister Mladen and Mrtools.

I really do not like too many alerts because I rather like a visual system, so all that noise and popup windows only distract me. I only set on some alerts of the CCI when oversold or overbought, that's it.

But there is one alert which I would like to have, that is when 'my' SSA + MA makes a crossing with the MA, either upwards or downwards.

Another thing, I always add three levels to this lovely tool; of course the zeroline, 0.0, but also -0.3 and 0.3.

I would like also to acquire an alert when the SSA crosses the -0.3 level and the 0.3 level. The 0.0 level is not necessary.

As alert a simple sound and popup, that's all.

Thank you !

Files:
ssa__ma.mq4  5 kb
 
Wulong10:
Hello Mister Mladen and Mrtools.

I really do not like too many alerts because I rather like a visual system, so all that noise and popup windows only distract me. I only set on some alerts of the CCI when oversold or overbought, that's it.

But there is one alert which I would like to have, that is when 'my' SSA + MA makes a crossing with the MA, either upwards or downwards.

Another thing, I always add three levels to this lovely tool; of course the zeroline, 0.0, but also -0.3 and 0.3.

I would like also to acquire an alert when the SSA crosses the -0.3 level and the 0.3 level. The 0.0 level is not necessary.

As alert a simple sound and popup, that's all.

Thank you !

Wulong10

The thing with SSA is that it is a recalculating algorithm. Adding alerts to it is, at least that is my opinion, not wise since it will always change the place of crosses and sometimes the crosses will disappear completely. Better to use it in non-signaling mode (estimation only)

 

Hi Mladen,

I know the SSA recalculates on higher timeframes.

When I use it on the M5, it will change a bit, on the M15 a lot more, but on the M1 I have tested this indy a lot and I'm very satisfied with it. With my settings it really doesn't adapt a lot, in fact it is very accurate.

Of course when there is a long rise or a long fall of the price, it's not very reliable, but isn't that so with a lot of indicators ?

Then you use a simple moving average on the chart for safety matters ...

Maybe anybody else can't use the alerts, but I can.

The alerts of the CCI are not always right either, but it's only an indication what might happen next.

So, if the SSA would give an alert, it's up to me to decide what to do about it and I'm getting good at that.

Besides, I think I'm not the only one who is fond of the SSA ...

Crosses that disappear ? Not very often on the M1 and I have been watching that chart for days ...

So, I would really like the alerts, if possible.

Danke schön !

 
Wulong10:
Hi Mladen,

I know the SSA recalculates on higher timeframes.

When I use it on the M5, it will change a bit, on the M15 a lot more, but on the M1 I have tested this indy a lot and I'm very satisfied with it. With my settings it really doesn't adapt a lot, in fact it is very accurate.

Of course when there is a long rise or a long fall of the price, it's not very reliable, but isn't that so with a lot of indicators ?

Then you use a simple moving average on the chart for safety matters ...

Maybe anybody else can't use the alerts, but I can.

The alerts of the CCI are not always right either, but it's only an indication what might happen next.

So, if the SSA would give an alert, it's up to me to decide what to do about it and I'm getting good at that.

Besides, I think I'm not the only one who is fond of the SSA ...

Crosses that disappear ? Not very often on the M1 and I have been watching that chart for days ...

So, I would really like the alerts, if possible.

Danke schön !

Wulong10

SSA always recalculates (believe me since I was the one that made that dll to calculate it). There is no exception to that rule (does not matter what time frame you use it on).

Also, if the number of computations is set to > 1, it will recalculate all the bars. If the number of computations is set to 1, then at least "lag" bars are going to be recalculated

Reason: