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
  #951 (permalink)  
Old 05-22-2008, 06:06 PM
Junior Member
 
Join Date: Dec 2006
Posts: 2
DMMcCollum is on a distinguished road
How to append a prefix to an int declaration after it is created?

Is it possible to:

// from include file

#define CP1 “GBPJPY”
Int iMyInt = 10;

// end include file

Then….

Append CP1 as a prefix to the int declaration of iMyInt

So that…

GBPJPYiMyInt = = 10

Resulting in…

//library file

Void MyFunction(string sSymbol)
{
If (sSymbol = = CP1 )
iMyInt becomes GBPJPYiMyInt;
}

//end library file

// script

Myfunction( CP1 );


//end script



Thank you very much!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #952 (permalink)  
Old 05-22-2008, 10:44 PM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 723
wolfe is on a distinguished road
Hello everyone,

This is a stupid coding question, and I know I've seen it somewhere before, but I need help.

I'm coding a custom indicator, and all I want it to do is read the current bid price at ONLY THE BEGINNING of a NEW bar. I can't just use Open[0] because every time a new tick comes in it will keep returning the open value for the current bar. I want the value to be returned only once, until a new bar is formed.

I know I'm missing something quite simple here, but am having a bit of trouble figuring it out. Could someone help me?

Thanks,

-wolfe
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #953 (permalink)  
Old 05-23-2008, 03:24 AM
Senior Member
 
Join Date: Jan 2006
Posts: 1,119
omelette is on a distinguished road
Quote:
Originally Posted by wolfe View Post
Hello everyone,

This is a stupid coding question, and I know I've seen it somewhere before, but I need help.

I'm coding a custom indicator, and all I want it to do is read the current bid price at ONLY THE BEGINNING of a NEW bar. I can't just use Open[0] because every time a new tick comes in it will keep returning the open value for the current bar. I want the value to be returned only once, until a new bar is formed.

I know I'm missing something quite simple here, but am having a bit of trouble figuring it out. Could someone help me?

Thanks,

-wolfe
Just store the current bar time (Time[0]) - when this value changes, you have a new bar, so get your price, store new value and repeat...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #954 (permalink)  
Old 05-23-2008, 03:54 AM
wolfe's Avatar
Senior Member
 
Join Date: Jan 2006
Posts: 723
wolfe is on a distinguished road
Quote:
Originally Posted by omelette View Post
Just store the current bar time (Time[0]) - when this value changes, you have a new bar, so get your price, store new value and repeat...
Thanks omelette,

I should have thought of that, kinda disappointed in myself!

Thanks for the help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #955 (permalink)  
Old 05-25-2008, 06:23 AM
darkkiller's Avatar
Senior Member
 
Join Date: Jul 2007
Location: Malaysia
Posts: 207
darkkiller is on a distinguished road
Can someone else show me what im doing wrong to this code?
I would like to add more timeframe into it like timeframe Daily,but i do not know what wrong

Quote:
//+---------------------------------------------------------+
//| #MTF_Hi_Low_Middle.mq4
//| Base from spudfibo.Upgrade by Darkkiller
//: Thanks to Mladen for helping me to make some correction
//+------------------------------------------------------------------+
#property indicator_chart_window

extern string note1 = "H4 Higher,Middle,Lower colors";
extern color H4HigherColor = DeepSkyBlue;
extern color H4MiddleColor = Yellow;
extern color H4LowerColor = HotPink;
extern string note2 = "Draw H4 Higher,Lower and Middle?";
extern bool H4HiLow = true;
extern bool H4Mid = true;

extern string note3 = "D1 Higher,Middle,Lower colors";
extern color D1HigherColor = DeepSkyBlue;
extern color D1MiddleColor = Yellow;
extern color D1LowerColor = HotPink;
extern string note4 = "Draw D1 Higher,Lower and Middle?";
extern bool D1HiLow = true;
extern bool D1Mid = true;


double HiPrice, LoPrice, Range, D1HiPrice, D1LoPrice, D1Range;
datetime StartTime;

int init()
{
return(0);
}

int deinit()
{
ObjectDelete("H4Higher");
ObjectDelete("H4Lower");
ObjectDelete("H4Middle");

ObjectDelete("D1Higher");
ObjectDelete("D1Lower");
ObjectDelete("D1Middle");
return(0);
}


//+------------------------------------------------------------------+
//| Draw Fibo
//+------------------------------------------------------------------+

