Coding help - page 351

 
mladen:
stevenpun For that it would be the easiest to add some "slope direction" buffer to that indicator or to use some other MACD that already has that slope solved in a buffer

How about this https://www.mql5.com/en/forum/178018/page67

But the problem what should i need to put in the code , i have google many ea but not success to find some example .

Please show me some example , thanks for helping .

 
stevenpun:
How about this https://www.mql5.com/en/forum/178018/page67

But the problem what should i need to put in the code , i have google many ea but not success to find some example .

Please show me some example , thanks for helping .

stevenpun

That would be a good example to use.

Read the "colors" buffer and when the value in it changes from -1 to 1 it is a signal to buy, and when the value changes from 1 to -1 it is a signal for sell (the "from" is the previous value of the colors buffer and "to" is the current value, or if you want to work with closed bars only, "from" is 2 bars ago and "to" is 1 bar ago)

 

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");

}

}

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

 

How to communicate between two or more EAs?

 

The newBie's trying to develop this to MT4 build 670. Help ~

Download the 'Three Moving Averages' Trading Robot (Expert Advisor) for MetaTrader 5 in MetaTrader Market ?

I like this because I like K.I.S.S. (keep it simple stupid)

I am a newbie and I would like to develop this.

(1. version_01)

When it runs, it places the position right away as soon as EA is on.

It is like reverse engineering from .ex5 to create .mq4.

(2. version_02)

On the same chart, visualize Weekly R & S that will be found from Zig-Zag.

(3. version_03)

Add logic,

--- don't enter above or below 20pips of trendline.

clear the position, at 20 pips apart from weekly R & S.

Your help will be grateful ~

Thanks in advance ~

 

cosmiclifeform, it is funny that I could not get the Nice TraderEA to back test since then,so i could not optimised it, I have done that on alpari demo and ista forex , the same....it keep on giving me blank result.Can u please tell me tips you use to backtest it.

cosmiclifeform:
Hi Mastercash,

I was able to download and run the NiceTrader EA in the Strategy Tester with no problems.

I just used the default settings and did not change anything...and did not get any error messages.

I did not try to run it real time on my demo...but this EA works fine with the Strategy Tester. See attached chart...

Do you get any log error messages or other clues why it's not trading for you...?

Hope this helps,

Robert

 
Mastercash:
cosmiclifeform, it is funny that I could not get the Nice TraderEA to back test since then,so i could not optimised it, I have done that on alpari demo and ista forex , the same....it keep on giving me blank result.Can u please tell me tips you use to backtest it.

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

 
apprentice coder:
How to communicate between two or more EAs?

If you mean if there is some function or set of functions dedicated for that, then the answer is, there is n such thing.

I have seen quite a few attempts and so far none of those way I have seen works in all the situations. Except one. But one is invented by me and since the idea is so simple that I still can not believe that nobody thought of it (it even provides communication of EAs that are not on the same location at all and does not use any API for that) then I am keeping that solution for me (in this case I am waiting to see if somebody thinks of the same thing)

Just try to think out of the expected bounds

 
mladen:
If you mean if there is some function or set of functions dedicated for that, then the answer is, there is n such thing.

I have seen quite a few attempts and so far none of those way I have seen works in all the situations. Except one. But one is invented by me and since the idea is so simple that I still can not believe that nobody thought of it (it even provides communication of EAs that are not on the same location at all and does not use any API for that) then I am keeping that solution for me (in this case I am waiting to see if somebody thinks of the same thing)

Just try to think out of the expected bounds

I know what you mean : ideas sometimes worth much more than the way how are they made after that. Thanks

 

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 ;-)

Files: