Go Back   Forex-TSD > Programming > MetaTrader Programming
Forex Forum Register More recent Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #621 (permalink)  
Old 01-18-2008, 06:52 AM
Dan7974's Avatar
Senior Member
 
Join Date: Jul 2006
Posts: 267
Dan7974 is on a distinguished road
Why doesn't this work?

PHP Code:
int Highest;
double Place;

int Start()
 {
  
Highest=iHighest(Symbol(),0,MODE_HIGH,1,0);Place=iHigh(Symbol(),0,Highest);
  
  if(
Gate==0){
   if(
iClose(Symbol(),0,0)>=Place){
    
OrderModify(ticket3,Ask,Ask-TrailingStop*Point-Spread,0,0,Green);
    
Gate=1;}
    
    return(
0);
 } 
I get errors. I can't make a simple trailing stop!!!!!!!
__________________
God Bless Everyone, and their trading logic.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #622 (permalink)  
Old 01-18-2008, 11:42 AM
Senior Member
 
Join Date: May 2007
Posts: 177
dvarrin is on a distinguished road
HOW to Open an order at the beginning of a bar only ??

Hi,

I'm implementing an EA in which I want to open an order only if a cross of some level by an indicator has occured between the second previous bar and the previous one.

For example, on the daily chart, If there is a cross between the 18th of January and the 19th of January, I want to open an order on the 20th of January.

I did something like this:
When I open an order, I record the order open time.
Then I do the following test: Is (CurrentTime() - LastOrderOpenTime) < Period() ??

If yes, it means that the current bar is not finished, yet, and I shouldn't open a new order. And also, when this condition becomes false, I should be on the next bar of the chart, and the cross happened before the last bar and no order should be opened until the next signal.

The problem is that when attaching it to a chart, it keeps on creating new orders until the bar is finished. Anybody can tell me what I did wrong?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #623 (permalink)  
Old 01-18-2008, 05:10 PM
nondisclosure007's Avatar
Senior Member
 
Join Date: Apr 2007
Posts: 131
nondisclosure007 is on a distinguished road
Quote:
Originally Posted by dvarrin View Post
Hi,

I'm implementing an EA in which I want to open an order only if a cross of some level by an indicator has occured between the second previous bar and the previous one.

For example, on the daily chart, If there is a cross between the 18th of January and the 19th of January, I want to open an order on the 20th of January.

I did something like this:
When I open an order, I record the order open time.
Then I do the following test: Is (CurrentTime() - LastOrderOpenTime) < Period() ??

If yes, it means that the current bar is not finished, yet, and I shouldn't open a new order. And also, when this condition becomes false, I should be on the next bar of the chart, and the cross happened before the last bar and no order should be opened until the next signal.

The problem is that when attaching it to a chart, it keeps on creating new orders until the bar is finished. Anybody can tell me what I did wrong?
Not sure but here is what somone jotted done for me sometime ago. I'd have to google it to give proper props to the original writer.

It helps determine whether or not your on the opening of a new bar.

Code:
int newbar()
{
   double g;
   int m,s,k;
   m=Time[0]+Period()*60-TimeCurrent();
   g=m/60.0;
   s=m%60;
   m=(m-m%60)/60;
   return(m);
}
And I use it like this:
Code:
if (newbar()==Period())
Hope that helps.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #624 (permalink)  
Old 01-18-2008, 05:22 PM
Senior Member
 
Join Date: Oct 2006
Posts: 104
antone is on a distinguished road
Quote:
Originally Posted by dvarrin View Post
Hi,

I'm implementing an EA in which I want to open an order only if a cross of some level by an indicator has occured between the second previous bar and the previous one.

For example, on the daily chart, If there is a cross between the 18th of January and the 19th of January, I want to open an order on the 20th of January.

I did something like this:
When I open an order, I record the order open time.
Then I do the following test: Is (CurrentTime() - LastOrderOpenTime) < Period() ??

If yes, it means that the current bar is not finished, yet, and I shouldn't open a new order. And also, when this condition becomes false, I should be on the next bar of the chart, and the cross happened before the last bar and no order should be opened until the next signal.

The problem is that when attaching it to a chart, it keeps on creating new orders until the bar is finished. Anybody can tell me what I did wrong?

Then I do the following test: Is (CurrentTime() - LastOrderOpenTime) < Period() ??
you can add // return (0);

OR
this might help.. add the code..

Quote:
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == false) break;
if(OrderSymbol()== Symbol () && OrderMagicNumber()== MN)
{
if( OrderOpenTime() >= iTime(0, PERIOD_D1, 0) samebar++;
}
}
you can choose from the 2..
Quote:
if ( samebar > 0 ) return (0);

OR

if (samebar < 1) {your order codes;}
i am not good in coding so might anyone try check if i place the right codes..

Last edited by antone; 01-18-2008 at 05:32 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #625 (permalink)  
Old 01-18-2008, 07:02 PM
Dan7974's Avatar
Senior Member
 
Join Date: Jul 2006
Posts: 267
Dan7974 is on a distinguished road
Quote:
Originally Posted by dvarrin View Post
Hi,

I'm implementing an EA in which I want to open an order only if a cross of some level by an indicator has occured between the second previous bar and the previous one.

For example, on the daily chart, If there is a cross between the 18th of January and the 19th of January, I want to open an order on the 20th of January.

I did something like this:
When I open an order, I record the order open time.
Then I do the following test: Is (CurrentTime() - LastOrderOpenTime) < Period() ??

If yes, it means that the current bar is not finished, yet, and I shouldn't open a new order. And also, when this condition becomes false, I should be on the next bar of the chart, and the cross happened before the last bar and no order should be opened until the next signal.