int DrawFibo()
{

///////////////////////////////////////////HILO/////
if(H4HiLow)
{

if(ObjectFind("H4Higher") == -1)
ObjectCreate("H4Higher", OBJ_FIBO, 0, StartTime, HiPrice+Range, StartTime, HiPrice);
else
{
ObjectSet("H4Higher",OBJPROP_TIME2, StartTime);
ObjectSet("H4Higher",OBJPROP_TIME1, StartTime);
ObjectSet("H4Higher",OBJPROP_PRICE1,HiPrice+Range) ;
ObjectSet("H4Higher",OBJPROP_PRICE2,HiPrice);
}
ObjectSet("H4Higher", OBJPROP_LEVELCOLOR, H4HigherColor);
ObjectSet("H4Higher", OBJPROP_FIBOLEVELS,1);
ObjectSet("H4Higher", OBJPROP_FIRSTLEVEL+0,0.0); ObjectSetFiboDescription("H4Higher", 0, "H4 HIGHER- %$");
ObjectSet("H4Higher", OBJPROP_RAY,true);
ObjectSet("H4Higher", OBJPROP_BACK,true);
ObjectSet("H4Higher", OBJPROP_COLOR,EMPTY);


if(ObjectFind("H4Lower") == -1)
ObjectCreate("H4Lower", OBJ_FIBO, 0, StartTime, LoPrice-Range, StartTime, LoPrice);
else
{
ObjectSet("H4Lower", OBJPROP_TIME2, StartTime);
ObjectSet("H4Lower", OBJPROP_TIME1, StartTime);
ObjectSet("H4Lower", OBJPROP_PRICE1,LoPrice-Range);
ObjectSet("H4Lower", OBJPROP_PRICE2,LoPrice);


}
ObjectSet("H4Lower", OBJPROP_LEVELCOLOR, H4LowerColor);
ObjectSet("H4Lower", OBJPROP_FIBOLEVELS, 1);
ObjectSet("H4Lower", OBJPROP_FIRSTLEVEL+0,0.0); ObjectSetFiboDescription("H4Lower", 0, "H4 LOWER - %$");
ObjectSet("H4Lower", OBJPROP_RAY, true);
ObjectSet("H4Lower", OBJPROP_BACK, true);
ObjectSet("H4Lower", OBJPROP_COLOR, EMPTY);

}



if(D1HiLow)
{

if(ObjectFind("D1Higher") == -1)
ObjectCreate("D1Higher", OBJ_FIBO, 0, D1StartTime, D1HiPrice+D1Range, D1StartTime, D1HiPrice);
else
{
ObjectSet("D1Higher", OBJPROP_TIME2, D1StartTime);
ObjectSet("D1Higher", OBJPROP_TIME1, D1StartTime);
ObjectSet("D1Higher", OBJPROP_PRICE1, D1HiPrice+D1Range);
ObjectSet("D1Higher", OBJPROP_PRICE2, D1HiPrice);
}
ObjectSet("D1Higher", OBJPROP_LEVELCOLOR, D1HigherColor);
ObjectSet("D1Higher", OBJPROP_FIBOLEVELS,1);
ObjectSet("D1Higher", OBJPROP_FIRSTLEVEL+0,0.0); ObjectSetFiboDescription("D1Higher", 0, "H4 HIGHER- %$");
ObjectSet("D1Higher", OBJPROP_RAY, true);
ObjectSet("D1Higher", OBJPROP_BACK, true);
ObjectSet("D1Higher", OBJPROP_COLOR, EMPTY);


if(ObjectFind("D1Lower") == -1)
ObjectCreate("D1Lower", OBJ_FIBO, 0, D1StartTime, D1LoPrice-D1Range, D1StartTime, 1LoPrice);
else
{
ObjectSet("D1Lower", OBJPROP_TIME2, D1StartTime);
ObjectSet("D1Lower", OBJPROP_TIME1, D1StartTime);
ObjectSet("D1Lower", OBJPROP_PRICE1, D1LoPrice-D1Range);
ObjectSet("D1Lower", OBJPROP_PRICE2, D1LoPrice);


}
ObjectSet("D1Lower", OBJPROP_LEVELCOLOR, D1LowerColor);
ObjectSet("D1Lower", OBJPROP_FIBOLEVELS,1);
ObjectSet("D1Lower", OBJPROP_FIRSTLEVEL+0,0.0); ObjectSetFiboDescription("D1Lower", 0, "H4 LOWER - %$");

ObjectSet("D1Lower", OBJPROP_RAY, true);
ObjectSet("D1Lower", OBJPROP_BACK, true);
ObjectSet("D1Lower", OBJPROP_COLOR, EMPTY);

}

/////////////////////////////////////////HILO////////

/////////////////////////////////////////MIDDLE////

if(H4Mid)
if(ObjectFind("H4Middle") == -1)
ObjectCreate("H4Middle", OBJ_FIBO, 0, StartTime, HiPrice, StartTime+PERIOD_H4*60, LoPrice);
else
{
ObjectSet("H4Middle", OBJPROP_TIME2, StartTime);
ObjectSet("H4Middle", OBJPROP_TIME1, StartTime+PERIOD_H4*60);
ObjectSet("H4Middle", OBJPROP_PRICE1, HiPrice);
ObjectSet("H4Middle", OBJPROP_PRICE2, LoPrice);


}
ObjectSet("H4Middle", OBJPROP_LEVELCOLOR, H4MiddleColor);
ObjectSet("H4Middle", OBJPROP_FIBOLEVELS,1);
ObjectSet("H4Middle", OBJPROP_FIRSTLEVEL+0,0.500); ObjectSetFiboDescription("H4Middle", 0, "H4 MIDDLE - %$");
ObjectSet("H4Middle", OBJPROP_RAY, true);
ObjectSet("H4Middle", OBJPROP_BACK, true);
ObjectSet("H4Middle", OBJPROP_COLOR, EMPTY);

}


