Forex
Google
New signals service!

Go Back   Forex Trading > Programming > Metatrader Programming


Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
LinkBack (1) Thread Tools Display Modes
  #1181 (permalink)  
Old 08-22-2008, 05:23 AM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
Quote:
Originally Posted by hiachiever View Post
Matrixebiz,

if you want to start at 6 and go back to 0 then use i--

(int i=6; i>0; i--)

This will start at 6, decrement by 1 on each loop for as long as I > 0.
If you want to include 0 then use i>=0.

Cheers,
Hiachiever
Ok, so if I put if (int i=6; i>0; i++)
then it will start at 6 then , start over incrementing 1, 2, 3 ... 6, correct?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1182 (permalink)  
Old 08-22-2008, 05:37 AM
Member
 
Join Date: Jan 2006
Posts: 56
hiachiever is on a distinguished road
Quote:
Originally Posted by matrixebiz View Post
Ok, so if I put if (int i=6; i>0; i++)
then it will start at 6 then , start over incrementing 1, 2, 3 ... 6, correct?
No quite if what you are wanting to do there is finish at 6.

The the code in this case would be
For (int i=1; i<=6; i++)

This will start at 1 and finish at 6 incrementing by 1 on each loop.

Cheers,
Hiachiever

Last edited by hiachiever; 08-22-2008 at 05:55 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1183 (permalink)  
Old 08-22-2008, 06:06 AM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
I'm trying to figure out if this is wrong;
for (int i=qqea_alert_x_candles_ago; i>0; i--) {
// int i = 1;
qqea_up = iCustom(NULL,0,"QQE Alert v3",0,i);
qqea_down = iCustom(NULL,0,"QQE Alert v3",1,i);

if (qqea_up < qqea_down) {
if (i == 1) qqeacross = True;
qqea_long = True;
qqea_short = False;
} else if (qqea_up > qqea_down) {
if (i == 1) qqeacross = True;
qqea_long = False;
qqea_short = True;
}
}
}

it should check for valid signal upto "qqea_alert_x_candles_ago" bars back, but then it has (i == 1) which i==1 only happens once ??
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1184 (permalink)  
Old 08-22-2008, 10:24 AM
Member
 
Join Date: Jan 2006
Posts: 56
hiachiever is on a distinguished road
Quote:
Originally Posted by matrixebiz View Post
I'm trying to figure out if this is wrong;

for (int i=qqea_alert_x_candles_ago; i>0; i--) {
// int i = 1;
qqea_up = iCustom(NULL,0,"QQE Alert v3",0,i);
qqea_down = iCustom(NULL,0,"QQE Alert v3",1,i);
Print("qqea_up: ", qqea_up, "qqea_down: ", qqea_down);

if (qqea_up < qqea_down) {
if (i == 1) qqeacross = True;
qqea_long = True;
qqea_short = False;
} else if (qqea_up > qqea_down) {
if (i == 1) qqeacross = True;
qqea_long = False;
qqea_short = True;
}
}
}

it should check for valid signal upto "qqea_alert_x_candles_ago" bars back, but then it has (i == 1) which i==1 only happens once ??
At face value your code looks alright, that is assuming "qqea_alert_x_candles_ago" > 0.
Your problem if this is not working is more than likley in relation to iCustom.
For this function to work correctly you need to pass an input element for every input element in the actual indicator. If you don't do this, or pass the wrong data types then icustom will return nothing.

I have added a Print statement into the code above. Use this to determine if the values returned from iCustom actually contain anything.

Cheers,
Hiachiever
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1185 (permalink)  
Old 08-22-2008, 11:30 AM
Member
 
Join Date: Jan 2008
Posts: 47
Pussy Galore is on a distinguished road
Help needed with code to count bars

My EA has a number of options to calculate the stoploss of an open position. One of those options is to use the low of last "x" number of price bars.

The line of code currently used within the EA to calculate the stoploss (SL) of this option for a long position is:

SL=iLow(Symbol(),Period(),iLowest(Symbol(),Period( ),MODE_LOW,StopLossBars,0));

StopLossBars is an externally input variable.

The problem I have is that I want the value of StopLossBars to increase with every bar counted since the position was opened until one of my other conditions for stoploss over rides this condition. I guess a line of code such as:

StopLossBars = StopLossBars + BarsCountedSincePositionOpened

would do the trick. Unfortunately my coding is pretty limited to cut'n'paste and I don't know how to calculate or code BarsCountedSincePositionOpened.

Could somebody tell me how to do it please?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1186 (permalink)  
Old 08-22-2008, 01:21 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
Quote:
Originally Posted by hiachiever View Post
At face value your code looks alright, that is assuming "qqea_alert_x_candles_ago" > 0.
Your problem if this is not working is more than likley in relation to iCustom.
For this function to work correctly you need to pass an input element for every input element in the actual indicator. If you don't do this, or pass the wrong data types then icustom will return nothing.

I have added a Print statement into the code above. Use this to determine if the values returned from iCustom actually contain anything.

Cheers,
Hiachiever
The code is from another EA but I was thinking that when the loop goes to "qqea_alert_x_candles_ago" > 1 then this statement "if (i == 1) qqeacross = True;" would be False now, correct? When it should stay True until i>qqea_alert_x_candles_ago.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1187 (permalink)  
Old 08-22-2008, 05:55 PM
Junior Member
 
Join Date: Nov 2007
Posts: 2
RogerioMolinario is on a distinguished road
Helping

Dear all,

I got this coding from a colleague. He told me, that should be a very good Indicator signaling SMA up or down entries. Can somebody help me to create an indicator with this coding below.

/*[[
Name := SMA Up and Down
Separate Window := no
First Color := Blue
First Draw Type := Line
Use Second Data := Yes
Second Color := Red
Second Draw Type := Line
]]*/
Inputs : MAPeriod(10), Bandwide_UP(20),Bandwide_DOWN(20);
Variables : shift(0), cnt(0), sum(0), loopbegin1(0), loopbegin2(0), first(True), prevbars(0);
Variables : MA(0);

SetLoopCount(0);
// initial checkings
If MAPeriod < 1 Then Exit;
// check for additional bars loading or total reloading
If Bars < prevbars Or Bars-prevbars>1 Then first = True;
prevbars = Bars;
// loopbegin1 and loopbegin2 prevent couning of counted bars exclude current
If first Then Begin
loopbegin1 = Bars-MAPeriod-1;
If loopbegin1 < 0 Then Exit; // not enough bars for counting
loopbegin2 = Bars-MAPeriod-1;
If loopbegin2 < 0 Then Exit; // not enough bars for counting
first = False; // this block is to be evaluated once only
End;

// convergence-divergence
loopbegin1 = loopbegin1+1; // current bar is to be recounted too
For shift = loopbegin1 Downto 0 Begin
MA = iMA(MAPeriod,MODE_SMA,shift);
SetIndexValue(shift,(MA+Bandwide_UP*point));
SetIndexValue2(shift,(MA-Bandwide_DOWN*point));
loopbegin1 = loopbegin1-1; // prevent to previous bars recounting
End;

Best regards,
Rogerio
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1188 (permalink)  
Old 08-23-2008, 12:49 AM
Junior Member
 
Join Date: Apr 2008
Posts: 18
denis68 is on a distinguished road
help needed with code

i need help with the following code at the moment it only opens a order if AC is above or below zero and i want it to open if red changes to green and visa verser

double AC1 = iAC(NULL, 0, Current + 0);
double AC2 = iAC(NULL, 0, Current + 1);

if ((AC1 < AC2)) Order = SIGNAL_CLOSEBUY;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1189 (permalink)  
Old 08-23-2008, 12:57 AM
Member
 
Join Date: Jan 2006
Posts: 56
hiachiever is on a distinguished road
Quote:
Originally Posted by matrixebiz View Post
The code is from another EA but I was thinking that when the loop goes to "qqea_alert_x_candles_ago" > 1 then this statement "if (i == 1) qqeacross = True;" would be False now, correct? When it should stay True until i>qqea_alert_x_candles_ago.
No that isn't correct.

In the for loop you are starting at 6 and decrementing to 1. This means in the final loop the for loop executes it carries out the "if (i == 1) qqeacross = True;" check. End result is that the output will be true if qqeacross has occurred.

The only problem that this may present is if qqeacross was set to true in a previous looop. To overcome this you should have qqeacross = false; prior to the for loop. In this way you can ensure that if qqeacross = true, then it was set by the loop just completed.

Cheers,
hiachiever
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #1190 (permalink)  
Old 08-23-2008, 01:09 AM
Member
 
Join Date: Jan 2006
Posts: 56
hiachiever is on a distinguished road
Post

Quote:
Originally Posted by Pussy Galore View Post
My EA has a number of options to calculate the stoploss of an open position. One of those options is to use the low of last "x" number of price bars.

The line of code currently used within the EA to calculate the stoploss (SL) of this option for a long position is:

SL=iLow(Symbol(),Period(),iLowest(Symbol(),Period( ),MODE_LOW,StopLossBars,0));

StopLossBars is an externally input variable.

The problem I have is that I want the value of StopLossBars to increase with every bar counted since the position was opened until one of my other conditions for stoploss over rides this condition. I guess a line of code such as:

StopLossBars = StopLossBars + BarsCountedSincePositionOpened

would do the trick. Unfortunately my coding is pretty limited to cut'n'paste and I don't know how to calculate or code BarsCountedSincePositionOpened.

Could somebody tell me how to do it please?

The way to do it is create a vriable on global scope (ie before init)
eg
int BarCount;

int init ()


Then in your stop loss code use the following:

if (BarCount<Bars)
{
SL=iLow(Symbol(),Period(),iLowest(Symbol(),Period( ),MODE_LOW,StopLossBars,0));
StopLossBars++;
BarCount=Bars;
}

This will increment StopLossBars by 1 on each new bar.

The only other addition to your code would be to reset 'StopLossBars' back its original default value when a new trade is opened.

Cheers,
Hiachiever
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
candle time, CHinGsMAroonCLK, coders guru, expert advisor, forex, how to code, I_XO_A_H, mechanical trading, trading

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-programming/554-how-code.html
Posted By For Type Date
Need an experienced programmer? - Page 2 Post #0 Refback 09-24-2008 07:24 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code this? iscuba11 Metatrader 4 mql 4 - Development course 1 08-03-2007 05:22 PM


All times are GMT. The time now is 12:09 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.