How to code? - page 39

 

mish

I had a moment of spare time, and made an attempt to capture your intention as I understood it.

Files:
advicerr.txt  2 kb
 

Thankyou

Thankyou ralph.ronnquist

these functions are exactly what I need and would be of use to others after a same function

I was caught up otherwise would have thanked you earlier especially because it took effort

Is there a simple way to change the function to work in strategy tester? I know the results of working with just one currency in the tester is next to useless except it mimics very roughly what I need in order to get the math right, any help is appreciated and I never would have worked the code out in short order so once again thankyou!

 

DT_ZZ.mq4-based EA

I'm having a little bit of trouble with this one.

I have the DT_ZZ.mq4 indicator and from what I see it's very promising. I do know that this indicator redraws and here's how I see it working.

If an arrow and section are equal, then wait for the bar to close, then buy/sell accordingly.

Anybody think they can help with that? (Code is posted below)

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

//| DT_ZZ.mq4 |

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

// optimized by Rosh

#property indicator_chart_window

#property indicator_buffers 3

#property indicator_color1 Green

#property indicator_color2 Blue

#property indicator_color3 Red

//---- indicator parameters

extern int ExtDepth=12;

extern int calculateLevel=2;

//---- indicator buffers

double zzL[];

double zzH[];

double zz[];

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

//| Custom indicator initialization function |

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

int init()

{

// IndicatorBuffers(3);

//---- drawing settings

SetIndexStyle(0,DRAW_SECTION);

SetIndexStyle(1,DRAW_ARROW);

SetIndexStyle(2,DRAW_ARROW);

SetIndexArrow(1,159);

SetIndexArrow(2,159);

//---- indicator buffers mapping

SetIndexBuffer(0,zz);

SetIndexBuffer(1,zzH);

SetIndexBuffer(2,zzL);

SetIndexEmptyValue(0,0.0);

SetIndexEmptyValue(1,0.0);

SetIndexEmptyValue(2,0.0);

//---- indicator short name

IndicatorShortName("DT_ZZ("+ExtDepth+")");

//---- initialization done

return(0);

}

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

//| |

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

int start()

{

int i,shift,pos,lasthighpos,lastlowpos,curhighpos,curlowpos;

double curlow,curhigh,lasthigh,lastlow;

double min, max;

int counted_bars=IndicatorCounted();

if (counted_bars==0)

{

ArrayInitialize(zz,0.0);

ArrayInitialize(zzL,0.0);

ArrayInitialize(zzH,0.0);

lasthighpos=Bars; lastlowpos=Bars;

lastlow=Low;lasthigh=High;

Print("limit=",Bars-ExtDepth);

for(shift=Bars-ExtDepth; shift>=0; shift--)

{

curlowpos=Lowest(NULL,0,MODE_LOW,ExtDepth,shift);

curlow=Low[curlowpos];

curhighpos=Highest(NULL,0,MODE_HIGH,ExtDepth,shift);

curhigh=High[curhighpos];

//------------------------------------------------

if( curlow>=lastlow ) { lastlow=curlow; }

else

{

//???? ????

if( lasthighpos>curlowpos )

{

zzL[curlowpos]=curlow;

///*

min=100000; pos=lasthighpos;

for(i=lasthighpos; i>=curlowpos; i--)

{

if (zzL==0.0) continue;

if (zzL<min) { min=zzL; pos=i; }

zz=0.0;

}

zz[pos]=min;

//*/

}

lastlowpos=curlowpos;

lastlow=curlow;

}

//--- high

if( curhigh<=lasthigh ) { lasthigh=curhigh;}

else

{

// ???? ?????

if( lastlowpos>curhighpos )

{

zzH[curhighpos]=curhigh;

///*

max=-100000; pos=lastlowpos;

for(i=lastlowpos; i>=curhighpos; i--)

{

if (zzH==0.0) continue;

if (zzH>max) { max=zzH; pos=i; }

zz=0.0;

}

zz[pos]=max;

//*/

}

lasthighpos=curhighpos;

lasthigh=curhigh;

}

zz[0]=Close[0];

}

//----------------------------------------------------------------------

}

else

{

int pos2;

i=0;

while (pos2<calculateLevel && i<Bars-1)

{

if (zz!=0 && (zzH!=0||zzL!=0)) pos2++;

i++;

}

pos2=i-1;

for (i=pos2-1;i>=0;i--)

{

zzH=0;

zzL=0;

zz=0;

}

if (zzH[pos2]!=0)

{

lasthighpos=pos2;

lasthigh=High[pos2];

lastlowpos=Lowest(NULL,0,MODE_LOW,ExtDepth,pos2);

lastlow=Low[lastlowpos];

}

else

{

lastlowpos=pos2;

lastlow=Low[pos2];

lasthighpos=Highest(NULL,0,MODE_HIGH,ExtDepth,pos2);

lasthigh=High[lasthighpos];

}

//------------------------- ????????? ??????

Print("limit=",pos2-1);

for(shift=pos2-1; shift>=0; shift--)

{

curlowpos=Lowest(NULL,0,MODE_LOW,ExtDepth,shift);

curlow=Low[curlowpos];

curhighpos=Highest(NULL,0,MODE_HIGH,ExtDepth,shift);

curhigh=High[curhighpos];

//------------------------------------------------

if( curlow>=lastlow ) { lastlow=curlow; }

else

{

//???? ????

if( lasthighpos>curlowpos )

{

zzL[curlowpos]=curlow;

///*

min=100000; pos=lasthighpos;

for(i=lasthighpos; i>=curlowpos; i--)

{

if (zzL==0.0) continue;

if (zzL<min) { min=zzL; pos=i; }

zz=0.0;

}

zz[pos]=min;

//*/

}

lastlowpos=curlowpos;

lastlow=curlow;

}

//--- high

if( curhigh<=lasthigh ) { lasthigh=curhigh;}

else

{

// ???? ?????

if( lastlowpos>curhighpos )

{

zzH[curhighpos]=curhigh;

///*

max=-100000; pos=lastlowpos;

for(i=lastlowpos; i>=curhighpos; i--)

{

if (zzH==0.0) continue;

if (zzH>max) { max=zzH; pos=i; }

zz=0.0;

}

zz[pos]=max;

//*/

}

lasthighpos=curhighpos;

lasthigh=curhigh;

}

}

//------------------------- ????????? ??????

zz[0]=Close[0];

}

return(0);

}

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