if(D1Mid)
if(ObjectFind("D1Middle") == -1)
ObjectCreate("D1Middle", OBJ_FIBO, 0, D1StartTime, D1HiPrice, D1StartTime+PERIOD_D1*60, D1LoPrice);
else
{
ObjectSet("D1Middle", OBJPROP_TIME2, D1StartTime);
ObjectSet("D1Middle", OBJPROP_TIME1, D1StartTime+PERIOD_D1*60);
ObjectSet("D1Middle", OBJPROP_PRICE1, D1HiPrice);
ObjectSet("D1Middle", OBJPROP_PRICE2, D1LoPrice);


}
ObjectSet("D1Middle", OBJPROP_LEVELCOLOR, D1MiddleColor);
ObjectSet("D1Middle", OBJPROP_FIBOLEVELS,1);
ObjectSet("D1Middle", OBJPROP_FIRSTLEVEL+0,0.500); ObjectSetFiboDescription("D1Middle", 0, "D1 MIDDLE - %$");
ObjectSet("D1Middle", OBJPROP_RAY, true);
ObjectSet("D1Middle", OBJPROP_BACK, true);
ObjectSet("D1Middle", OBJPROP_COLOR, EMPTY);

}
/////////////////////////////////////////MIDDLE////







//+-----------------------------------------------+
//| Indicator start function
//+-----------------------------------------------+



int start()
{
int shift = iBarShift(NULL, PERIOD_D1, Time[0]) + 1; // H4
HiPrice = iHigh(NULL, PERIOD_H4, shift);
LoPrice = iLow (NULL, PERIOD_H4, shift);
StartTime = iTime(NULL, PERIOD_H4, shift);

D1HiPrice = iHigh(NULL, PERIOD_D1, shift);
D1LoPrice = iLow (NULL, PERIOD_D1, shift);
D1StartTime = iTime(NULL, PERIOD_D1, shift);

if(TimeDayOfWeek(StartTime) == 0/*Sunday*/)
{//Add fridays high and low
HiPrice = MathMax(HiPrice, iHigh(NULL,PERIOD_H4, shift+1));
LoPrice = MathMin(LoPrice, iLow(NULL,PERIOD_H4, shift+1));

D1HiPrice = MathMax(D1HiPrice, iHigh(NULL, PERIOD_D1, shift+1));
D1LoPrice = MathMin(D1LoPrice, iLow(NULL, PERIOD_D1, shift+1));
}

Range = HiPrice - LoPrice;
D1Range = D1HiPrice - D1LoPrice;
DrawFibo();

return(0);
}


//+------------------------------+
Bellow this i attach the original for H4 high low mid
Attached Files
File Type: mq4 H4_hi_low_middle_DK_v1.mq4 (3.9 KB, 8 views)
File Type: mq4 #MTF_Hi_Low_Middle_DK(not work).mq4 (7.0 KB, 3 views)

