Forex



Go Back   Forex Trading > Programming > MetaTrader
Forex Forum Register More recent Blogs 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
  #1521 (permalink)  
Old 01-09-2009, 03:11 AM
Junior Member
 
Join Date: May 2008
Posts: 9
i2trader is on a distinguished road
Help me place trades in between the spreads!

Ok, spreads kill some pairs. but is theire away to place trades in the middle of a spreads. This way we can save pips and make more money. i have this code and can it be changed to modify the order to chart price not bid ask?
void PlaceBuyOrder()
{
double BuyOrders, Lots;
double LowestBuy = 1000, HighestBuy;

if (BarTime != Time[0])
{
BarTime = Time[0];
TickPrice = 0;
TradeAllowed = true;
}

RefreshRates();

for (Order = OrdersTotal() - 1; Order >= 0; Order--)
{
if (OrderSelect(Order, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Reference && OrderType() == OP_BUY)
{
if (OrderOpenPrice() < LowestBuy) LowestBuy = OrderOpenPrice();
if (OrderOpenPrice() > HighestBuy) HighestBuy = OrderOpenPrice();
BuyOrders++;
}
}
}

if (TradeAllowed)
{
if (Ask >= HighestBuy + (TrendSpacing * Point))
{
// if (Multiplier)
if (Multiplier == 1)
Lots = NormalizeDouble(LotSize * MathPow(LotIncrement, BuyOrders), 2);
else
Lots = NormalizeDouble(LotSize + (LotIncrement * BuyOrders), 2);
}

if (Ask <= LowestBuy - (Spacing * Point))
{
// if (Multiplier)
if (Multiplier == 1)
Lots = NormalizeDouble(LotSize * CounterTrendMultiplier * MathPow(LotIncrement, BuyOrders), 2);
else
Lots = NormalizeDouble((LotSize * CounterTrendMultiplier) + (LotIncrement * BuyOrders), 2);
}

if (Lots == 0)
{
// if (Multiplier)
if (Multiplier == 1)
Lots = NormalizeDouble(LotSize, 2);
else
Lots = NormalizeDouble(LotSize, 2);
}

OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, TradeComment, Reference, Green);

Error = GetLastError();
if (Error != 0)
Write("Error opening BUY order: " + ErrorDescription(Error) + " (C" + Error + ") Ask:" + Ask + " Slippage:" + Slippage);
else
{
TickPrice = Close[0];
TradeAllowed = false;
}
}
}


void PlaceSellOrder()
{
double SellOrders, Lots;
double HighestSell, LowestSell = 1000;

if (BarTime != Time[0])
{
BarTime = Time[0];
TickPrice = 0;
TradeAllowed = true;
}

RefreshRates();

for (Order = OrdersTotal() - 1; Order >= 0; Order--)
{
if (OrderSelect(Order, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Reference && OrderType() == OP_SELL)
{
if (OrderOpenPrice() > HighestSell) HighestSell = OrderOpenPrice();
if (OrderOpenPrice() < LowestSell) LowestSell = OrderOpenPrice();
SellOrders++;
}
}
}

if (TradeAllowed)
{
if (Bid <= LowestSell - (TrendSpacing * Point))
{
// if (Multiplier)
if (Multiplier == 1)
Lots = NormalizeDouble(LotSize * MathPow(LotIncrement, SellOrders), 2);
else
Lots = NormalizeDouble(LotSize + (LotIncrement * SellOrders), 2);
}

if (Bid >= HighestSell + (Spacing * Point))
{
// if (Multiplier)
if (Multiplier == 1)
Lots = NormalizeDouble(LotSize * CounterTrendMultiplier * MathPow(LotIncrement, SellOrders), 2);
else
Lots = NormalizeDouble((LotSize * CounterTrendMultiplier) + (LotIncrement * SellOrders), 2);
}

if (Lots == 0)
{
// if (Multiplier)
if (Multiplier == 1)
Lots = NormalizeDouble(LotSize, 2);
else
Lots = NormalizeDouble(LotSize, 2);
}


OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, TradeComment, Reference, Red);

Error = GetLastError();
if (Error != 0)
Write("Error opening SELL order: " + ErrorDescription(Error) + " (D" + Error + ") Bid:" + Bid + " Slippage:" + Slippage);
else
{
TickPrice = Close[0];
TradeAllowed = false;
}
}
}

Is this some that can be done?
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
  #1522 (permalink)  
Old 01-09-2009, 06:46 PM
Member
 
Join Date: Jul 2008
Posts: 48
chiwing is on a distinguished road
HELP~just 1 error, use 3 Hours still can't find it out

I AM VERY WORRY , BECAUSE I CAN'T FIND how to correct the error below
can anyone tell me where is the mistake? or help me to debug , i have attached the files, see buttom~ ~

'\end_of_program' - unbalanced left parenthesis C:\Program Files\ MetaTrader\experts\scripts\delete_pending_SAM.mq4 (38, 2)

IT IS A SCRIPT FILE~ ~


//+------------------------------------------------------------------+
//| delete_pending.mq4 |
//| Copyright ?2004, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property show_inputs
bool result;
extern double OverSymbolDel = 1; //0:FASLE ; 1: TRUE

//+------------------------------------------------------------------+
//| script "delete pending order" |
//+------------------------------------------------------------------+
int start()
{
for (int number=0; (number <= OrdersTotal()+1); number++ )
{for (int times=0;( times <= OrdersTotal()+1); times++ )
{if (OrderSelect(number,SELECT_BY_POS,MODE_TRADES) )
{if((OrderType()==OP_BUY) || (OrderType()==OP_SELL) ) break;
if ((OverSymbolDel ==0)&& (Symbol()==OrderSymbol() ) delPending();

if (OverSymbolDel ==1) delPending();
}
else Print("Error when Order Select ", GetLastError() ) ;

}
}

}
//+------------------------------------------------------------------+

void delPending()
{OrderPrint();
int ticket =OrderTicket();
result=OrderDelete(ticket);
if (result==False) Print("Error when delete Order ", GetLastError() );
}
Attached Files
File Type: mq4 delete_pending_SAM.mq4 (1.5 KB, 8 views)

Last edited by chiwing; 01-09-2009 at 06:53 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
  #1523 (permalink)  
Old 01-09-2009, 09:06 PM
Senior Member
 
Join Date: Oct 2008
Location: Vancouver, BC
Posts: 158
Roger09 is on a distinguished road
To chiwing
Try this:
Code:
#property copyright "Copyright ?2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property show_inputs
bool result;
extern double OverSymbolDel = 1; //0:FASLE ; 1: TRUE

//+------------------------------------------------------------------+
//| script "delete pending order" |
//+------------------------------------------------------------------+
int start()
{ 
for (int number=OrdersTotal()-1; number >= 0; number--) 
   {
   OrderSelect(number,SELECT_BY_POS,MODE_TRADES);
   if((OrderType()==OP_BUY) || (OrderType()==OP_SELL) ) continue;
   if (OverSymbolDel ==0&& Symbol()==OrderSymbol() ) delPending();
   if (OverSymbolDel ==1) delPending();
   } 
}
//+------------------------------------------------------------------+

void delPending()
{
OrderPrint();
int ticket =OrderTicket();
result=OrderDelete(ticket);
if (!result) Print("Error when delete Order ", GetLastError() );
}

Last edited by Roger09; 01-09-2009 at 09:11 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
  #1524 (permalink)  
Old 01-10-2009, 03:41 AM
Member
 
Join Date: Jul 2008
Posts: 48
chiwing is on a distinguished road
Quote:
Originally Posted by Roger09 View Post
To chiwing
Try this:
Code:
#property copyright "Copyright ?2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property show_inputs
bool result;
extern double OverSymbolDel = 1; //0:FASLE ; 1: TRUE

//+------------------------------------------------------------------+
//| script "delete pending order" |
//+------------------------------------------------------------------+
int start()
{ 
for (int number=OrdersTotal()-1; number >= 0; number--) 
   {
   OrderSelect(number,SELECT_BY_POS,MODE_TRADES);
   if((OrderType()==OP_BUY) || (OrderType()==OP_SELL) ) continue;
   if (OverSymbolDel ==0&& Symbol()==OrderSymbol() ) delPending();
   if (OverSymbolDel ==1) delPending();
   } 
}
//+------------------------------------------------------------------+

void delPending()
{
OrderPrint();
int ticket =OrderTicket();
result=OrderDelete(ticket);
if (!result) Print("Error when delete Order ", GetLastError() );
}
thanks for your help~ ~

and i find my mistake :

{if (OrderSelect(number,SELECT_BY_POS,MODE_TRADES) )
change to
OrderSelect(number,SELECT_BY_POS,MODE_TRADES);


{if((OrderType()==OP_BUY) || (OrderType()==OP_SELL) ) break;
change to
if((OrderType()==OP_BUY) || (OrderType()==OP_SELL) ) countinue;
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
  #1525 (permalink)  
Old 01-10-2009, 04:07 AM
Member
 
Join Date: Jul 2008
Posts: 48
chiwing is on a distinguished road
Quote:
Originally Posted by Roger09 View Post
To chiwing
Try this:
Code:
#property copyright "Copyright ?2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property show_inputs
bool result;
extern double OverSymbolDel = 1; //0:FASLE ; 1: TRUE

//+------------------------------------------------------------------+
//| script "delete pending order" |
//+------------------------------------------------------------------+
int start()
{ 
for (int number=OrdersTotal()-1; number >= 0; number--) 
   {
   OrderSelect(number,SELECT_BY_POS,MODE_TRADES);
   if((OrderType()==OP_BUY) || (OrderType()==OP_SELL) ) continue;
   if (OverSymbolDel ==0&& Symbol()==OrderSymbol() ) delPending();
   if (OverSymbolDel ==1) delPending();
   } 
}
//+------------------------------------------------------------------+

void delPending()
{
OrderPrint();
int ticket =OrderTicket();
result=OrderDelete(ticket);
if (!result) Print("Error when delete Order ", GetLastError() );
}
if ( (OverSymbolDel ==0 ) && (Symbol()==OrderSymbol() ) delPending();
change to
if ( (OverSymbolDel ==0 ) && (Symbol()==OrderSymbol() )) delPending();
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
  #1526 (permalink)  
Old 01-11-2009, 09:19 PM
Kikousi's Avatar
Junior Member
 
Join Date: Nov 2008
Posts: 6
Kikousi is on a distinguished road
GetClientRect???

How should I do though I want to acquire the client coordinates of the chart?
I want to know lower right coordinates without using OBJPROP_CORNER.

My best regards.
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
  #1527 (permalink)  
Old 01-12-2009, 12:55 PM
Junior Member
 
Join Date: May 2008
Posts: 16
billsechen is on a distinguished road
Eu h1 ea

please help me to modify the best one
Attached Files
File Type: mq4 Stat_Euclidean_Metric (Modified).mq4 (15.5 KB, 58 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
  #1528 (permalink)  
Old 01-12-2009, 01:08 PM
Moxy's Avatar
Junior Member
 
Join Date: Oct 2007
Posts: 2
Moxy is on a distinguished road
Post Help with Logic

Hi all,

I would like a little help with some code logic. I am trying to build an EA of a system I am looking at but am a little puzzled how to write the logic for Buy and Sell Signals. Here is the Pseudo logic of what I want to turn into MQL:

BUY LOGIC:

Code:
If (MA_1 > MA_2) and (Previous(MA_1 < MA_2))                // A moving average cross mean we have a "GET READY" signal

//	Once we have a "GET READY" signal the following conditions need to be true
//	in order for the system to create a "BUY_SIGNAL".
//      Note: the following conditions do not necessarily have to become true on the exact same bar,
              but need to trigger true within + or - 2 bars of the "GET READY" bar.

	( CLOSE > MA3 )	                                    // Price closes above a MA
        ( CCI Crosses above the ZERO line )                 // CCI crosses up above zero
        ( Fast Stochastic crosses above Slow Stochastic )   // Stochastic triggers to the up side
The Sell Logic is just the opposite of the buy logic.

I don't need full EA code just the logic converted to MQL 'IF' and 'LOOP' statements to workout the signal. I think I can figure out the OpenOrder code etc... from many examples already in this thread.

Any help anyone can give would be much appreciated.

Thanks,
Moxy

Last edited by Moxy; 01-12-2009 at 09:52 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
  #1529 (permalink)  
Old 01-12-2009, 11:27 PM
Senior Member
 
Join Date: Nov 2006
Posts: 308
luxinterior is on a distinguished road
You're best bet is to look in the metaeditor help file.

Take a look at functions like iMa, iStochastic and iCCI. They have examples and if you combine those with information you'll get from looking at the code in any EA you'll find it easy.

Good luck

Lux
__________________
Build An Expert Advisor. FREE E-course As Seen On TV
ForexArea.com
Users of Gap Trader from 'Forex-Assistant' MUST Read This
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
  #1530 (permalink)  
Old 01-13-2009, 07:44 AM
Moxy's Avatar
Junior Member
 
Join Date: Oct 2007
Posts: 2
Moxy is on a distinguished road
Quote:
Originally Posted by luxinterior View Post
You're best bet is to look in the metaeditor help file.

Take a look at functions like iMa, iStochastic and iCCI. They have examples and if you combine those with information you'll get from looking at the code in any EA you'll find it easy.

Good luck

Lux
Hi Lux,

Thanks for the reply. I can workout out the individual iMA statements etc... the problem i have is how to reference the different time bars once a signal is triggered. For example... If I have a GET READY signal I need to look at the 2 bars before and 2 bars after (5 bars in total) for the other indicators to confirm I have a BUY SIGNAL on the open of the next bar. Not sure if I am making sense !!

I guess it is... how would i structure the necessary FOR loops etc.. when I need to reference bars both before and after the bar being processed.

Regards,
Moxy
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, dll, eli hayun, Eur_harvester.ex4, expert adviser, expert advisor, forex, higher high, how to code, indicator, I_XO_A_H, kehedge, mechanical trading, metatrader command line, mt4, MT4-LevelStop-Reverse, OrderReliable.mqh, programming, rectangle tool, trading, volty channel stop


Currently Active Users Viewing This Thread: 2 (1 members and 1 guests)
healingcancer
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 01:04 AM.



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