The problem is that when attaching it to a chart, it keeps on creating new orders until the bar is finished. Anybody can tell me what I did wrong?
Ummm...
PHP Code:
if(iOpen(Symbol(),0,0)==iClose(Symbol(),0,0)&&iLow(Symbol(),0,0)==iHigh(Symbol(),0,0))
 {
  
//A new bar has happend.
  

__________________
God Bless Everyone, and their trading logic.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #626 (permalink)  
Old 01-18-2008, 07:03 PM
Dan7974's Avatar
Senior Member
 
Join Date: Jul 2006
Posts: 267
Dan7974 is on a distinguished road
How do I know the profit of the previous trade? And the lots, and the side?
__________________
God Bless Everyone, and their trading logic.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #627 (permalink)  
Old 01-18-2008, 07:16 PM
Senior Member
 
Join Date: Jan 2006
Posts: 1,117
omelette is on a distinguished road
Quote:
Originally Posted by Dan7974 View Post
How do I know the profit of the previous trade? And the lots, and the side?
Use OrdersHistoryTotal() instead of OrdersTotal(). Then use OrderProfit(), OrderLots() etc. You must make sure that historical quotes for the timeperiod you are interested in are loaded though, and I think you can only do this manually - right-click on the 'Orders History' tab and select 'All History'.

Should have added that you need to use 'MODE_HISTORY' with OrderSelect()...

Last edited by omelette; 01-18-2008 at 07:21 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #628 (permalink)  
Old 01-18-2008, 08:12 PM
Senior Member
 
Join Date: Feb 2006
Posts: 589
Michel is on a distinguished road
Quote:
Originally Posted by omelette View Post
Use OrdersHistoryTotal() instead of OrdersTotal(). Then use OrderProfit(), OrderLots() etc. You must make sure that historical quotes for the timeperiod you are interested in are loaded though, and I think you can only do this manually - right-click on the 'Orders History' tab and select 'All History'.

Should have added that you need to use 'MODE_HISTORY' with OrderSelect()...
Hi Omelette,
Do you know that BT have a problem looking in the history: it looks on the real history, not the one of the BT. I asked Metaquote few months ago about this bug but they didn't have any answer.... Maybe now it's fixed...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #629 (permalink)  
Old 01-19-2008, 07:51 AM
Banned
 
Join Date: Nov 2007
Posts: 374
oilfxpro is on a distinguished road
Hi

How do u code an interest rate tightening cycle on one currency ,and a interest rate reduction cycle on another currency?

Can EA look at swaps current and swaps historical rates?

OILFXPRO
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #630 (permalink)  
Old 01-19-2008, 12:45 PM
Junior Member
 
Join Date: Dec 2007
Posts: 8
manu29 is on a distinguished road
Help on function call

Hi,

I would like to replace the code of this indicator :

int start()
{
int bar, limit, i;
int counted_bars=IndicatorCounted();

if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;

//Hull average computation
for(i=0; i<limit; i++)
TempBuf1[i]=2*iMA(NULL,0,HalfHullPeriod,0,MODE_LWMA,PRICE_CLO SE,i)-iMA(NULL,0,HullPeriod,0,MODE_LWMA,PRICE_CLOSE,i);
for(i=0; i<limit; i++)
HullBuf[i]=iMAOnArray(TempBuf1,0,SqrtHullPeriod,0,MODE_LWMA, i);

//----
return(0);
}

by a call at a function like that :

double ComputeHull(double MyArray[], int MyPeriod)
{
double MyTemp[];
double result = -1;
int i;

int HalfPeriod = MathRound(MyPeriod/2);
int SqrtPeriod = MathRound(MathSqrt(MyPeriod));

//Copy Close Values to CloseTemp
ArrayResize(MyTemp, SqrtPeriod);
ArraySetAsSeries(MyTemp, true);

//HMA value computation
for(i=0; i<SqrtPeriod; i++)
{
MyTemp[i] = 2*iMAOnArray(MyArray, 0, HalfPeriod, 0, MODE_LWMA, i) - iMAOnArray(MyArray, 0, MyPeriod, 0, MODE_LWMA, i);
}
result = iMAOnArray(MyTemp, 0, SqrtPeriod, 0, MODE_LWMA, 0);

//---- done
return(result);
}

int start()
{
double CloseTemp[];
int bar, limit, i;
int counted_bars=IndicatorCounted();

if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;

ArrayResize(CloseTemp, HullPeriod+SqrtHullPeriod);
ArraySetAsSeries(CloseTemp, true);

for(i=0; i<limit; i++)
{
ArrayCopy(CloseTemp, Close, 0, i, HullPeriod+SqrtHullPeriod);
HullAntBuf[i]=ComputeHull(CloseTemp, HullPeriod);
}

//----
return(0);
}

I don't understand why the result is not the same. It is not a spécific problem about the HMA just i'd like to ompute my indicator in a spécific function where the array is passed in argument.

I've attached source code of an indicator which display the two curves, it's seems that it is the second call to iMAOnArray which done different results.

Please help me i don't understand the problem
Attached Files
File Type: mq4 HULL_ANTICIP.mq4 (3.8 KB, 13 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
#include, candle time, CHinGsMAroonCLK, code, coders guru, conditionally, crossover, dll, eli hayun, Eur_harvester.ex4, expert adviser, expert advisor, forex, Gann Hilo, higher high, how to code, indicator, I_XO_A_H, kehedge, mechanical trading, metatrader command line, mql4, mt4, MT4-LevelStop-Reverse, OrderReliable.mqh, programming, rectangle tool, strings, time range high low, trading, volty channel stop


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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 05:58 AM.



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