Last edited by newdigital; 05-25-2008 at 08:00 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #956 (permalink)  
Old 05-26-2008, 01:53 PM
Beno's Avatar
Senior Member
 
Join Date: Aug 2006
Location: London
Posts: 362
Beno is on a distinguished road
I would like some help please I am trying to use the delta-stop as a stop loss
and trailing stop. Attached is the EA.

Is it posible to do this.
Attached Files
File Type: mq4 euroform V 3.0.mq4 (20.7 KB, 5 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #957 (permalink)  
Old 05-26-2008, 04:52 PM
TheRumpledOne's Avatar
Banned
 
Join Date: Nov 2006
Posts: 802
TheRumpledOne is an unknown quantity at this point
highlower.gif

Quote:

//+------------------------------------------------------------------+
//| MODIFIED BY Avery T. Horton, Jr. aka TheRumpledOne |
//| |
//| |
//|
//
// google search "therumpledone mt4"
//
//+------------------------------------------------------------------+
//| _Fibo_Hi_Low_Middle.mq4
//| Base from spudfibo.Upgrade by Darkkiller
//: Thanks to Mladen for helping me to make some correction
//+------------------------------------------------------------------+
#property indicator_chart_window


extern int myChartPeriod = 0 ;

extern string note1 = "Higher,Middle,Lower colors";
extern color HigherColor = DeepSkyBlue;
extern color MiddleColor = Yellow;
extern color LowerColor = HotPink;
extern string note2 = "Draw middle?";
extern bool HiLow = true;
extern bool Mid = true;

double HiPrice, LoPrice, Range;
datetime StartTime;

string tChartPeriod, tHigher, tLower, tMiddle ;



int init()
{
if(myChartPeriod == 0) { myChartPeriod = Period() ; }

tChartPeriod = TimeFrameToString(myChartPeriod) ;

tHigher = tChartPeriod + "H" ;
tLower = tChartPeriod + "L" ;
tMiddle = tChartPeriod + "M" ;

return(0);
}

int deinit()
{
ObjectDelete(tHigher);
ObjectDelete(tLower);
ObjectDelete(tMiddle);
return(0);
}


//+------------------------------------------------------------------+
//| Draw Fibo
//+------------------------------------------------------------------+

int DrawFibo()
{


if(HiLow)
{

if(ObjectFind(tHigher) == -1)
ObjectCreate(tHigher,OBJ_FIBO,0,StartTime,HiPrice+ Range,StartTime,HiPrice);
else
{
ObjectSet(tHigher,OBJPROP_TIME2, StartTime);
ObjectSet(tHigher,OBJPROP_TIME1, StartTime);
ObjectSet(tHigher,OBJPROP_PRICE1,HiPrice+Range);
ObjectSet(tHigher,OBJPROP_PRICE2,HiPrice);
}
ObjectSet(tHigher,OBJPROP_LEVELCOLOR,HigherColor);
ObjectSet(tHigher,OBJPROP_FIBOLEVELS,1);
ObjectSet(tHigher,OBJPROP_FIRSTLEVEL+0,0.0);
ObjectSetFiboDescription(tHigher,0,tChartPeriod+" HIGHER- %$");
ObjectSet(tHigher,OBJPROP_RAY,true);
ObjectSet(tHigher,OBJPROP_BACK,true);
ObjectSet(tHigher,OBJPROP_COLOR,EMPTY);


if(ObjectFind(tLower) == -1)
ObjectCreate(tLower,OBJ_FIBO,0,StartTime,LoPrice-Range,StartTime,LoPrice);
else
{
ObjectSet(tLower,OBJPROP_TIME2, StartTime);
ObjectSet(tLower,OBJPROP_TIME1, StartTime);
ObjectSet(tLower,OBJPROP_PRICE1,LoPrice-Range);
ObjectSet(tLower,OBJPROP_PRICE2,LoPrice);


}
ObjectSet(tLower,OBJPROP_LEVELCOLOR,LowerColor);
ObjectSet(tLower,OBJPROP_FIBOLEVELS,1);
ObjectSet(tLower,OBJPROP_FIRSTLEVEL+0,0.0);
ObjectSetFiboDescription(tLower,0,tChartPeriod+" LOWER - %$");

ObjectSet(tLower,OBJPROP_RAY,true);
ObjectSet(tLower,OBJPROP_BACK,true);
ObjectSet(tLower,OBJPROP_COLOR,EMPTY);

}







/////////////////////////////////////////MIDDLE///////////////////////////

if(Mid)
if(ObjectFind(tMiddle) == -1)
ObjectCreate(tMiddle,OBJ_FIBO,0,StartTime,HiPrice, StartTime+myChartPeriod*60,LoPrice);
else
{
ObjectSet(tMiddle,OBJPROP_TIME2, StartTime);
ObjectSet(tMiddle,OBJPROP_TIME1, StartTime+myChartPeriod*60);
ObjectSet(tMiddle,OBJPROP_PRICE1,HiPrice);
ObjectSet(tMiddle,OBJPROP_PRICE2,LoPrice);


}
ObjectSet(tMiddle,OBJPROP_LEVELCOLOR,MiddleColor);
ObjectSet(tMiddle,OBJPROP_FIBOLEVELS,1);

ObjectSet(tMiddle,OBJPROP_FIRSTLEVEL+0,0.500);
ObjectSetFiboDescription(tMiddle,0,tChartPeriod+" MIDDLE - %$");


ObjectSet(tMiddle,OBJPROP_RAY,true);
ObjectSet(tMiddle,OBJPROP_BACK,true);
ObjectSet(tMiddle,OBJPROP_COLOR,EMPTY);

}


//+------------------------------------------------------------------+
//| Indicator start function
//+------------------------------------------------------------------+

int start()
{
int shift = iBarShift(NULL,myChartPeriod,Time[0]) + 1; //
HiPrice = iHigh(NULL,myChartPeriod,shift);
LoPrice = iLow (NULL,myChartPeriod,shift);
StartTime = iTime(NULL,myChartPeriod,shift);

if(TimeDayOfWeek(StartTime)==0/*Sunday*/)
{//Add fridays high and low
HiPrice = MathMax(HiPrice,iHigh(NULL,myChartPeriod,shift+1)) ;
LoPrice = MathMin(LoPrice,iLow(NULL,myChartPeriod,shift+1));
}

Range = HiPrice-LoPrice;

DrawFibo();

// Comment( "Period_", tChartPeriod ) ;

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

string TimeFrameToString(int tf)
{
string tfs;
switch(tf) {
case PERIOD_M1: tfs="M1" ; break;
case PERIOD_M5: tfs="M5" ; break;
case PERIOD_M15: tfs="M15" ; break;
case PERIOD_M30: tfs="M30" ; break;
case PERIOD_H1: tfs="H1" ; break;
case PERIOD_H4: tfs="H4" ; break;
case PERIOD_D1: tfs="D1" ; break;
case PERIOD_W1: tfs="W1" ; break;
case PERIOD_MN1: tfs="MN";
}
return(tfs);
}
That's how I did it.

P.S. why are my attachments getting deleted?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #958 (permalink)  
Old 05-27-2008, 03:15 AM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
MoveStopOnce

Hello, trying to get this MoveStopOnce code to work but the Sell trades don't seem to get modified by the code, just the Buys. Anything wrong?
Code:
//Buys
//MoveOnce
            if(MoveStopOnce && MoveStopWhenPrice > 0) {
               if(Bid - OrderOpenPrice() >= Point * MoveStopWhenPrice) {
                  if(OrderStopLoss() < OrderOpenPrice() + Point * MoveStopTo) {
                  OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() + Point * MoveStopTo, OrderTakeProfit(), 0, Red);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
Code:
//Sells
//MoveOnce
            if(MoveStopOnce && MoveStopWhenPrice > 0) {
               if(OrderOpenPrice() - Ask >= Point * MoveStopWhenPrice) {
                  if(OrderStopLoss() > OrderOpenPrice() - Point * MoveStopTo) {
                  OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * MoveStopTo, OrderTakeProfit(), 0, Red);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #959 (permalink)  
Old 05-27-2008, 04:50 PM
Member
 
Join Date: Oct 2006
Posts: 71
Big Be is on a distinguished road
MoveStopOnce

I have had this problem.
I think you need to add:
if (OrderType() == OP_BUY)

AND use OP_SELL for the sell code.

Big Be
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #960 (permalink)  
Old 05-27-2008, 05:25 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,174
matrixebiz is on a distinguished road
Quote:
Originally Posted by Big Be View Post
I have had this problem.
I think you need to add:
if (OrderType() == OP_BUY)

AND use OP_SELL for the sell code.

Big Be
Ok, I'll try it when I get home but then why does it still work with Buy orders already?
Thanks
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:07 PM.



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