can this be altered 4 strategy tester?

ralph.ronnquist

has provided me generously a great function that many may benefit from that require it's use.

My problem is because I'm so lousy currently at programming I can't seem to alter it enough 4 strategy tester.

For testing purposes only one currency is satisfactory just to work out the math of trades under different circumstances with different currencies.

Is it possible to change ralph's work to suit this need.

Thankyou

Files:
ralph.txt  2 kb
 

In principle you would only need to change the string "EURCHF" to be "EURUSD". I.e., to work with long "EURUSD" versus short "EURUSD".

 

I've tried that

Thanks for your reply but I have tried to no avail. The code you provided has taught me and my girlfriend much about how little we know about programming!

Thankyou very much!

 

Hmm. The only "badness" I can see upfront is the test "v == cut", which compares two double numbers for equality. Perhaps it works better to only look at the full $ amounts, and thus change "euprofit", "ecprofit", "cut" and "v" to be of "int" type?

 
NTrader:
Trivial question: I'm writing a new Personal Indicator for the first time. I can't view my logs that I make with the command Print("...") in the start{} method. Where I can view them on MetaTrader 4?

Ok, I use Comment() command..

 

Dumbo here

Hi all

This is a great thread for someone like me who knows nothing about programming. It has much useful information and many little peices of code I could copy and play with.

I hope someone could help me out with this peice.I want to make an EA based on price. What do I enter in the code to tell the following:

1) I want the EA to look at price at 20:00 on the hour chart and see what it's relation is to the 100sma.

2)If price is above the 100sma, I want it to open 2 buy orders at certain level.

3) These levels are based on the closing price of the 16:00 candle, so if the 16:00 candle is 1.2000, I want it to open a buy at 1.1120 and 1.2080

I have the stops and trailing stops and profit levels all worked out and stuff, all codes taken from this thred. So I thank those who posted them. I

I will be forever debted if someone could help me out here.

Kind regards

Susan

 

Help

Hi, everyone

I tried to create an EA, and I got the following error message:

'\end_of_program' - ending bracket '}' expected C:\...\My_First_EA.mq4(96,1)

I double-clicked it, get to the line, then check it with opening-ending brackets prior to it, and still don't know where I made mistake.

This is the second EA I tried, with the same error message, based on the same indicator.

Thank you.

Reason: