Forex



Go Back   Forex Trading > Programming > Metatrader Programming
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
  #1151 (permalink)  
Old 08-12-2008, 08:52 AM
Junior Member
 
Join Date: Aug 2008
Posts: 7
gorgoroth is on a distinguished road
Quote:
Originally Posted by gorgoroth View Post
Hi everyone,

I've developed a set of functions to manage configuration settings from an EA.
Those functions are exported by a c++ DLL and each of the exported function has the __stdcall calling convetion requested my MQL4.

My problem arises when a function need to return a string to the EA.

Naturally the function cannot:
- return a pointer to a local variabile (variable goes out of scope)
- return a pointer to a dll global variable (problems with concurrent access)
- return a pointer to a heap allocated string (need functions to free memory to be called from the EA: I don't not like this approach)

So i resolved to pass a string and string size from the EA. Es:

Code:
string buffer;

GetString( buffer, 30 );
and from the c++ dll, something like this

Code:
void __stdcall GetString( LPTSTR buffer, int BufSize )
{
    // Read a string from a some source
    ....
    // -1 to take into account the terminating null character
    StringCchCopy( buffer, BufSize-1, ReadStringFromASource );
}

Here starts the weird behaviour of MQL managing strings returned from a DLL.

using the following code:

Code:
string buffer;
GetString( buffer, 30 );
the first time buffer contains the right string. A first question arises: buffer is not initialized but after calling GetString it contains the string returned. I have to suppose that MQL allocates space for a string variable when it's declared.

Next time GetString() is called the string returned seems to be truncated to the length-1 of the previous string length and not resetted as expected because of the 'string buffer;' statement.

Tried even:

Code:
string buffer = "                              "; // 'allocate' 30 blank characters
GetString( buffer, StringLen(buffer) );
but after the first time, when the execution returns to this code, the assignment of buffer does not work any more and buffer still contains the previous read string, and it seems it can only contains the number of characters of his content.

At first I have thought that the null character is not handled very well by MQL and modified the c++ code like this ...

Code:
CopyMemory( buffer, ReadStringFromASource, min(BufferSize,ReadStringFromASourceLength) );
and not adding the terminating null character.

But when called from MQL, no string at all is returning.

Has someone an answer ?
No one has problems returning string from DLLs ?
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
  #1152 (permalink)  
Old 08-12-2008, 11:29 AM
Senior Member
 
Join Date: Oct 2006
Posts: 104
antone is on a distinguished road
I need help..

Can anyone show me a code? to attach to my EA..

One order per signal.. cause sometimes i have 3 signal cause of different TF.. i want all signal to open..

or a code that would take one order per bar but each Timeframe attach to one EA.. don't want to open alot of chart..
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
  #1153 (permalink)  
Old 08-12-2008, 12:35 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,215
matrixebiz is on a distinguished road
What is wrong with my BuyStop?
Code:
ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Distance*Point,Slippage,Bid-Distance-StopLoss*Point,Ask+Distance+TakeProfit*Point,"",MagicNumber,0,Blue);
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
  #1154 (permalink)  
Old 08-12-2008, 01:11 PM
Senior Member
 
Join Date: Oct 2006
Posts: 104
antone is on a distinguished road
Quote:
Originally Posted by matrixebiz View Post
What is wrong with my BuyStop?
Code:
ticket=OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Distance*Point,Slippage,Bid-Distance-StopLoss*Point,Ask+Distance+TakeProfit*Point,"",MagicNumber,0,Blue);
your Stop lose and Take profit..

you should also add *point to your distance before adding it..

OR

Bid-((Distance-StopLoss)*Point),Ask+((Distance+TakeProfit)*Point)
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
  #1155 (permalink)  
Old 08-12-2008, 04:47 PM
Senior Member
 
Join Date: Feb 2007
Posts: 985
FerruFx is on a distinguished road
Quote:
Originally Posted by matrixebiz View Post
What is the difference between a Limit order and a Stop order?
Thanks
Here's the MT4 platform help file:

Quote:
Pending Order
Pending order is the client's commitment to the brokerage company to buy or sell a security at a pre-defined price in the future. This type of orders is used for opening of a trade position provided the future quotes reach the pre-defined level. There are four types of pending orders available in the terminal:

Buy Limit — buy provided the future "ASK" price is equal to the pre-defined value. The current price level is higher than the value of the placed order. Orders of this type are usually placed in anticipation of that the security price, having fallen to a certain level, will increase;

Buy Stop — buy provided the future "ASK" price is equal to the pre-defined value. The current price level is lower than the value of the placed order. Orders of this type are usually placed in anticipation of that the security price, having reached a certain level, will keep on increasing;

Sell Limit — sell provided the future "BID" price is equal to the pre-defined value. The current price level is lower than the value of the placed order. Orders of this type are usually placed in anticipation of that the security price, having increased to a certain level, will fall;

Sell Stop — sell provided the future "BID" price is equal to the pre-defined value. The current price level is higher than the value of the placed order. Orders of this type are usually placed in anticipation of that the security price, having reached a certain level, will keep on falling.
Hope that helps.

FerruFx
__________________
FerruFx / www.ervent.net - Professional Coding Services (EAs/Indicators/Alerts)

BBVPS.com - Reliable Windows VPS For MT4 Hosting
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
  #1156 (permalink)  
Old 08-12-2008, 05:36 PM
ichanz's Avatar
Junior Member
 
Join Date: Mar 2008
Posts: 14
ichanz is on a distinguished road
code for Opening Several Pair at simultaneously

Hi CodersGuru, Could you please let me know how to code script or EA for OP_SELL or OP_BUY for several pairs simultaneously at nearly same time.

For Instance : I would like to open BUY or SELL EURUSD and USDJPY at the same time.

Thank you
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
  #1157 (permalink)  
Old 08-13-2008, 01:35 AM
willmalou's Avatar
Member
 
Join Date: Apr 2006
Posts: 44
willmalou is on a distinguished road
Trades not closing

This seems to be simple to code but my trades do not close when they are supposed to.
In this example trades should close at the cross of the lower time frame.

if (CloseSell1_1 > CloseSell1_2) Order = SIGNAL_CLOSESELL;
Attached Images
File Type: jpg close.JPG (169.7 KB, 138 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
  #1158 (permalink)  
Old 08-13-2008, 01:20 PM
Junior Member
 
Join Date: Aug 2008
Posts: 7
takis76 is on a distinguished road
Red face Noob Question 02 Trailing Stop

Hi ,

I am here again and as noob , I am asking , how could I create a trailing stop code.



Code:
//+------------------------------------------------------------------+
//|                                                 TAKIS EA 007.mq4 |
//|                                   Copyright © 2008, Takis76 bots |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Takis76 bots"
#property link      ""

//---- input parameters
extern double    Lots=0.01;


   int my_bars;
   string my_string;
   string my_string_mesos_oros;
   string my_string_timi_high;
   string my_string_timi_tora;

   double pinakas_timon[5];
   double mesos_oros;
   int orders;
   double StopLoss=10;
   int ticket;
   double TakeProfit=10;
   int MagicNumber=55555;
   int ypologisa_ton_meso_oro=0;   


   double timi_tora;
   double timi_high;
   double timi_open;
   
   int xronos;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----

   
   my_bars=Bars;
   my_string=DoubleToStr(my_bars, 0);

   
   ObjectCreate("Show_Bars", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Show_Bars", my_string, 12, "Arial", Red);
   ObjectSet("Show_Bars", OBJPROP_CORNER, 0);
   ObjectSet("Show_Bars", OBJPROP_XDISTANCE, 1);
   ObjectSet("Show_Bars", OBJPROP_YDISTANCE, 10);
   
   
   //if (ypologisa_ton_meso_oro<6)
   //{
   mesos_oros=pinakas_timon[0]+pinakas_timon[1]+pinakas_timon[2]+pinakas_timon[3]+pinakas_timon[4]+pinakas_timon[5]/5;
   pinakas_timon[0]=Low[0];
   pinakas_timon[1]=Low[-1];
   pinakas_timon[2]=Low[-2];
   pinakas_timon[3]=Low[-3];
   pinakas_timon[4]=Low[-4];
   my_string_mesos_oros=DoubleToStr(mesos_oros, 4);
   //ypologisa_ton_meso_oro++;
   
   //}
   
   
   ObjectCreate("Mesi_Timi", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Mesi_Timi", my_string_mesos_oros, 12, "Arial", LightGreen);
   ObjectSet("Mesi_Timi", OBJPROP_CORNER, 0);
   ObjectSet("Mesi_Timi", OBJPROP_XDISTANCE, 1);
   ObjectSet("Mesi_Timi", OBJPROP_YDISTANCE, 25);





   
   timi_tora=Bid;
   timi_high=High[1];
   timi_open=Open[1];
   
   orders=OrdersTotal();
   
   //if (High[0]<(High[1]+High[2]+High[3]+High[4]+High[5]/5)*0.0099 && orders<1)
   if (High[0]<High[1] && orders<1)
   {
       //ticket=OrderSend(Symbol(),OP_BUY,Lots,(Ask),3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"My order comment",MagicNumber,0,Green);
         
         ticket=OrderSend(Symbol(),OP_SELLLIMIT,Lots,(High[0]),3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"My order comment",MagicNumber,0,Red);
   
      PlaySound("alert.wav");
   }
   if (orders>0)
   {
   
   //OrderModify(ticket,-1,Bid+StopLoss*Point,Low[0],0,White);
   }



   my_string_timi_high=DoubleToStr(timi_high, 4);

   ObjectCreate("Timi_High", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Timi_High", my_string_timi_high, 12, "Arial", LightBlue);
   ObjectSet("Timi_High", OBJPROP_CORNER, 0);
   ObjectSet("Timi_High", OBJPROP_XDISTANCE, 1);
   ObjectSet("Timi_High", OBJPROP_YDISTANCE, 50);


   my_string_timi_tora=DoubleToStr(timi_tora, 4);

   ObjectCreate("Timi_Tora", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Timi_Tora", my_string_timi_tora, 12, "Arial", LightBlue);
   ObjectSet("Timi_Tora", OBJPROP_CORNER, 0);
   ObjectSet("Timi_Tora", OBJPROP_XDISTANCE, 60);
   ObjectSet("Timi_Tora", OBJPROP_YDISTANCE, 50);
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
As you see , this is my code of my expert Advisor.
Some variables are in greek.


Timi_Tora: -> Price_Now
my_string_timi_tora: -> The string of Price_Now
Mesi_Timi: -> Average_Price
my_string_mesos_oros:-> My string of Average
pinakas_timon[5]:-> Table of Variables
mesos_oros:-> Average
ypologisa_ton_meso_oro:->I calsulated the average
timi_high:-> Price High
timi_open:-> Price Open
xronos:-> Chronos

I put some english translate to my greek variables.

This expert advisor , Compares the high of the previously bar with the high of the current bar.
If the current bar with index[0] is lower than the previously bar , index[1] then I am opening one sell order.

Most of times the order is lower At least on pip of the previously , because as a high of this bar , have big change to go below at least one pip.

I have put 10 pips as take profit but some times the value reach the 9 pips and the order does not establish.

So some trailing ston need to wost time to take one pip profit.

This code is working with H1 Time Period
How do I do that?

This code working with H1 Time Period


Thank you very much.


I made some changes in another code...

And I had abnormal results , I backtest it from 1999 to 2007 and it made this Idea , about four hundred trilion dolars.
Then after 2007 program got crazy and drop OrderSend Error 138 .

Last edited by takis76; 08-13-2008 at 03:45 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
  #1159 (permalink)  
Old 08-13-2008, 02:30 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,215
matrixebiz is on a distinguished road
Hello, what code can I use to check if any Pending orders are open and close them at a specific time?

Thank you
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
  #1160 (permalink)  
Old 08-13-2008, 08:12 PM
Junior Member
 
Join Date: Aug 2008
Posts: 7
takis76 is on a distinguished road
This is how to close all of your open orders

This Function will close all open trades.


Code:
      int orders = OrdersTotal();

void CloseAll()
{
      
      if (orders>0)
      {
      
         for (int cnt = 0 ; cnt < orders ; cnt++)
         {
            OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
            if (OrderMagicNumber() == MagicNumber)
               if(OrderType()==OP_BUY)
               OrderClose(OrderTicket(),OrderLots(),Bid,3,  Violet);
               if(OrderType()==OP_SELL)   
               OrderClose(OrderTicket(),OrderLots(),Ask,3,  Violet);
               if(OrderType()==OP_BUYLIMIT)
               OrderDelete(ticket,Black);
               if(OrderType()==OP_SELLLIMIT)
               OrderDelete(ticket,Black);
         }
         
      }
      
}
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

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 04:51 AM.



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